public void Good_Post_Create()
        {
            // Arrange
            var informationItemViewModel = new InformationItemViewModel()
            {
                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 informationItem = new InformationItem()
            {
                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 fileName    = "text.jpg";
            var fileLength  = 1000;
            var contentType = "image";
            var fakeImage   = Substitute.For <HttpPostedFileBase>();
            var validator   = new ModelValidator <InformationItemViewModel>(informationItemViewModel);
            var service     = Substitute.For <IInformationItemService>();

            fakeImage.FileName.Returns(fileName);
            fakeImage.ContentType.Returns(contentType);
            fakeImage.ContentLength.Returns(fileLength);

            var controller = new InformationItemController(service);

            service.MapViewModelToObject(informationItemViewModel).Returns(informationItem);
            informationItem.PictureUrl = service.AddInformationItemImage(fakeImage);
            service.CreateInformationItem(informationItem);
            service.SaveInfomrationItem();

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

            validator.AddToModelError(controller);
            var result     = controller.Create(informationItemViewModel, fakeImage) as RedirectToRouteResult;
            var actionName = result.RouteValues.Values.ElementAt(0);

            // Assert
            Assert.That(result, !Is.Null);
            Assert.That("Index", Is.EqualTo(actionName));
            Assert.That(valid, Is.True);
        }
        public void Post_Create_File_Is_Null_Or_ContentLength_0_Or_Content_Type_Not_Image()
        {
            // Arrange
            var informationItemViewModel = new InformationItemViewModel()
            {
                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. "
            };
            HttpPostedFileBase fakeImage = null;
            var service    = Substitute.For <IInformationItemService>();
            var controller = new InformationItemController(service);

            // Act
            var result     = controller.Create(informationItemViewModel, fakeImage) as RedirectToRouteResult;
            var actionName = result.RouteValues.Values.ElementAt(0);
            var tempData   = controller.TempData["ModelIsNotValid"];

            // Assert
            Assert.That(result, !Is.Null);
            Assert.That("Index", Is.EqualTo(actionName));
            Assert.That("Zdjęcie nie zostało przesłane prawidłowo. Spróbuj ponownie.", Is.EqualTo(tempData));
        }
        public void Post_Create_Model_Not_Valid()
        {
            // Arrange
            var informationItemViewModel = new InformationItemViewModel()
            {
                //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 fileName    = "text.jpg";
            var fileLength  = 1000;
            var contentType = "image";
            var fakeImage   = Substitute.For <HttpPostedFileBase>();
            var validator   = new ModelValidator <InformationItemViewModel>(informationItemViewModel);
            var service     = Substitute.For <IInformationItemService>();

            fakeImage.FileName.Returns(fileName);
            fakeImage.ContentType.Returns(contentType);
            fakeImage.ContentLength.Returns(fileLength);

            var controller = new InformationItemController(service);

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

            validator.AddToModelError(controller);
            var result     = controller.Create(informationItemViewModel, fakeImage) as RedirectToRouteResult;
            var actionName = result.RouteValues.Values.ElementAt(0);
            var tempData   = controller.TempData["ModelIsNotValid"];

            // Assert
            Assert.That(valid, Is.False);
            Assert.That(result, !Is.Null);
            Assert.That("Wystąpił błąd w formularzu, spróbuj ponownie.", Is.EqualTo(tempData));
            Assert.That("Index", Is.EqualTo(actionName));
        }