public void ReturnInstanceOfTypeIEnumerableProductModel_WhenInvoked() { // Arrange Mapper.Reset(); AutomapperConfiguration.Initialize(); var mockContext = new Mock <IOnlineStoreContext>(); var productsMock = new List <Product> { new Product { Name = "Testproduct", Quantity = 5, Category = new Category() { Name = "Patki" } } }.GetQueryableMockDbSet(); var fakemapper = new Mock <IMapper>(); var fakeCategoryService = new Mock <ICategoryService>(); mockContext.Setup(s => s.Products).Returns(productsMock.Object); var service = new Logic.Services.ProductService(mockContext.Object, fakemapper.Object, fakeCategoryService.Object); // Act var products = service.GetProductsByCategoryName("Patki"); //Assert Assert.IsInstanceOfType(products, typeof(IEnumerable <ProductModel>)); }
public void ReturnCorrectAmountOfProducts_WhenInvoked() { // Arrange Mapper.Reset(); AutomapperConfiguration.Initialize(); var mockContext = new Mock <IOnlineStoreContext>(); var productsMock = new List <Product> { new Product { Name = "Testproduct", Quantity = 5, Category = new Category() { Name = "Patki" } } }.GetQueryableMockDbSet(); var fakemapper = new Mock <IMapper>(); var fakeCategoryService = new Mock <ICategoryService>(); mockContext.Setup(s => s.Products).Returns(productsMock.Object); var service = new Logic.Services.ProductService(mockContext.Object, fakemapper.Object, fakeCategoryService.Object); // Act var products = service.GetProductsByCategoryName("Patki"); //Assert Assert.AreEqual(1, products.Count()); }
public void ThrowArgumentNullException_WhenProvidedEmptyString() { //Arrange var fakeContext = new Mock <IOnlineStoreContext>(); var fakemapper = new Mock <IMapper>(); var fakeCategoryService = new Mock <ICategoryService>(); var service = new Logic.Services.ProductService(fakeContext.Object, fakemapper.Object, fakeCategoryService.Object); //Act && Assert Assert.ThrowsException <ArgumentNullException>(() => service.GetProductsByCategoryName(null)); }