Exemple #1
0
        public void Delete_IdExisting_ReturnsDeletedProductMetricWithSpecifiedId()
        {
            //Arrange
            int           existingId = 12;
            ProductMetric expected   = new ProductMetric
            {
                Id      = existingId,
                Name    = "Oversized Hoodie",
                MetricX = "",
                MetricY = "Length",
                MetricZ = "Sleeve Length"
            };

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

            productMetricRepository.Setup(repo => repo.Delete(existingId)).
            Returns(expected);

            IProductMetricService productMetricService = new ProductMetricService(productMetricRepository.Object);

            //Act
            ProductMetric actual = productMetricService.Delete(existingId);

            //Assert
            Assert.Equal(expected, actual);
        }
Exemple #2
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);
        }
Exemple #3
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);
        }
Exemple #4
0
        public void Create_ProductMetricNull_ThrowsArgumentNullException()
        {
            //Arrange
            ProductMetric invalidProductMetric = null;

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

            IProductMetricService productMetricService = new ProductMetricService(productMetricRepository.Object);

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

            //Assert
            Assert.Throws <ArgumentNullException>(actual);
        }
Exemple #5
0
        public void Delete_IdNonExisting_ReturnsNull()
        {
            //Arrange
            int           existingId = 12;
            ProductMetric expected   = null;

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

            productMetricRepository.Setup(repo => repo.Delete(existingId)).
            Returns(expected);

            IProductMetricService productMetricService = new ProductMetricService(productMetricRepository.Object);

            //Act
            ProductMetric actual = productMetricService.Delete(existingId);

            //Assert
            Assert.Equal(expected, actual);
        }
Exemple #6
0
        public void Create_NameNull_ThrowsArgumentException()
        {
            //Arrange
            ProductMetric invalidProductMetric = new ProductMetric
            {
                Name    = null,
                MetricX = "Width",
                MetricY = "Length",
                MetricZ = "Sleeve Length"
            };

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

            IProductMetricService productMetricService = new ProductMetricService(productMetricRepository.Object);

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

            //Assert
            Assert.Throws <ArgumentException>(actual);
        }
Exemple #7
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);
        }