public void AddCallsAddFromRepository() { var testItem = ProductObjectMother.CreateAvailableProduct(1); ProductService.Add(testItem); ProductRepositoryMock.Verify(x => x.Add(testItem), Times.Once()); }
public static void Setup(TestContext context) { Mock <IProductRepository> _productRepository = new ProductRepositoryMock()._productRepository; Mock <IProductHelper> _productHelper = new MockProductHelper()._productHelper; Mock <IOptions <MockAmqpInfo> > _amqpInfo = new MockAmqpInfo()._amqpInfo; Mock <Prueba.Services.RabbitMQ.AmqpService> _amqpService = new MockAmqpService()._amqpService; _productService = new ProductServices(_productRepository.Object, _productHelper.Object, _amqpService.Object); }
public void UpdateCallsUpdateFromRepository() { var product = ProductObjectMother.CreateProductWithNoId(); ProductService.Add(product); product.Name = "New name"; ProductService.Update(product); ProductRepositoryMock.Verify(x => x.Update(product)); }
public void GivenAProductRepository_WhenICallGetAllProducts_IShouldGetCorrectProducts() { var repository = new ProductRepositoryMock(); var productsController = new ProductsController(repository); var products = productsController.GetAllProducts(); Assert.IsNotNull(products); Assert.AreEqual(4, products.Count()); Assert.IsNull(products.ElementAtOrDefault(3).Name); }
public void Filter_NegativeConsumption_ThrowsException() { // Arrange var consumptionkWh = -1; var db = new ProductRepositoryMock(); var filter = GetFilter(consumptionkWh); // Act var result = filter.Filter(db.GetProducts()).ToArray(); // Assert Assert.Fail("Exception expected"); }
public ProductServiceTest() { var dbContext = GetDbContext(); var productRepositoryMock = new ProductRepositoryMock(); var userRepositoryMock = new UserRepositoryMock(); userRepositoryMock.IsModeratorMock(_currentUserId, true); _productService = new ProductService(productRepositoryMock.Object, userRepositoryMock.Object, dbContext); }
public void Filter_ZeroConsumption_ProductsWithDefaultValues() { // Arrange var consumptionkWh = 0; var db = new ProductRepositoryMock(); var filter = GetFilter(consumptionkWh); var expectedAnnualCosts = new double[] { 60, 800 }; // Act var result = filter.Filter(db.GetProducts()).ToArray(); // Assert for (int i = 0; i < expectedAnnualCosts.Length - 1; i++) { Assert.AreEqual(expectedAnnualCosts[i], result[i].AnnualCost); } }
static void Main(string[] args) { Product p1 = new Product() { Created = Convert.ToDateTime("01/01/2012"), // ReadOnly - so should not be updated with this value Updated = Convert.ToDateTime("01/02/2012"), // ReadOnly - so should not be updated with this value Id = 99, // ReadOnly - should not be udpated with this value Name = "Product 1", Price = 12.30m }; Product p2 = new Product() { Name = "Product 2", Price = 18.50m, }; IRepository <Product> repo = new ProductRepositoryMock(); // test the add repo.Add(p1); repo.Add(p2); PrintProducts(repo.GetAll()); // p1 should not change because of change in Id p1.Id = 5; // no update should happen p1.Name = "Product 1 updated"; p1.Price = 10.50m; // p2 should update name and price but not date created p2.Name = "Product 2 updated"; p2.Price = 17m; p2.Created = DateTime.Now; repo.Update(p1); repo.Update(p2); PrintProducts(repo.GetAll()); Console.ReadKey(); }
public void Filter_ExampleRates_MatchedExampleValues() { // Arrange var db = new ProductRepositoryMock(); var consumptionRates = new int[] { 3500, 4500, 6000 }; var expectedAnnualCosts = new double[, ] { { 800.0, 830.0 }, { 950.0, 1050.0 }, { 1380.0, 1400.0 } }; // Act var idx = 0; foreach (var rate in consumptionRates) { var filter = GetFilter(rate); var result = filter.Filter(db.GetProducts()).ToArray(); // Assert Assert.AreEqual(expectedAnnualCosts[idx, 0], result[0].AnnualCost); idx++; } }
public void GetPageOrderedByPriceDescCallsGetOrderedPageFromRepository() { ProductService.GetPageOrderedByPriceDesc(1, 1); ProductRepositoryMock.Verify(x => x.GetOrderedPage( 1, 1, It.IsAny <Func <Product, IComparable> >(), false), Times.Once()); }
public void DeleteCallsDeleteFromRepository() { ProductService.Delete(1); ProductRepositoryMock.Verify(x => x.Delete(1), Times.Once()); }
public void FindAllCallsFindAllFromRepository() { ProductService.FindAll(); ProductRepositoryMock.Verify(x => x.FindAll(), Times.Once()); }