Exemplo n.º 1
0
        public void Update_ProductsSpecified_ThrowsArgumentException()
        {
            //Arrange
            ProductModel invalidProductModel = new ProductModel
            {
                Id              = 1,
                Name            = "Rust In Peace Hoodie",
                ProductCategory = new ProductCategory {
                    Id = 2
                },
                ProductMetric = new ProductMetric {
                    Id = 4
                },
                Price    = 120,
                Products = new List <Product>
                {
                    new Product {
                        Id = 1
                    }
                }
            };

            Mock <IProductModelRepository>    productModelRepository    = new Mock <IProductModelRepository>();
            Mock <IProductCategoryRepository> productCategoryRepository = new Mock <IProductCategoryRepository>();
            Mock <IProductMetricRepository>   productMetricRepository   = new Mock <IProductMetricRepository>();

            IProductModelService productModelService = new ProductModelService(productModelRepository.Object,
                                                                               productCategoryRepository.Object, productMetricRepository.Object);

            //Act
            Action actual = () => productModelService.Update(invalidProductModel);

            //Assert
            Assert.Throws <ArgumentException>(actual);
        }
Exemplo n.º 2
0
        public async void Update()
        {
            var mock  = new ServiceMockFacade <IProductModelRepository>();
            var model = new ApiProductModelRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <ProductModel>())).Returns(Task.FromResult(new ProductModel()));
            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(new ProductModel()));
            var service = new ProductModelService(mock.LoggerMock.Object,
                                                  mock.RepositoryMock.Object,
                                                  mock.ModelValidatorMockFactory.ProductModelModelValidatorMock.Object,
                                                  mock.BOLMapperMockFactory.BOLProductModelMapperMock,
                                                  mock.DALMapperMockFactory.DALProductModelMapperMock,
                                                  mock.BOLMapperMockFactory.BOLProductMapperMock,
                                                  mock.DALMapperMockFactory.DALProductMapperMock,
                                                  mock.BOLMapperMockFactory.BOLProductModelIllustrationMapperMock,
                                                  mock.DALMapperMockFactory.DALProductModelIllustrationMapperMock,
                                                  mock.BOLMapperMockFactory.BOLProductModelProductDescriptionCultureMapperMock,
                                                  mock.DALMapperMockFactory.DALProductModelProductDescriptionCultureMapperMock);

            UpdateResponse <ApiProductModelResponseModel> response = await service.Update(default(int), model);

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.ProductModelModelValidatorMock.Verify(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiProductModelRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Update(It.IsAny <ProductModel>()));
        }
Exemplo n.º 3
0
        public void Update_ProductMetricNull_ThrowsArgumentException()
        {
            //Arrange
            ProductModel invalidProductModel = new ProductModel
            {
                Id              = 1,
                Name            = "Rust In Peace Hoodie",
                ProductCategory = new ProductCategory {
                    Id = 4
                },
                ProductMetric = null,
                Price         = 120,
                Products      = null
            };

            Mock <IProductModelRepository> productModelRepository = new Mock <IProductModelRepository>();

            productModelRepository.Setup(repo => repo.Read(invalidProductModel.Id)).
            Returns(invalidProductModel);
            Mock <IProductCategoryRepository> productCategoryRepository = new Mock <IProductCategoryRepository>();

            productCategoryRepository.Setup(repo => repo.Read(invalidProductModel.ProductCategory.Id)).
            Returns(invalidProductModel.ProductCategory);
            Mock <IProductMetricRepository> productMetricRepository = new Mock <IProductMetricRepository>();

            IProductModelService productModelService = new ProductModelService(productModelRepository.Object,
                                                                               productCategoryRepository.Object, productMetricRepository.Object);

            //Act
            Action actual = () => productModelService.Update(invalidProductModel);

            //Assert
            Assert.Throws <ArgumentException>(actual);
        }
Exemplo n.º 4
0
        public void Update_NameEmpty_ThrowsArgumentException()
        {
            //Arrange
            ProductModel invalidProductModel = new ProductModel
            {
                Id              = 1,
                Name            = "",
                ProductCategory = new ProductCategory {
                    Id = 2
                },
                ProductMetric = new ProductMetric {
                    Id = 4
                },
                Price    = 130,
                Products = null
            };

            Mock <IProductModelRepository>    productModelRepository    = new Mock <IProductModelRepository>();
            Mock <IProductCategoryRepository> productCategoryRepository = new Mock <IProductCategoryRepository>();
            Mock <IProductMetricRepository>   productMetricRepository   = new Mock <IProductMetricRepository>();

            IProductModelService productModelService = new ProductModelService(productModelRepository.Object,
                                                                               productCategoryRepository.Object, productMetricRepository.Object);

            //Act
            Action actual = () => productModelService.Update(invalidProductModel);

            //Assert
            Assert.Throws <ArgumentException>(actual);
        }
Exemplo n.º 5
0
        public void Update_ProductModelNull_ThrowsArgumentNullException()
        {
            //Arrange
            ProductModel invalidProductModel = null;

            Mock <IProductModelRepository>    productModelRepository    = new Mock <IProductModelRepository>();
            Mock <IProductCategoryRepository> productCategoryRepository = new Mock <IProductCategoryRepository>();
            Mock <IProductMetricRepository>   productMetricRepository   = new Mock <IProductMetricRepository>();

            IProductModelService productModelService = new ProductModelService(productModelRepository.Object,
                                                                               productCategoryRepository.Object, productMetricRepository.Object);

            //Act
            Action actual = () => productModelService.Update(invalidProductModel);

            //Assert
            Assert.Throws <ArgumentNullException>(actual);
        }
Exemplo n.º 6
0
        public void Update_ProductModelValid_ReturnsUpdatedProductModel()
        {
            //Arrange
            ProductModel validProductModel = new ProductModel
            {
                Id              = 3,
                Name            = "Rust In Peace Hoodie",
                ProductCategory = new ProductCategory {
                    Id = 2
                },
                ProductMetric = new ProductMetric {
                    Id = 4
                },
                Price    = 130,
                Products = null
            };
            ProductModel expected = validProductModel;

            Mock <IProductModelRepository> productModelRepository = new Mock <IProductModelRepository>();

            productModelRepository.Setup(repo => repo.Read(validProductModel.Id)).
            Returns(validProductModel);
            productModelRepository.Setup(repo => repo.Update(validProductModel)).
            Returns(validProductModel);
            Mock <IProductCategoryRepository> productCategoryRepository = new Mock <IProductCategoryRepository>();

            productCategoryRepository.Setup(repo => repo.Read(validProductModel.ProductCategory.Id)).
            Returns(validProductModel.ProductCategory);
            Mock <IProductMetricRepository> productMetricRepository = new Mock <IProductMetricRepository>();

            productMetricRepository.Setup(repo => repo.Read(validProductModel.ProductMetric.Id)).
            Returns(validProductModel.ProductMetric);

            IProductModelService productModelService = new ProductModelService(productModelRepository.Object,
                                                                               productCategoryRepository.Object, productMetricRepository.Object);

            //Act
            ProductModel actual = productModelService.Update(validProductModel);

            //Assert
            Assert.Equal(expected, actual);
        }
Exemplo n.º 7
0
        public void Update_IdNotExisting_ThrowsArgumentException()
        {
            //Arrange
            ProductModel nonExistingProductModel = new ProductModel
            {
                Id              = 1,
                Name            = "Rust In Peace Hoodie",
                ProductCategory = new ProductCategory {
                    Id = 2
                },
                ProductMetric = new ProductMetric {
                    Id = 4
                },
                Price    = 130,
                Products = null
            };

            ProductModel nullProductModel = null;

            Mock <IProductModelRepository> productModelRepository = new Mock <IProductModelRepository>();

            productModelRepository.Setup(repo => repo.Read(nonExistingProductModel.Id)).
            Returns(nullProductModel);
            Mock <IProductCategoryRepository> productCategoryRepository = new Mock <IProductCategoryRepository>();

            productCategoryRepository.Setup(repo => repo.Read(nonExistingProductModel.ProductCategory.Id)).
            Returns(nonExistingProductModel.ProductCategory);
            Mock <IProductMetricRepository> productMetricRepository = new Mock <IProductMetricRepository>();

            productMetricRepository.Setup(repo => repo.Read(nonExistingProductModel.ProductMetric.Id)).
            Returns(nonExistingProductModel.ProductMetric);

            IProductModelService productModelService = new ProductModelService(productModelRepository.Object,
                                                                               productCategoryRepository.Object, productMetricRepository.Object);

            //Act
            Action actual = () => productModelService.Update(nonExistingProductModel);

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