コード例 #1
0
        public void AddNote_NullNote_ThrowsArgumentNullException()
        {
            //arrange
            Note testInputNote = null;
            int  testUserId    = 0;

            //act
            Action act = () => testNotesService.AddNote(testInputNote, testUserId);

            //assert
            ArgumentNullException exception = Assert.Throws <ArgumentNullException>(act);

            Assert.Equal("Value cannot be null. (Parameter 'note')", exception.Message);
        }
コード例 #2
0
        public void PublishMessageIfNoteIsAdded()
        {
            var sut = new NotesService(storageMoq.Object, eventsMoq.Object);

            sut.AddNote(new Note(), 2);
            eventsMoq.Verify(f => f.NotifyAdded(It.IsAny <Note>(), 2), Times.AtLeast(1));
        }
コード例 #3
0
        public void AddNote_If_Arguments_IsCorrect_NoteEvent_MustCall_NotifyAdded()
        {
            var service = new NotesService(_storageMoq.Object, _eventMoq.Object);

            service.AddNote(_testNote, _testUserId);

            _eventMoq.Verify(x => x.NotifyAdded(_testNote, _testUserId), Times.Once);
        }
コード例 #4
0
        public void AddEvent_Should_Return_Null_Exception_If_Note_Null()
        {
            var notesStorage = Substitute.For <INotesStorage>();
            var noteEvents   = Substitute.For <INoteEvents>();
            var sut          = new NotesService(notesStorage, noteEvents);

            Assert.Throws <ArgumentNullException>(() => sut.AddNote(null, 1));
        }
コード例 #5
0
        public void IfNoteIsNullThrowArgumentNullException()
        {
            var noteService = new NotesService(new Mock <INotesStorage>().Object, new Mock <INoteEvents>().Object);

            void Action() => noteService.AddNote(null, It.IsAny <int>());

            Assert.Throws <ArgumentNullException>(Action);
        }
コード例 #6
0
        public void Should_Not_Show_Notify_Added()
        {
            var          storage = Substitute.For <INotesStorage>();
            var          events  = Substitute.For <INoteEvents>();
            Note         note    = null;
            NotesService notes   = new NotesService(storage, events);

            Assert.Throws <ArgumentNullException>(() => notes.AddNote(note, 2));
            events.DidNotReceive().NotifyAdded(note, 2);
        }
コード例 #7
0
        public void Should_Show_Notify_Added()
        {
            var          storage = Substitute.For <INotesStorage>();
            var          events  = Substitute.For <INoteEvents>();
            var          note    = Substitute.For <Note>();
            NotesService notes   = new NotesService(storage, events);

            notes.AddNote(note, 2);
            events.Received().NotifyAdded(note, 2);
        }
コード例 #8
0
        public void NotifyAdded_If_AddNote()
        {
            var notesStorage = Substitute.For <INotesStorage>();
            var noteEvents   = Substitute.For <INoteEvents>();
            var sut          = new NotesService(notesStorage, noteEvents);

            sut.AddNote(new Note(), 1);

            notesStorage.Received().AddNote(Arg.Any <Note>(), 1);
            noteEvents.Received().NotifyAdded(Arg.Any <Note>(), 1);
        }
コード例 #9
0
        public void IfDoINotesStorageAddNoteThenDoINoteEventsNotifyAdded()
        {
            var note        = new Note();
            var id          = It.IsAny <int>();
            var storege     = new Mock <INotesStorage>();
            var events      = new Mock <INoteEvents>();
            var noteService = new NotesService(storege.Object, events.Object);

            noteService.AddNote(note, id);

            storege.Verify(n => n.AddNote(note, id), Times.Once);
            events.Verify(n => n.NotifyAdded(note, id), Times.Once);
        }
コード例 #10
0
        public void NotPublishMessageIfAddNoteIsFailed()
        {
            var sut = new NotesService(storageMoq.Object, eventsMoq.Object);

            try
            {
                sut.AddNote(null, 2);
            }
            catch (Exception) { }
            finally
            {
                eventsMoq.Verify(f => f.NotifyAdded(It.IsAny <Note>(), 2), Times.Never);
            }
        }
コード例 #11
0
        public void AddNote_If_NotesStorage_ThrowException_NoteEvent_DontCall_NotifyAdded()
        {
            _storageMoq.Setup(x => x.AddNote(_testNote, _testUserId)).Throws <ArgumentException>();

            var service = new NotesService(_storageMoq.Object, _eventMoq.Object);

            try
            {
                service.AddNote(_testNote, _testUserId);
            }
            catch
            {
                _eventMoq.Verify(x => x.NotifyAdded(_testNote, _testUserId), Times.Never);
            }
        }
コード例 #12
0
        public IActionResult Create(NoteInputModel input)
        {
            if (!ModelState.IsValid)
            {
                return(View(input));
            }

            var note = _mapper.Map <Note>(input);

            note.Updated = note.Created = DateTime.Now;
            _notesService.AddNote(note);
            _notesService.SaveChanges();

            return(RedirectToAction("Edit", new { id = note.Id }));
        }
コード例 #13
0
        public void IfDoNotINotesStorageAddNoteThenDoNotINoteEventsNotifyAdded()
        {
            var  id      = It.IsAny <int>();
            Note note    = new Note();
            var  storege = new Mock <INotesStorage>();
            var  events  = new Mock <INoteEvents>();

            storege.Setup(s => s.AddNote(note, id)).Throws(new Exception());
            var noteService = new NotesService(storege.Object, events.Object);

            try
            {
                noteService.AddNote(note, id);
            }
            catch (Exception)
            {
            }
            storege.Verify(n => n.AddNote(note, id), Times.Once);
            events.Verify(n => n.NotifyAdded(note, id), Times.Never);
        }
コード例 #14
0
        public void AddNote_MustThrow_ArgumentNullException_If_NoteIsNull()
        {
            var service = new NotesService(_storageMoq.Object, _eventMoq.Object);

            Assert.Throws <ArgumentNullException>(() => service.AddNote(null, _testUserId));
        }
コード例 #15
0
        public void ThrowExceptionWhenAddedNoteIsNull()
        {
            var sut = new NotesService(storageMoq.Object, eventsMoq.Object);

            Assert.Throws <ArgumentNullException>(() => sut.AddNote(null, 1));
        }
コード例 #16
0
 public ActionResult <Note> AddNote([FromBody] NoteInput newNote)
 {
     return(_service.AddNote(newNote));
 }