public void Create_IdSpecified_ThrowsArgumentException() { //Arrange ProductSize invalidProductSize = new ProductSize { Id = 1, ProductMetric = new ProductMetric { Id = 1 }, Size = "L", MetricXValue = 70, MetricYValue = 100, MetricZValue = 75 }; Mock <IProductSizeRepository> productSizeRepository = new Mock <IProductSizeRepository>(); Mock <IProductMetricRepository> productMetricRepository = new Mock <IProductMetricRepository>(); IProductSizeService productSizeService = new ProductSizeService(productSizeRepository.Object, productMetricRepository.Object); //Act Action actual = () => productSizeService.Create(invalidProductSize); //Assert Assert.Throws <ArgumentException>(actual); }
public void Create_ProductMetricNonExisting_ThrowsArgumentException() { //Arrange ProductSize invalidProductSize = new ProductSize { ProductMetric = new ProductMetric { Id = 1 }, Size = "L", MetricXValue = 70, MetricYValue = 100, MetricZValue = 75 }; ProductMetric nullProductMetric = null; Mock <IProductSizeRepository> productSizeRepository = new Mock <IProductSizeRepository>(); Mock <IProductMetricRepository> productMetricRepository = new Mock <IProductMetricRepository>(); productMetricRepository.Setup(repo => repo.Read(invalidProductSize.ProductMetric.Id)). Returns(nullProductMetric); IProductSizeService productSizeService = new ProductSizeService(productSizeRepository.Object, productMetricRepository.Object); //Act Action actual = () => productSizeService.Create(invalidProductSize); //Assert Assert.Throws <ArgumentException>(actual); }
public void Create_ProductSizeValid_ReturnsCreatedProductSizeWithId() { //Arrange ProductSize validProductSize = new ProductSize { ProductMetric = new ProductMetric { Id = 1 }, Size = "L", MetricXValue = 70, MetricYValue = 100, MetricZValue = 75 }; ProductSize expected = new ProductSize { Id = 1, ProductMetric = new ProductMetric { Id = 1 }, Size = "L", MetricXValue = 70, MetricYValue = 100, MetricZValue = 75 }; ProductMetric fetchedProductMetric = new ProductMetric { Id = 1, Name = "Oversized Hoodie", MetricX = "Length", MetricY = "Width", MetricZ = "Sleeve Length" }; Mock <IProductSizeRepository> productSizeRepository = new Mock <IProductSizeRepository>(); productSizeRepository.Setup(repo => repo.Create(validProductSize)). Returns(expected); Mock <IProductMetricRepository> productMetricRepository = new Mock <IProductMetricRepository>(); productMetricRepository.Setup(repo => repo.Read(validProductSize.ProductMetric.Id)). Returns(fetchedProductMetric); IProductSizeService productSizeService = new ProductSizeService(productSizeRepository.Object, productMetricRepository.Object); //Act ProductSize actual = productSizeService.Create(validProductSize); //Assert Assert.Equal(expected, actual); }
public void Create_ProductSizeNull_ThrowsArgumentNullException() { //Arrange ProductSize invalidProductSize = null; Mock <IProductSizeRepository> productSizeRepository = new Mock <IProductSizeRepository>(); Mock <IProductMetricRepository> productMetricRepository = new Mock <IProductMetricRepository>(); IProductSizeService productSizeService = new ProductSizeService(productSizeRepository.Object, productMetricRepository.Object); //Act Action actual = () => productSizeService.Create(invalidProductSize); //Assert Assert.Throws <ArgumentNullException>(actual); }
public void Create_MetricValueNegative_ThrowsArgumentException() { //Arrange ProductSize invalidProductSize = new ProductSize { ProductMetric = new ProductMetric { Id = 1 }, Size = "XL", MetricXValue = 70, MetricYValue = -13, MetricZValue = 20 }; ProductMetric fetchedProductMetric = new ProductMetric { Id = 1, Name = "Oversized Hoodie", MetricX = "Length", MetricY = "Width", MetricZ = "Sleeve Length" }; Mock <IProductSizeRepository> productSizeRepository = new Mock <IProductSizeRepository>(); Mock <IProductMetricRepository> productMetricRepository = new Mock <IProductMetricRepository>(); productMetricRepository.Setup(repo => repo.Read(invalidProductSize.ProductMetric.Id)). Returns(fetchedProductMetric); IProductSizeService productSizeService = new ProductSizeService(productSizeRepository.Object, productMetricRepository.Object); //Act Action actual = () => productSizeService.Create(invalidProductSize); //Assert Assert.Throws <ArgumentException>(actual); }