public void PriceCategoryGetTest() { int id = 1; var priceCategories = DataForTests.PriceCategories; EFWorkUnitMock.Setup(x => x.PriceCategories.Get(id)).Returns(priceCategories[id - 1]); var priceCategoryService = new PriceCategoryService(EFWorkUnitMock.Object); var result = priceCategoryService.Get(id); var expected = toDTOMapper.Map <PriceCategory, PriceCategoryDTO>(priceCategories[id - 1]); Assert.AreEqual(expected, result); }
public void PriceCategoryGetTest() { int id = 2; var priceCategory = DataForTests.PriceCategories[id - 1]; var toDTO = new MapperConfiguration( cfg => { cfg.CreateMap <PriceCategory, PriceCategoryDTO>().ReverseMap(); cfg.CreateMap <Category, CategoryDTO>().ReverseMap(); }).CreateMapper(); var priceCategoryDTO = toDTO.Map <PriceCategory, PriceCategoryDTO>(priceCategory); EFWorkUnitMock.Setup(x => x.PriceCategories.Get(id)).Returns(priceCategory); PriceCategoryServiceMock.Setup(a => a.Get(id)).Returns(priceCategoryDTO); var priceCategoryService = new PriceCategoryService(EFWorkUnitMock.Object); PriceCategoryController controller = new PriceCategoryController(PriceCategoryServiceMock.Object); var httpResponse = controller.Get(httpRequest, id); var result = httpResponse.Content.ReadAsAsync <PriceCategoryModel>(); PriceCategoryModel expected = mapper.Map <PriceCategoryDTO, PriceCategoryModel>(priceCategoryService.Get(id)); Assert.AreEqual(expected, result.Result); }