Ejemplo n.º 1
0
        public async Task CreateNoteTests()
        {
            var newNote = new NoteViewModel()
            {
                Content        = "new note",
                CaseId         = "1",
                OriginalPoster = "poster",
            };

            var notesList = new List <Note>();

            var mockNotesRepo = new Mock <IDeletableEntityRepository <Note> >();

            mockNotesRepo.Setup(x => x.AddAsync(It.IsAny <Note>()))
            .Callback((Note newNote) =>
            {
                newNote.Id = "newDbId";
                notesList.Add(newNote);
            });

            var notesService = new NotesService(mockNotesRepo.Object);

            var result = await notesService.CreateNoteAsync(newNote);

            Assert.Equal("newDbId", result.Id);
            Assert.Single(notesList);
        }
Ejemplo n.º 2
0
        public async Task Create_Note_Successfully()
        {
            var options = DbContextHelper.GetTestInMemoryDatabase(nameof(Create_Note_Successfully));

            using (var context = new NoteTakerContext(options, httpContextAccessor.Object))
            {
                var service = new NotesService(context, httpContextAccessor.Object);

                var note = await service.CreateNoteAsync("Apples", "Oranges");

                note.Should().NotBeNull();

                httpContextAccessor.Verify(x => x.HttpContext.User, Times.Once);
            };
        }