public void Update_ProductMetricSpecified_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.Update(invalidProductSize);

            //Assert
            Assert.Throws <ArgumentException>(actual);
        }
        public void Update_ProductSizeValid_ReturnsUpdatedProductSize()
        {
            //Arrange
            ProductSize validProductSize = new ProductSize
            {
                Id            = 1,
                ProductMetric = null,
                Size          = "L",
                MetricXValue  = 70,
                MetricYValue  = 100,
                MetricZValue  = 75
            };

            ProductSize expected = validProductSize;

            ProductMetric fetchedProductMetric = new ProductMetric {
                Id = 1, MetricX = "Length", MetricY = "Width", MetricZ = "Sleeve Length"
            };

            ProductSize fetchedProductSize = new ProductSize
            {
                Id            = 1,
                ProductMetric = fetchedProductMetric,
                Size          = "XL",
                MetricXValue  = 70,
                MetricYValue  = 100,
                MetricZValue  = 150
            };

            Mock <IProductSizeRepository> productSizeRepository = new Mock <IProductSizeRepository>();

            productSizeRepository.Setup(repo => repo.Read(validProductSize.Id)).
            Returns(expected);
            productSizeRepository.Setup((repo => repo.ReadIncludeProductMetric(validProductSize.Id)))
            .Returns(fetchedProductSize);
            productSizeRepository.Setup(repo => repo.Update(validProductSize)).
            Returns(expected);
            Mock <IProductMetricRepository> productMetricRepository = new Mock <IProductMetricRepository>();

            IProductSizeService productSizeService = new ProductSizeService(productSizeRepository.Object,
                                                                            productMetricRepository.Object);

            //Act
            ProductSize actual = productSizeService.Update(validProductSize);

            //Assert
            Assert.Equal(expected, actual);
        }
        public void Update_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.Update(invalidProductSize);

            //Assert
            Assert.Throws <ArgumentNullException>(actual);
        }
        public void Update_IdNonExisting_ThrowsArgumentException()
        {
            //Arrange
            ProductSize invalidProductSize = new ProductSize
            {
                Id            = 1,
                ProductMetric = null,
                Size          = "L",
                MetricXValue  = 70,
                MetricYValue  = 100,
                MetricZValue  = 75
            };

            ProductSize nullProductSize = null;

            ProductMetric fetchedProductMetric = new ProductMetric {
                Id = 1, MetricX = "Length", MetricY = "Width", MetricZ = "Sleeve Length"
            };

            ProductSize fetchedProductSize = new ProductSize
            {
                Id            = 1,
                ProductMetric = fetchedProductMetric,
                Size          = "XL",
                MetricXValue  = 70,
                MetricYValue  = 100,
                MetricZValue  = 150
            };

            Mock <IProductSizeRepository> productSizeRepository = new Mock <IProductSizeRepository>();

            productSizeRepository.Setup(repo => repo.Read(invalidProductSize.Id)).
            Returns(nullProductSize);
            productSizeRepository.Setup((repo => repo.ReadIncludeProductMetric(invalidProductSize.Id)))
            .Returns(fetchedProductSize);
            Mock <IProductMetricRepository> productMetricRepository = new Mock <IProductMetricRepository>();

            IProductSizeService productSizeService = new ProductSizeService(productSizeRepository.Object,
                                                                            productMetricRepository.Object);

            //Act
            Action actual = () => productSizeService.Update(invalidProductSize);

            //Assert
            Assert.Throws <ArgumentException>(actual);
        }