Exemplo n.º 1
0
        public void TestCreateNoteView()
        {
            NoteController controller = new NoteController();
            ViewResult     view       = controller.Create("pipipi") as ViewResult;

            Assert.IsNotNull(view);
        }
Exemplo n.º 2
0
        public void CreateNoteTest(string header, string description, int id)
        {
            Note note = new Note(header, description);

            NoteController noteController = new NoteController();

            noteController.Create(header, description);

            Assert.Equal(note, noteController.GetNote(id));
        }
Exemplo n.º 3
0
        public void UpdateNoteTest(string header, string description, int id)
        {
            Note note = new Note("васильки", "цветочки");

            NoteController noteController = new NoteController();

            noteController.Create(header, description);
            noteController.Update(id, "васильки", "цветочки");

            Assert.Equal(note, noteController.GetNote(id));
        }
Exemplo n.º 4
0
        public void CreateGetMethodReturnViewWithEmptyModel()
        {
            var userManager    = TestUserManager <AppUser>();
            var repository     = new Mock <IRepository <Note> >().Object;
            var noteController = new NoteController(userManager, repository);

            var result = noteController.Create();

            var viewResult = Assert.IsType <ViewResult>(result);

            Assert.Null(viewResult.Model);
        }
Exemplo n.º 5
0
        public void CreateShouldReturnListOfNotes_ModelIsValid()
        {
            var note = new Note {
                NoteTitle = "Technology", NoteContent = "DevOps", NoteStatus = "Started"
            };
            var mockRepo = new Mock <INoteRepository>();

            mockRepo.Setup(repo => repo.AddNote(note));
            var noteController = new NoteController(mockRepo.Object);

            var actual = noteController.Create(note);

            var actionResult = Assert.IsType <RedirectToActionResult>(actual);

            Assert.Null(actionResult.ControllerName);
            Assert.Equal("Index", actionResult.ActionName);
        }
Exemplo n.º 6
0
        public void CreatePostMethodSavesNoteSuccessfully()
        {
            var testStore   = new List <Note>();
            var userManager = TestUserManager <AppUser>();
            var repoMock    = new Mock <IRepository <Note> >();

            repoMock.Setup(x => x.CreateAsync(It.IsAny <Note>())).Callback((Note item) => { testStore.Add(item); });
            repoMock.Setup(x => x.SaveAsync()).Callback(() => { });
            var repository = repoMock.Object;
            var note       = new CreateNoteViewModel {
                Description = "test note"
            };
            var noteController = new NoteController(userManager, repository);

            var result = noteController.Create(note);

            Assert.Single(testStore);
        }
Exemplo n.º 7
0
        public void CreateShouldReturn_ModelIsInValid()
        {
            var note = new Note {
                NoteContent = "ASP.NET Core", NoteStatus = "Completed"
            };
            var mockRepo = new Mock <INoteRepository>();

            mockRepo.Setup(repo => repo.AddNote(note));
            var noteController = new NoteController(mockRepo.Object);

            noteController.ModelState.AddModelError("NoteTitle", "Required");

            var actual = noteController.Create(note);

            var actionResult = Assert.IsType <ViewResult>(actual);

            Assert.IsAssignableFrom <Note>(actionResult.ViewData.Model);
            Assert.Same(actionResult.ViewData.Model, note);
        }
Exemplo n.º 8
0
        public async void Create_Errors()
        {
            NoteControllerMockFacade mock = new NoteControllerMockFacade();

            var mockResponse = new Mock <CreateResponse <ApiNoteServerResponseModel> >(null as ApiNoteServerResponseModel);
            var mockRecord   = new ApiNoteServerResponseModel();

            mockResponse.SetupGet(x => x.Success).Returns(false);

            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiNoteServerRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiNoteServerResponseModel> >(mockResponse.Object));
            NoteController controller = new NoteController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            IActionResult response = await controller.Create(new ApiNoteServerRequestModel());

            response.Should().BeOfType <ObjectResult>();
            (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity);
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiNoteServerRequestModel>()));
        }
Exemplo n.º 9
0
        public void Can_Create_Note()
        {
            // Arrange
            var note = new Note()
            {
                Title            = "Note 1",
                IntervalInDays   = 1,
                FirstStudiedDate = DateTime.Parse("01-01-17"),
                Resources        = new List <Resource>()
            };
            var context = new TestContext();

            context.Users.Add(user);

            // Arrange - create the controller
            NoteController target = new NoteController(context)
            {
                GetUserId = () => user.Id
            };

            // Act
            target.Create(new CreateNoteViewModel()
            {
                Title            = note.Title,
                FirstStudiedDate = note.FirstStudiedDate,
                IntervalInDays   = note.IntervalInDays,
                Resources        = (List <Resource>)note.Resources
            });

            // Assert - ensure note and its corresponding review is saved
            var savedNote   = context.Notes.SingleOrDefault();
            var savedReview = context.Reviews.SingleOrDefault();

            Assert.IsNotNull(savedNote);
            Assert.AreEqual(note.Title, savedNote.Title);
            Assert.AreEqual(user, savedNote.User);
            Assert.IsNotNull(savedReview);
            Assert.AreEqual(savedNote, savedReview.Note);
        }
Exemplo n.º 10
0
        public async void Create_No_Errors()
        {
            NoteControllerMockFacade mock = new NoteControllerMockFacade();

            var mockResponse = ValidationResponseFactory <ApiNoteServerResponseModel> .CreateResponse(null as ApiNoteServerResponseModel);

            mockResponse.SetRecord(new ApiNoteServerResponseModel());
            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiNoteServerRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiNoteServerResponseModel> >(mockResponse));
            NoteController controller = new NoteController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            IActionResult response = await controller.Create(new ApiNoteServerRequestModel());

            response.Should().BeOfType <CreatedResult>();
            (response as CreatedResult).StatusCode.Should().Be((int)HttpStatusCode.Created);
            var createResponse = (response as CreatedResult).Value as CreateResponse <ApiNoteServerResponseModel>;

            createResponse.Record.Should().NotBeNull();
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiNoteServerRequestModel>()));
        }