public void CreatePost_WithNotSuccessfullyCreatedJournal_ShouldReturnBadRequest()
        {
            // Arrange
            Mock <IJournalService> journalService = new Mock <IJournalService>();

            journalService
            .Setup(s => s.Exists(It.IsAny <string>()))
            .Returns(false);

            journalService
            .Setup(s => s.Create(
                       It.IsAny <string>(),
                       It.IsAny <string>(),
                       It.IsAny <string>()))
            .Returns(-1);

            JournalFormServiceModel formModel          = this.GetJournalFormModel();
            JournalsController      journalsController = new JournalsController(journalService.Object);

            journalsController.TempData = Mock.Of <ITempDataDictionary>();

            // Act
            IActionResult result = journalsController.Create(formModel);

            // Assert
            Assert.IsType <BadRequestResult>(result);
        }
        public void EditGet_WithExistingJournalId_ShouldRetunView()
        {
            // Arrange
            Mock <IJournalService>  journalService = new Mock <IJournalService>();
            JournalFormServiceModel formModel      = this.GetJournalFormModel();

            journalService
            .Setup(s => s.GetForm(It.IsAny <int>()))
            .Returns(formModel);

            JournalsController journalsController = new JournalsController(journalService.Object);

            journalsController.TempData = Mock.Of <ITempDataDictionary>();

            // Act
            IActionResult result = journalsController.Edit(1);

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

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

            this.AssertJournals(formModel, returnModel);
        }
        public void EditPost_WithNotSuccessfullEdit_ShouldReturnBadRequest()
        {
            // Arranges
            Mock <IJournalService> journalService = new Mock <IJournalService>();

            JournalFormServiceModel formModel = this.GetJournalFormModel();

            journalService
            .Setup(s => s.Exists(It.IsAny <string>()))
            .Returns(false);

            journalService
            .Setup(s => s.GetName(It.IsAny <int>()))
            .Returns(formModel.Name);

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

            JournalsController journalsController = new JournalsController(journalService.Object);

            // Act
            IActionResult result = journalsController.Edit(1, formModel);

            // Assert
            Assert.IsType <BadRequestResult>(result);
        }
Esempio n. 4
0
        public void All_ShouldReturnView()
        {
            // Arrange
            Mock <IJournalService> journalService = new Mock <IJournalService>();
            ListJournalsViewModel  listModel      = this.GetListJournalsViewModel();

            journalService
            .Setup(t => t.Total())
            .Returns(20);

            journalService
            .Setup(t => t.All(It.IsAny <int>(), It.IsAny <int>()))
            .Returns(this.GetListJournalsServiceModel());

            JournalsController journalsController = new JournalsController(journalService.Object);

            // Act
            IActionResult result = journalsController.All(2);

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

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

            this.AssertPages(listModel, returnModel);
            this.AssertJournals(listModel, returnModel);
        }
        public void CreatePost_WithExistingJournalName_ShouldReturnView()
        {
            // Arrange
            Mock <IJournalService> journalService = new Mock <IJournalService>();

            journalService
            .Setup(s => s.Exists(It.IsAny <string>()))
            .Returns(true);

            Mock <ITempDataDictionary> tempData = new Mock <ITempDataDictionary>();

            string errorMessage = null;

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

            JournalFormServiceModel formModel          = this.GetJournalFormModel();
            JournalsController      journalsController = new JournalsController(journalService.Object);

            journalsController.TempData = tempData.Object;

            // Act
            IActionResult result = journalsController.Create(formModel);

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

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

            this.AssertJournals(formModel, returnModel);
            Assert.Equal(string.Format(WebConstants.EntryExists, Journal), errorMessage);
        }
        public void CreateGet_ShouldReturnView()
        {
            // Arrange
            JournalsController journalsController = new JournalsController(null);

            // Act
            IActionResult result = journalsController.Create();

            // Assert
            Assert.IsType <ViewResult>(result);
        }
Esempio n. 7
0
        public async Task Delete_JournalFound_Deleted_ReturnsOk()
        {
            _mockService.Setup(s =>
                               s.Delete(It.IsAny <long>()));

            _controller = new JournalsController(_mockService.Object, _logger);

            var result = await _controller.Delete(1L);

            result.Should().BeOfType <OkResult>();
        }
Esempio n. 8
0
        public async Task GetAll_JournalsNotFound_ReturnsBadRequest()
        {
            _mockService.Setup(s =>
                               s.GetAll(It.IsAny <string>(), 5))
            .ReturnsAsync(() => null);

            _controller = new JournalsController(_mockService.Object, _logger);

            var result = await _controller.GetAll("UserId", 5);

            result.Should().BeOfType <NotFoundResult>();
        }
Esempio n. 9
0
        public async Task GetOne_JournalNotFound_ReturnsBadRequest()
        {
            _mockService.Setup(s =>
                               s.GetById(It.IsAny <long>()))
            .ReturnsAsync(() => null);

            _controller = new JournalsController(_mockService.Object, _logger);

            var result = await _controller.GetOne(1L);

            result.Should().BeOfType <NotFoundResult>();
        }
Esempio n. 10
0
        public async Task Add_UserFound_DuplicateTitle_ReturnsBadRequest()
        {
            _mockService.Setup(s =>
                               s.Add(It.IsAny <string>(), It.IsAny <string>()))
            .ReturnsAsync(() => null);

            _controller = new JournalsController(_mockService.Object, _logger);

            var result = await _controller.Add("UserId", new NewJournalDto { Title = "My Title" });

            result.Should().BeOfType <BadRequestResult>();
        }
        public void EditPost_WithSuccessfullEdit_ShouldReturnRedirectResult()
        {
            // Arranges
            Mock <IJournalService>  journalService = new Mock <IJournalService>();
            JournalFormServiceModel formModel      = this.GetJournalFormModel();

            const int journalId = 1;

            journalService
            .Setup(s => s.Exists(It.IsAny <string>()))
            .Returns(false);

            journalService
            .Setup(s => s.GetName(It.IsAny <int>()))
            .Returns(formModel.Name);

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

            Mock <ITempDataDictionary> tempData = new Mock <ITempDataDictionary>();

            string successmessage = null;

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

            JournalsController journalsController = new JournalsController(journalService.Object);

            journalsController.TempData = tempData.Object;

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

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

            this.AssertRedirect(journalId, redirectResult);
            Assert.Equal(string.Format(WebConstants.SuccessfullEntityOperation, Journal, WebConstants.Edited), successmessage);
        }
Esempio n. 12
0
        public void Details_WithNotExistingId_ShouldReturnBadRequest()
        {
            // Arrange
            Mock <IJournalService>     journalService = new Mock <IJournalService>();
            JournalDetailsServiceModel detailsModel   = null;

            journalService
            .Setup(t => t.Details(It.IsAny <int>()))
            .Returns(detailsModel);

            JournalsController journalsController = new JournalsController(journalService.Object);

            // Act
            IActionResult result = journalsController.Details(1);

            // Assert
            Assert.IsType <BadRequestResult>(result);
        }
Esempio n. 13
0
        public async Task Update_JournalFound_UpdateSuccessful_ReturnsOk()
        {
            var journal = new JournalDto
            {
                Id     = 1L,
                Title  = "Some Journal",
                UserId = "UserId"
            };

            _mockService.Setup(s =>
                               s.Update(It.IsAny <JournalDto>()))
            .ReturnsAsync(journal);

            _controller = new JournalsController(_mockService.Object, _logger);

            var result = await _controller.Update(journal.Id, journal);

            result.Should().BeOfType <OkObjectResult>();
        }
Esempio n. 14
0
        public async Task GetOne_JournalFound_ReturnsOk()
        {
            var journal = new Journal
            {
                Id     = 1L,
                Title  = "My Journal",
                UserId = "UserId"
            };

            _mockService.Setup(s =>
                               s.GetById(It.IsAny <long>()))
            .ReturnsAsync(new JournalDto(journal));

            _controller = new JournalsController(_mockService.Object, _logger);

            var result = await _controller.GetOne(1L);

            result.Should().BeOfType <OkObjectResult>();
        }
        public void EditPost_WithNotExistingJournalId_ShouldRetunBadRequest()
        {
            // Arrange
            Mock <IJournalService>  journalService = new Mock <IJournalService>();
            JournalFormServiceModel formModel      = null;

            journalService
            .Setup(s => s.GetForm(It.IsAny <int>()))
            .Returns(formModel);

            JournalsController journalsController = new JournalsController(journalService.Object);

            journalsController.TempData = Mock.Of <ITempDataDictionary>();

            // Act
            IActionResult result = journalsController.Edit(1);

            // Assert
            Assert.IsType <BadRequestResult>(result);
        }
Esempio n. 16
0
        public async Task Add_UserFound_UniqueTitle_JournalAdded_ReturnsOk()
        {
            const string userId     = "UserId";
            const string title      = "Squeaky New Journal";
            var          journalDto = new JournalDto
            {
                Title  = title,
                UserId = userId
            };

            _mockService.Setup(s =>
                               s.Add(It.IsAny <string>(), It.IsAny <string>()))
            .ReturnsAsync(journalDto);

            _controller = new JournalsController(_mockService.Object, _logger);

            var result = await _controller.Add(userId, new NewJournalDto { Title = title });

            result.Should().BeOfType <OkObjectResult>();
        }
Esempio n. 17
0
        public async Task GetAll_UserFound_ReturnsOkWithList()
        {
            const string userId   = "UserId";
            var          journals = new List <JournalDto>();

            for (var i = 0; i < 5; i++)
            {
                journals.Add(new JournalDto {
                    Title = $"Journal {i + 1}", UserId = userId
                });
            }

            _mockService.Setup(s =>
                               s.GetAll(It.IsAny <string>(), 5))
            .ReturnsAsync(journals);

            _controller = new JournalsController(_mockService.Object, _logger);

            var result = await _controller.GetAll(userId, page : 5);

            result.Should().BeOfType <OkObjectResult>();
        }
Esempio n. 18
0
        public void TestJournalMappings()
        {
            Journal j = new Journal {
                Id           = 31,
                AspNetUser   = new Guid(),
                AspNetUserId = new Guid(),
                File         = new byte[] { 1, 2, 3 },
                Title        = "TheTitle"
            };

            JournalViewModel vm = JournalsController.Journal2Model(j);
            Journal          j2 = new Journal();

            JournalsController.Model2Journal(vm, j2);
            j2.File = j.File; // hack, HttpPostedFileBase PdfUpload could not be initialized
            Assert.AreEqual(j.AspNetUser, j2.AspNetUser);
            Assert.AreEqual(j.AspNetUserId, j2.AspNetUserId);
            Assert.AreEqual(j.File, j2.File);
            Assert.AreEqual(j.Id, j2.Id);
            Assert.AreEqual(j.Title, j2.Title);
            //Assert.AreEqual(j, j2); // no IComparable (test task, keeping simple)
        }
Esempio n. 19
0
        void Initialize()
        {
            _journalRepository               = new Mock <IJournalRepository>();
            _baseJournalPriceRepository      = new Mock <IBaseJournalPriceRepository>();
            _languageRepository              = new Mock <ILanguageRepository>();
            _subjectRepository               = new Mock <ISubjectRepository>();
            _institutionJournalRepository    = new Mock <IInstitutionJournalRepository>();
            _valuationJournalPriceRepository = new Mock <IValuationJournalPriceRepository>();
            _valuationScoreCardRepository    = new Mock <IValuationScoreCardRepository>();
            _institutionRepository           = new Mock <IInstitutionRepository>();
            _baseScoreCardRepository         = new Mock <IBaseScoreCardRepository>();
            _userProfileRepository           = new Mock <IUserProfileRepository>();
            _authentication = new Mock <IAuthentication>();
            _bulkImporter   = new Mock <IBulkImporter <UniversityLicense> >();

            _controller = new JournalsController(_journalRepository.Object, _baseJournalPriceRepository.Object, _valuationJournalPriceRepository.Object, _valuationScoreCardRepository.Object, _languageRepository.Object, _institutionJournalRepository.Object, _baseScoreCardRepository.Object, _userProfileRepository.Object, _authentication.Object, _institutionRepository.Object, _bulkImporter.Object, _subjectRepository.Object);

            _uploadFile = new Mock <HttpPostedFileBase>();
            _viewModel  = new InstitutionalPricesViewModel
            {
                File = _uploadFile.Object
            };
        }
Esempio n. 20
0
        public void Details_WithExistingId_ShouldReturnView()
        {
            // Arrange
            Mock <IJournalService>     journalService = new Mock <IJournalService>();
            JournalDetailsServiceModel detailsModel   = this.GetJournalDetailsServiceModel();

            journalService
            .Setup(t => t.Details(It.IsAny <int>()))
            .Returns(detailsModel);

            JournalsController journalsController = new JournalsController(journalService.Object);

            // Act
            IActionResult result = journalsController.Details(1);

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

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

            this.AssertJournals(detailsModel, returnModel);
        }