public void EditPost_WithNotSuccessfullEdit_ShouldReturnBadRequest()
        {
            // Arrange
            Mock <IPublicationService> publicationService = new Mock <IPublicationService>();

            const int journalId = 1;
            PublicationFormServiceModel formModel = this.GetPublicationFormServiceModel();

            publicationService
            .Setup(p => p.GetTitle(It.IsAny <int>()))
            .Returns(formModel.Title);

            publicationService
            .Setup(p => p.TitleExists(It.IsAny <string>()))
            .Returns(false);

            publicationService
            .Setup(p => p.Edit(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <string>()))
            .Returns(false);

            PublicationsController publicationsController = new PublicationsController(publicationService.Object, null, null, null);

            // Act
            IActionResult result = publicationsController.Edit(journalId, formModel);

            // Assert
            Assert.IsType <BadRequestResult>(result);
        }
        public void EditGet_WithExistingPublicationId_ShouldReturnView()
        {
            // Arrange
            Mock <IPublicationService> publicationService = new Mock <IPublicationService>();

            const int journalId = 1;
            PublicationFormServiceModel formModel = this.GetPublicationFormServiceModel();

            publicationService
            .Setup(p => p.GetForm(It.IsAny <int>()))
            .Returns(formModel);

            PublicationsController publicationsController = new PublicationsController(publicationService.Object, null, null, null);

            // Act
            IActionResult result = publicationsController.Edit(journalId);

            // Assert
            Assert.IsType <ViewResult>(result);
            object model = (result as ViewResult).Model;

            Assert.IsType <PublicationFormServiceModel>(model);
            PublicationFormServiceModel returnModel = model as PublicationFormServiceModel;

            this.AssertPublications(formModel, returnModel);
        }
        public void EditPost_WithNewExistingTitle_ShouldReturnCorrectView()
        {
            // Arrange
            Mock <IPublicationService> publicationService = new Mock <IPublicationService>();
            Mock <ITempDataDictionary> tempData           = new Mock <ITempDataDictionary>();

            const int journalId = 1;
            PublicationFormServiceModel formModel = this.GetPublicationFormServiceModel();

            publicationService
            .Setup(p => p.GetTitle(It.IsAny <int>()))
            .Returns(formModel.Title);

            formModel.Title = "New Title";

            publicationService
            .Setup(p => p.TitleExists(It.IsAny <string>()))
            .Returns(true);

            string errorMessage = null;

            tempData
            .SetupSet(t => t[WebConstants.TempDataErrorMessage]    = It.IsAny <string>())
            .Callback((string key, object message) => errorMessage = message as string);

            PublicationsController publicationsController = new PublicationsController(publicationService.Object, null, null, null);

            publicationsController.TempData = tempData.Object;

            // Act
            IActionResult result = publicationsController.Edit(journalId, formModel);

            // Assert
            Assert.IsType <ViewResult>(result);
            object model = (result as ViewResult).Model;

            Assert.IsType <PublicationFormServiceModel>(model);
            PublicationFormServiceModel returnModel = model as PublicationFormServiceModel;

            this.AssertPublications(formModel, returnModel);
            Assert.Equal(string.Format(WebConstants.EntryExists, Publication), errorMessage);
        }
        public void EditGet_WithNotExistingPublicationId_ShouldReturnBadRequest()
        {
            // Arrange
            Mock <IPublicationService> publicationService = new Mock <IPublicationService>();

            const int journalId = 1;
            PublicationFormServiceModel formModel = null;

            publicationService
            .Setup(p => p.GetForm(It.IsAny <int>()))
            .Returns(formModel);

            PublicationsController publicationsController = new PublicationsController(publicationService.Object, null, null, null);

            // Act
            IActionResult result = publicationsController.Edit(journalId);

            // Assert
            Assert.IsType <BadRequestResult>(result);
        }
        public void EditPost_WithSuccessfullEdit_ShouldReturnRedirectResult()
        {
            // Arrange
            Mock <IPublicationService> publicationService = new Mock <IPublicationService>();
            Mock <ITempDataDictionary> tempData           = new Mock <ITempDataDictionary>();

            const int journalId = 1;
            PublicationFormServiceModel formModel = this.GetPublicationFormServiceModel();

            publicationService
            .Setup(p => p.GetTitle(It.IsAny <int>()))
            .Returns("Fake Title");

            publicationService
            .Setup(p => p.TitleExists(It.IsAny <string>()))
            .Returns(false);

            publicationService
            .Setup(p => p.Edit(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <string>()))
            .Returns(true);

            string successmessage = null;

            tempData
            .SetupSet(t => t[WebConstants.TempDataSuccessMessage]    = It.IsAny <string>())
            .Callback((string key, object message) => successmessage = message as string);

            PublicationsController publicationsController = new PublicationsController(publicationService.Object, null, null, null);

            publicationsController.TempData = tempData.Object;

            // Act
            IActionResult result = publicationsController.Edit(journalId, formModel);

            // Assert
            Assert.IsType <RedirectToActionResult>(result);
            RedirectToActionResult redirectResult = result as RedirectToActionResult;

            this.AssertRedirect(journalId, redirectResult);
            Assert.Equal(string.Format(WebConstants.SuccessfullEntityOperation, Publication, WebConstants.Edited), successmessage);
        }