public void Post_Edit_Is_Not_Valid()
        {
            // Arrange
            var informationItemViewModel = new InformationItemViewModel()
            {
                PictureUrl = "/Content/Images/pizza_1.jpg",
                //Position = 1,
                //Title = "Menu",
                Content = "Ut at viverra arcu. Donec sed interdum nulla, eu porttitor lorem. Morbi efficitur sapien ullamcorper lorem vestibulum, ut aliquet turpis consequat. Suspendisse ac nibh non velit scelerisque bibendum. "
            };
            var service    = Substitute.For <IInformationItemService>();
            var controller = new InformationItemController(service);
            var validator  = new ModelValidator <InformationItemViewModel>(informationItemViewModel);

            // Act
            var valid = validator.IsValid();

            validator.AddToModelError(controller);
            var result   = controller.Edit(informationItemViewModel) as RedirectToRouteResult;
            var tempData = controller.TempData["ModelIsNotValid"];

            // Assert
            Assert.That(result, !Is.Null);
            Assert.That(valid, Is.False);
            Assert.That("Wystąpił błąd w formularzu, spróbuj ponownie.", Is.EqualTo(tempData));
        }
        public void Post_Edit_Model_Is_Null()
        {
            // Arrange
            var             id = -1;
            InformationItem informationItem          = null;
            var             informationItemViewModel = new InformationItemViewModel()
            {
                PictureUrl = "/Content/Images/pizza_1.jpg",
                Position   = 1,
                Title      = "Menu",
                Content    = "Ut at viverra arcu. Donec sed interdum nulla, eu porttitor lorem. Morbi efficitur sapien ullamcorper lorem vestibulum, ut aliquet turpis consequat. Suspendisse ac nibh non velit scelerisque bibendum. "
            };
            var service    = Substitute.For <IInformationItemService>();
            var validator  = new ModelValidator <InformationItemViewModel>(informationItemViewModel);
            var controller = new InformationItemController(service);

            service.GetInfomrationItem(id).Returns(informationItem);

            // Act
            var valid = validator.IsValid();

            validator.AddToModelError(controller);
            var result     = controller.Edit(informationItemViewModel) as HttpNotFoundResult;
            var statusCode = result.StatusCode;

            // Assert
            Assert.That(result, !Is.Null);
            Assert.That(valid, Is.True);
            Assert.That(404, Is.EqualTo(statusCode));
        }
        public void Get_Edit_Id_Is_Null()
        {
            // Arrange
            int?id         = null;
            var service    = Substitute.For <IInformationItemService>();
            var controller = new InformationItemController(service);

            // Act
            var result     = controller.Edit(id) as HttpStatusCodeResult;
            var statusCode = result.StatusCode;

            // Assert
            Assert.That(result, !Is.Null);
            Assert.That(400, Is.EqualTo(statusCode));
        }
        public void Get_Edit_Model_Null()
        {
            // Arrange
            var             id = 1;
            InformationItem informationItem = null;
            var             service         = Substitute.For <IInformationItemService>();
            var             controller      = new InformationItemController(service);

            service.GetInfomrationItem(id).Returns(informationItem);

            // Act
            var result     = controller.Edit(id) as HttpNotFoundResult;
            var statusCode = result.StatusCode;

            // Assert
            Assert.That(result, !Is.Null);
            Assert.That(404, Is.EqualTo(statusCode));
        }
        public void Good_Post_Edit()
        {
            // Arrange
            var informationItem = new InformationItem()
            {
                ID         = 1,
                PictureUrl = "/Content/Images/pizza_1.jpg",
                Position   = 1,
                Title      = "Menu",
                Content    = "Ut at viverra arcu. Donec sed interdum nulla, eu porttitor lorem. Morbi efficitur sapien ullamcorper lorem vestibulum, ut aliquet turpis consequat. Suspendisse ac nibh non velit scelerisque bibendum. "
            };
            var informationItemViewModel = new InformationItemViewModel()
            {
                ID         = 1,
                PictureUrl = "/Content/Images/pizza_1.jpg",
                Position   = 1,
                Title      = "Menu",
                Content    = "Ut at viverra arcu. Donec sed interdum nulla, eu porttitor lorem. Morbi efficitur sapien ullamcorper lorem vestibulum, ut aliquet turpis consequat. Suspendisse ac nibh non velit scelerisque bibendum. "
            };
            var service        = Substitute.For <IInformationItemService>();
            var validator      = new ModelValidator <InformationItemViewModel>(informationItemViewModel);
            var fakeController = new FakeController();
            var controller     = new InformationItemController(service);

            fakeController.PrepareFakeAjaxRequest();
            controller.ControllerContext = fakeController.GetControllerContext <InformationItemController>(new RouteData(), controller);
            service.GetInfomrationItem(informationItem.ID).Returns(informationItem);
            service.UpdateInformationItem(informationItem);
            service.SaveInfomrationItem();

            // Act
            var valid = validator.IsValid();

            validator.AddToModelError(controller);
            var result      = controller.Edit(informationItemViewModel) as RedirectToRouteResult;
            var actionName  = result.RouteValues.Values.ElementAt(0);
            var ajaxRequest = controller.Request.IsAjaxRequest();

            // Assert
            Assert.That(result, !Is.Null);
            Assert.That("Index", Is.EqualTo(actionName));
            Assert.That(ajaxRequest, Is.True);
            Assert.That(valid, Is.True);
        }
        public void Good_Get_Edit()
        {
            // Arrange
            var id = 1;
            var informationItem = new InformationItem()
            {
                ID         = 1,
                PictureUrl = "/Content/Images/pizza_1.jpg",
                Position   = 1,
                Title      = "Menu",
                Content    = "Ut at viverra arcu. Donec sed interdum nulla, eu porttitor lorem. Morbi efficitur sapien ullamcorper lorem vestibulum, ut aliquet turpis consequat. Suspendisse ac nibh non velit scelerisque bibendum. "
            };
            var informationItemViewModel = new InformationItemViewModel()
            {
                ID         = 1,
                PictureUrl = "/Content/Images/pizza_1.jpg",
                Position   = 1,
                Title      = "Menu",
                Content    = "Ut at viverra arcu. Donec sed interdum nulla, eu porttitor lorem. Morbi efficitur sapien ullamcorper lorem vestibulum, ut aliquet turpis consequat. Suspendisse ac nibh non velit scelerisque bibendum. "
            };
            var service        = Substitute.For <IInformationItemService>();
            var fakeController = new FakeController();
            var controller     = new InformationItemController(service);

            fakeController.PrepareFakeAjaxRequest();
            controller.ControllerContext = fakeController.GetControllerContext <InformationItemController>(new RouteData(), controller);
            service.GetInfomrationItem(id).Returns(informationItem);
            service.MapObjectToViewModel(informationItem).Returns(informationItemViewModel);
            // Act
            var result      = controller.Edit(id) as PartialViewResult;
            var viewName    = result.ViewName;
            var model       = result.Model;
            var ajaxRequest = controller.Request.IsAjaxRequest();

            // Assert
            Assert.That(result, !Is.Null);
            Assert.That("_EditPartial", Is.EqualTo(viewName));
            Assert.That(ajaxRequest, Is.True);
            Assert.That(model, !Is.Null);
        }