Пример #1
0
        public void Update_IdNonExisting_ThrowsArgumentException()
        {
            //Arrange
            ProductMetric invalidProductMetric = new ProductMetric
            {
                Id      = 1,
                Name    = "Oversized Hoodie",
                MetricX = "Width",
                MetricY = "Length",
                MetricZ = "Sleeve Length"
            };

            ProductMetric nullProductMetric = null;

            Mock <IProductMetricRepository> productMetricRepository = new Mock <IProductMetricRepository>();

            productMetricRepository.Setup(repo => repo.Read(invalidProductMetric.Id)).
            Returns(nullProductMetric);

            IProductMetricService productMetricService = new ProductMetricService(productMetricRepository.Object);

            //Act
            Action actual = () => productMetricService.Update(invalidProductMetric);

            //Assert
            Assert.Throws <ArgumentException>(actual);
        }
Пример #2
0
        public void Update_ProductMetricValid_ReturnsUpdatedProductMetric()
        {
            //Arrange
            ProductMetric validProductMetric = new ProductMetric
            {
                Id      = 1,
                Name    = "Oversized Hoodie",
                MetricX = "Width",
                MetricY = "Length",
                MetricZ = "Sleeve Length"
            };

            ProductMetric expected = validProductMetric;

            Mock <IProductMetricRepository> productMetricRepository = new Mock <IProductMetricRepository>();

            productMetricRepository.Setup(repo => repo.Read(validProductMetric.Id)).
            Returns(validProductMetric);
            productMetricRepository.Setup(repo => repo.Update(validProductMetric)).
            Returns(expected);

            IProductMetricService productMetricService = new ProductMetricService(productMetricRepository.Object);

            //Act
            ProductMetric actual = productMetricService.Update(validProductMetric);

            //Assert
            Assert.Equal(expected, actual);
        }
Пример #3
0
        public void Update_ProductMetricNull_ThrowsArgumentNullException()
        {
            //Arrange
            ProductMetric invalidProductMetric = null;

            Mock <IProductMetricRepository> productMetricRepository = new Mock <IProductMetricRepository>();

            IProductMetricService productMetricService = new ProductMetricService(productMetricRepository.Object);

            //Act
            Action actual = () => productMetricService.Update(invalidProductMetric);

            //Assert
            Assert.Throws <ArgumentNullException>(actual);
        }
Пример #4
0
        public void Update_MetricXEmpty_ThrowsArgumentException()
        {
            //Arrange
            ProductMetric invalidProductMetric = new ProductMetric
            {
                Id      = 3,
                Name    = "Oversized Hoodie",
                MetricX = "",
                MetricY = "Length",
                MetricZ = "Sleeve Length"
            };

            Mock <IProductMetricRepository> productMetricRepository = new Mock <IProductMetricRepository>();

            IProductMetricService productMetricService = new ProductMetricService(productMetricRepository.Object);

            //Act
            Action actual = () => productMetricService.Update(invalidProductMetric);

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