コード例 #1
0
        public void SaveProductOption_ThrowsException()
        {
            // Arrange
            var productOption = new ProductOption
            {
                Id          = 1,
                Code        = "PO1",
                Description = "Description",
                ProductId   = 1
            };

            _productRepository.Setup(x => x.AddProductOption(productOption)).Throws(new Exception("An error occurred while adding new Product Option"));
            var productCommandService = new ProductCommandService(_productRepository.Object, _logger.Object);

            // Act & Assert
            Assert.Throws <Exception>(() => productCommandService.SaveProductOption(productOption));
        }
コード例 #2
0
        public void SaveProductOption_PositiveScenario()
        {
            // Arrange
            var productOption = new ProductOption
            {
                Id          = 1,
                Code        = "PO1",
                Description = "Description",
                ProductId   = 1
            };

            _productRepository.Setup(x => x.AddProductOption(productOption)).Returns(productOption.Id);
            var productCommandService = new ProductCommandService(_productRepository.Object, _logger.Object);

            // Act
            int productOptionId = productCommandService.SaveProductOption(productOption);

            // Assert
            _productRepository.Verify(x => x.AddProductOption(productOption), Times.Once);
            Assert.Equal(productOptionId, productOption.Id);
        }