public void Create_IdSpecified_ThrowsArgumentException()
        {
            //Arrange
            ProductStock invalidProductStock = new ProductStock
            {
                Id      = 5,
                Product = new Product {
                    Id = 5
                },
                ProductSize = new ProductSize {
                    Id = 3
                },
                Quantity = 120
            };

            Mock <IProductStockRepository> productStockRepository = new Mock <IProductStockRepository>();
            Mock <IProductRepository>      productRepository      = new Mock <IProductRepository>();
            Mock <IProductSizeRepository>  productSizeRepository  = new Mock <IProductSizeRepository>();
            IProductStockService           productStockService    = new ProductStockService(productStockRepository.Object,
                                                                                            productRepository.Object,
                                                                                            productSizeRepository.Object);

            //Act
            Action actual = () => productStockService.Create(invalidProductStock);

            //Assert
            Assert.Throws <ArgumentException>(actual);
        }
        public void Create_ProductSizeNonExisting_ThrowsArgumentException()
        {
            //Arrange
            ProductStock invalidProductStock = new ProductStock
            {
                Product = new Product {
                    Id = 5
                },
                ProductSize = new ProductSize {
                    Id = 3
                },
                Quantity = 120
            };

            ProductSize nullProductSize = null;

            Mock <IProductStockRepository> productStockRepository = new Mock <IProductStockRepository>();
            Mock <IProductRepository>      productRepository      = new Mock <IProductRepository>();

            productRepository.Setup(repo => repo.Read(invalidProductStock.Product.Id)).
            Returns(invalidProductStock.Product);
            Mock <IProductSizeRepository> productSizeRepository = new Mock <IProductSizeRepository>();

            productSizeRepository.Setup(repo => repo.Read(invalidProductStock.ProductSize.Id)).
            Returns(nullProductSize);
            IProductStockService productStockService = new ProductStockService(productStockRepository.Object,
                                                                               productRepository.Object,
                                                                               productSizeRepository.Object);

            //Act
            Action actual = () => productStockService.Create(invalidProductStock);

            //Assert
            Assert.Throws <ArgumentException>(actual);
        }
        public void Create_ProductStockValid_ReturnsCreatedProductStockWithId()
        {
            //Arrange
            ProductStock validProductStock = new ProductStock
            {
                Product = new Product {
                    Id = 5
                },
                ProductSize = new ProductSize {
                    Id = 3
                },
                Quantity = 120
            };
            ProductStock expected = new ProductStock
            {
                Id      = 1,
                Product = new Product {
                    Id = 5
                },
                ProductSize = new ProductSize {
                    Id = 3
                },
                Quantity = 120
            };

            Mock <IProductStockRepository> productStockRepository = new Mock <IProductStockRepository>();

            productStockRepository.Setup(repo => repo.Create(validProductStock)).
            Returns(expected);
            Mock <IProductRepository> productRepository = new Mock <IProductRepository>();

            productRepository.Setup(repo => repo.Read(validProductStock.Product.Id)).
            Returns(validProductStock.Product);
            Mock <IProductSizeRepository> productSizeRepository = new Mock <IProductSizeRepository>();

            productSizeRepository.Setup(repo => repo.Read(validProductStock.ProductSize.Id)).
            Returns(validProductStock.ProductSize);

            IProductStockService productStockService = new ProductStockService(productStockRepository.Object,
                                                                               productRepository.Object,
                                                                               productSizeRepository.Object);

            //Act
            ProductStock actual = productStockService.Create(validProductStock);

            //Assert
            Assert.Equal(expected, actual);
        }
        public void Create_ProductStockNull_ThrowsArgumentNullException()
        {
            //Arrange
            ProductStock invalidProductStock = null;

            Mock <IProductStockRepository> productStockRepository = new Mock <IProductStockRepository>();
            Mock <IProductRepository>      productRepository      = new Mock <IProductRepository>();
            Mock <IProductSizeRepository>  productSizeRepository  = new Mock <IProductSizeRepository>();
            IProductStockService           productStockService    = new ProductStockService(productStockRepository.Object,
                                                                                            productRepository.Object,
                                                                                            productSizeRepository.Object);

            //Act
            Action actual = () => productStockService.Create(invalidProductStock);

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