tdd

How to unit test class with no logic?

你说的曾经没有我的故事 提交于 2019-12-12 07:19:40
问题 I find it easy to write unit tests for algorithms. For example, sort(List) , it is easy to write tests like: list = [2, 1, 4]; assert(sort(list) == [1, 2, 4]); But I find it really hard to test methods that have no logic, no if statements, just a set of calls. There are mainly 2 examples that I'd like an answer for how to unit test them: Example 1: Let's say I have a class that is responsible for writing some data to a file, but that data is written in a specific way by external functions (

How to test my linq repository calls

限于喜欢 提交于 2019-12-12 04:43:31
问题 I have the following UserRepository: public class UserRepository : Repository<Entities.User> { public Entities.IUser Find(string domain, string username, string password) { return (from u in FindAll() where u.Account.SubDomain == domain && u.EmailAddress == username && u.PasswordHash == password && !u.IsArchived select u).FirstOrDefault(); } } The "FindAll" method is part of Repository and basically just calls context.GetTable().AsQueryable() I want to be able to write a test that will call

Testing ASP.NET Web API POST and Parameterless GET Routes with WebApiContrib.Testing

醉酒当歌 提交于 2019-12-12 04:05:37
问题 I am trying to set up some route tests using the WebApiContrib.Testing library. My get tests (like this) work fine... [Test] [Category("Auth Api Tests")] public void TheAuthControllerAcceptsASingleItemGetRouteWithAHashString() { "~/auth/sjkfhiuehfkshjksdfh".ShouldMapTo<AuthController>(c => c.Get("sjkfhiuehfkshjksdfh")); } I am rather lost on the post test - I currently have the following which fails with a NotImplementedException... [Test] [Category("Auth Api Tests")] public void

How to do unit test a service which has wcf client called

送分小仙女□ 提交于 2019-12-12 02:55:17
问题 public class RefDataProvider : IRefDataProvider { private const string REF_DATA_COUNTRIES = "CountryData"; public IEnumerable<CountryLookupDto> GetCountries() { //if in cache then get cached version if (CacheManager.GetInstance.OCache.Contains(REF_DATA_COUNTRIES)) return CacheManager.GetInstance.GetTypedItem<IEnumerable<CountryLookupDto>>(REF_DATA_COUNTRIES); //not in cache so get from dadtavase using (var service = new CrmServiceClient()) { try { IEnumerable<CountryLookupDto> countriesDto =

How to write tests for classes with inheritance

这一生的挚爱 提交于 2019-12-11 19:27:37
问题 I have a project written in Angular 1.3 that have services that inherit each other. There is a BaseApiService , which is a parent class and it implements a lot of functionality related to API calls. It looks like that: .factory('BaseApiService', function ($resource, apiHost, apiUrl, WebSocketService, $q, $timeout) { //initializer return function (resourceName, options) { options = angular.extend({}, { resourceUrl: resourceName + '/:id', resourceParams: {id: '@id'}, resourceMethods: { 'get':

mocking a method with an anonymous type argument

只愿长相守 提交于 2019-12-11 18:43:52
问题 I have the following code: var connector = new Mock<IConector>(); connector .Setup(cn => cn.listar("FetchEstandar", new Estandar(), new {Id = 1})) .Returns(new List<Estandar>{ new Estandar {Id = 1} }); var entidad = connector.Object .listar("FetchEstandar", new Estandar(), new {Id = 1}); when I call listar on the connector Object, I get an "Expression Cannot Contain an Anonymouse Type" error. I've tried with rhino mocks and moq. Is there any way I can mock this method? am I doing something

TDD test shows error even though response is correct

隐身守侯 提交于 2019-12-11 18:39:00
问题 I am following a tutorial about api here and I am following the exact code and I am also adapting the code for an Etsy app, here is my code for the second test, the tutorial code is identical to the tutorial, and works. The following code has been adapted to work with the Etsy APi. #etsywrapper/__core.py from . import session class Listings(object): def __init__(self, id): self.id = id def info(self): path = 'https://openapi.etsy.com/v2/listings/{}/inventory'.format(self.id) response =

Correctly Unit Test Service / Repository Interaction

感情迁移 提交于 2019-12-11 18:29:26
问题 I have a method CreateAccount(...) that I want to unit test. Basically it creates an Account Entity and saves it to the DB, then returns the newly created Account. I am mocking the Repository and expecting an Insert(...) call. But the Insert method expects an Account object. This test passes, but it just does not seem correct, because CreateAccount creates an account, and I am creating an account for the Mock'ed expected call (two seperate Account instances). What would be the correct way to

ReferenceError: CoffeeScript + JsTestDriver + Qunit

谁说胖子不能爱 提交于 2019-12-11 13:22:59
问题 Currently I'm looking into TDD with CoffeeScript and JsTestDriver however I'm stuck on a ReferenceError thrown by JsTestDriver. Some info: Using the IntelliJ JsTestDriver plugin Testing via Chrome Configured JsTestDriver the same way as on: http://code.google.com/p/js-test-driver/wiki/QUnitAdapter Writing the tests in CoffeeScript CoffeeScript is compiled to javascript and put in the configured directories before the test is run Config server: http://Mark-PC:9876/capture load: - js/lib/main/*

Ruby - Making test pass

我的未来我决定 提交于 2019-12-11 12:25:46
问题 I'm trying to make this test pass and am not sure how to go about making this pass. TEST def test_it_is_thirsty_by_default vampire = Vampire.new("Count von Count") assert vampire.thirsty? end def test_it_is_not_thirsty_after_drinking vampire = Vampire.new("Elizabeth Bathory") vampire.drink refute vampire.thirsty? end CODE def thirsty? true end def drink thirsty? === false end It is giving a failure message on the last test: Failed refutation, no message given What am I missing? My thought is