Ejemplo n.º 1
0
        public async Task AddManyProductOptionsAsync_InvalidProductId_ThrowException()
        {
            //Arrange
            var options = new List <ProductOption>()
            {
                new ProductOption()
                {
                    Name        = "6b64c5a8-00f9-4a57-a62b-54198117ef54",
                    Description = "Option 1"
                },
                new ProductOption()
                {
                    Name        = "15601605-3d80-452d-8170-89368bad5f0a",
                    Description = "Option 2"
                }
            };

            var product = new Models.Product()
            {
                Id = "7fb87db7-4c8d-4e19-905d-0d3fb88fb6a4"
            };

            _productRepository.Setup(x => x.GetAsync(It.IsAny <Guid>())).ThrowsAsync(new ProductNotFoundException("Product not found"));


            //Act
            var productOptionService = new ProductOptionService(_logger.Object,
                                                                _productRepository.Object,
                                                                _productOptionRepository.Object);

            //Assert
            Assert.ThrowsAsync <ProductNotFoundException>(async() => await productOptionService.AddManyProductOptionsAsync(product.Id, options));
        }
        public async Task UpdateProductOptionShouldReturnSuccessWhenCommandSuccess()
        {
            // Arrange
            _mediator.Setup(e => e.Send(It.IsAny <UpdateProductOptionCommand>(), It.IsAny <CancellationToken>())).Returns(Task.CompletedTask);

            // Act
            var service = new ProductOptionService(_mapper.Object, _mediator.Object);

            var result = await service.UpdateProductOption(new UpdateProductOptionCommand(Guid.NewGuid(), "name", "desc"));

            // Assert
            Assert.AreEqual(result.IsSuccess, true);
        }
        public async Task UpdateProductOptionShouldReturnExeptionWhenCommandFail()
        {
            // Arrange
            _mediator.Setup(e => e.Send(It.IsAny <UpdateProductOptionCommand>(), It.IsAny <CancellationToken>())).ThrowsAsync(new Exception("Exception error!"));

            // Act
            var service = new ProductOptionService(_mapper.Object, _mediator.Object);

            var result = await service.UpdateProductOption(new UpdateProductOptionCommand(Guid.NewGuid(), "name", "desc"));

            // Assert
            Assert.AreEqual(result.IsSuccess, false);
            Assert.AreEqual(result.FailureReason, "Exception error!");
        }
Ejemplo n.º 4
0
        public void Initialize()
        {
            //Arrange for Tests
            var mapperConfig = new MapperConfiguration(cnfig =>
            {
                cnfig.AddProfile(new RepositoryMapper());
            });

            _mapper = mapperConfig.CreateMapper();

            _mockContext = new FakeDatabaseEntitiesContext
            {
                Products =
                {
                    new data.Product {
                        Id = new Guid("8f2e9176-35ee-4f0a-ae55-83023d2db1a3"), Name = "Samsung Galaxy S7", Description = "Newest mobile product from Samsung.", Price = 1024.99M, DeliveryPrice = 16.99M
                    },
                    new data.Product {
                        Id = new Guid("de1287c0-4b15-4a7b-9d8a-dd21b3cafec3"), Name = "Apple iPhone 6S", Description = "Newest mobile product from Apple.", Price = 1299.99M, DeliveryPrice = 15.99M
                    }
                },
                ProductOptions =
                {
                    new data.ProductOption {
                        Id = new Guid("0643ccf0-ab00-4862-b3c5-40e2731abcc9"), ProductId = new Guid("8f2e9176-35ee-4f0a-ae55-83023d2db1a3"), Name = "White", Description = "White Samsung Galaxy S7"
                    },
                    new data.ProductOption {
                        Id = new Guid("a21d5777-a655-4020-b431-624bb331e9a2"), ProductId = new Guid("8f2e9176-35ee-4f0a-ae55-83023d2db1a3"), Name = "Black", Description = "Black Samsung Galaxy S7"
                    },
                    new data.ProductOption {
                        Id = new Guid("5c2996ab-54ad-4999-92d2-89245682d534"), ProductId = new Guid("de1287c0-4b15-4a7b-9d8a-dd21b3cafec3"), Name = "Rose Gold", Description = "Gold Apple iPhone 6S"
                    }
                }
            };
            _logging = new LoggingService();
            var productOptionRepository = new ProductOptionRepository(_mapper, _mockContext, _logging);
            var productRepository       = new ProductRepository(_mapper, _mockContext, _logging);

            var productOptionService = new ProductOptionService(productOptionRepository);
            var productService       = new ProductService(productRepository);

            _Controller = new ProductsController(productService, productOptionService, _logging);
        }
        public async Task CreateProductOptionShouldReturnGroupedValidationExeptionWhenCommandFail()
        {
            // Arrange
            var validationExceptions = new List <ValidationFailure>()
            {
                new ValidationFailure("p1", "error p1"),
                new ValidationFailure("p2", "error p2")
            };

            _mediator.Setup(e => e.Send(It.IsAny <CreateProductOptionCommand>(), It.IsAny <CancellationToken>())).ThrowsAsync(new ValidationException(validationExceptions));

            // Act
            var service = new ProductOptionService(_mapper.Object, _mediator.Object);

            var result = await service.CreateProductOption(new CreateProductOptionCommand(Guid.NewGuid(), "name", "desc"));

            // Assert
            Assert.AreEqual(result.IsSuccess, false);
            Assert.IsTrue(result.FailureReason.Contains("error p1"));
            Assert.IsTrue(result.FailureReason.Contains("error p2"));
        }
Ejemplo n.º 6
0
        public async Task AddManyProductOptionsAsync_ValidProductIdAndOptions_ReturnOptions()
        {
            //Arrange
            var options = new List <ProductOption>()
            {
                new ProductOption()
                {
                    Name        = "6b64c5a8-00f9-4a57-a62b-54198117ef54",
                    Description = "Option 1"
                },
                new ProductOption()
                {
                    Name        = "15601605-3d80-452d-8170-89368bad5f0a",
                    Description = "Option 2"
                }
            };

            var product = new Models.Product()
            {
                Id = "7fb87db7-4c8d-4e19-905d-0d3fb88fb6a4"
            };

            _productRepository.Setup(x => x.GetAsync(It.IsAny <Guid>())).ReturnsAsync(product);


            //Act
            var productOptionService = new ProductOptionService(_logger.Object,
                                                                _productRepository.Object,
                                                                _productOptionRepository.Object);

            var result = await productOptionService.AddManyProductOptionsAsync(product.Id, options);

            //Assert
            _productOptionRepository.Verify(x => x.CreateManyAsync(It.IsAny <List <ProductOption> >()), Times.Once);
            Assert.IsNotNull(result);
        }
Ejemplo n.º 7
0
 public void SetUp()
 {
     _productOptionsRepositoryMock = new Mock <IProductOptionsRepository>();
     _underTest = new ProductOptionService(_productOptionsRepositoryMock.Object);
 }
 public ProductOptionsController(ProductOptionService service)
 {
     _optionService = service;
 }
Ejemplo n.º 9
0
        public void DeleteAllSharedOptions()
        {
            var all = ProductOptionService.GetPage(1, long.MaxValue);

            ((ProductOptionService)ProductOptionService).Delete(all.Items);
        }