Example #1
0
        public async void Returns_NoteOut_when_Success()
        {
            NotePost notePost = new NotePost
            {
                Title   = "New note's title",
                Content = "New note's content"
            };

            NoteOut noteOut = new NoteOut
            {
                ID      = Guid.NewGuid(),
                Title   = "New note's title",
                Content = "New note's content"
            };

            StatusCode <NoteOut> status           = new StatusCode <NoteOut>(StatusCodes.Status200OK, noteOut);
            Mock <INotesService> notesServiceMock = new Mock <INotesService>();

            notesServiceMock.Setup(_ => _.PostNoteByUser(It.IsAny <NotePost>(), It.IsAny <string>()))
            .Returns(Task.FromResult(status));

            NotesController notesController = new NotesController(notesServiceMock.Object, UserManagerHelper.GetUserManager(ADMIN_USERNAME));

            notesController.Authenticate(ADMIN_USERNAME);

            IActionResult result = await notesController.Post(notePost);

            OkObjectResult okObjectResult = result as OkObjectResult;

            Assert.NotNull(okObjectResult);
            Assert.IsType <NoteOut>(okObjectResult.Value);
        }
Example #2
0
        public async void Returns_NoteOut_when_NoteIsSharedForEveryone()
        {
            NoteOut note = new NoteOut
            {
                ID                  = Guid.NewGuid(),
                Title               = "Note Title",
                Content             = "Note Content",
                IsShared            = true,
                IsSharedForEveryone = true,
                ResourceType        = DAO.Models.Base.ResourceType.NOTE
            };

            Mock <INotesService> notesServiceMock = new Mock <INotesService>();

            notesServiceMock.Setup(_ => _.GetByIdAndUser(It.IsAny <Guid>(), It.IsAny <string>()))
            .Returns(Task.FromResult(new StatusCode <NoteOut>(StatusCodes.Status200OK, note)));

            NotesController notesController = new NotesController(notesServiceMock.Object, UserManagerHelper.GetUserManager(ADMIN_USERNAME));

            IActionResult result = await notesController.Get(Guid.NewGuid());

            OkObjectResult okObjectResult = result as OkObjectResult;

            Assert.NotNull(okObjectResult);
            Assert.IsType <NoteOut>(okObjectResult.Value);
        }
Example #3
0
        public async void Returns_PatchedNoteOut_when_Success()
        {
            NoteOut note = new NoteOut
            {
                ID = Guid.NewGuid()
            };

            StatusCode <NoteOut> status = new StatusCode <NoteOut>(StatusCodes.Status200OK, note);

            Mock <INotesService> notesServiceMock = new Mock <INotesService>();

            notesServiceMock.Setup(_ => _.PatchByIdAndNotePatchAndUser(It.IsAny <Guid>(), It.IsAny <JsonPatchDocument <NotePatch> >(), It.IsAny <string>()))
            .Returns(Task.FromResult(status));

            NotesController notesController = new NotesController(notesServiceMock.Object, UserManagerHelper.GetUserManager(ADMIN_USERNAME));

            notesController.Authenticate(ADMIN_USERNAME);

            IActionResult result = await notesController.Patch(Guid.NewGuid(), new JsonPatchDocument <NotePatch>());

            OkObjectResult okObjectResult = result as OkObjectResult;

            Assert.NotNull(okObjectResult);
            Assert.IsType <NoteOut>(okObjectResult.Value);
        }
Example #4
0
        public async Task <StatusCode <NoteOut> > PostNoteByUser(NotePost note, string username)
        {
            string userId = (await _databaseContext.Users
                             .FirstOrDefaultAsync(_ => _.UserName == username))?
                            .Id;

            Note newNote = new Note
            {
                CreatedDateTime = DateTime.Now,
                ResourceType    = DAO.Models.Base.ResourceType.NOTE,
                Content         = note.Content,
                OwnerID         = userId,
                Title           = note.Title
            };

            await _databaseContext.Notes.AddAsync(newNote);

            await _databaseContext.SaveChangesAsync();

            NoteOut result = _mapper.Map <NoteOut>(newNote);

            return(new StatusCode <NoteOut>(StatusCodes.Status200OK, result));
        }