Пример #1
0
        public void AddFlavorShouldReturnUnprocessableEntityIfModelStateIsInvalid()
        {
            // Arrange
            var mock = new Mock <IPizzaFlavorService>();

            Service    = mock.Object;
            Controller = new PizzaFlavorsController(Service);
            Controller.Configuration = new HttpConfiguration();
            Controller.Request       = new HttpRequestMessage();
            Controller.ModelState.AddModelError("", "");
            var mockAddModel = Builder <PizzaFlavorAddModel> .CreateNew().Build();

            // Act
            var result = Controller.Add(mockAddModel);

            // Assert
            Assert.AreEqual(422, (int)result.StatusCode);
        }
Пример #2
0
        public void AddFlavorShouldReturnInternalServerErrorIfServiceAddReturnsFalse()
        {
            // Arrange
            var mock = new Mock <IPizzaFlavorService>();

            mock.Setup <bool>(_ => _.Add(It.IsAny <PizzaFlavorAddModel>()))
            .Returns(false);
            Service    = mock.Object;
            Controller = new PizzaFlavorsController(Service);
            Controller.Configuration = new HttpConfiguration();
            Controller.Request       = new HttpRequestMessage();
            var mockAddModel = Builder <PizzaFlavorAddModel> .CreateNew().Build();

            // Act
            var result = Controller.Add(mockAddModel);

            // Assert
            Assert.AreEqual(HttpStatusCode.InternalServerError, result.StatusCode);
        }