public void DeleteShouldCallDelete() { var deleteCounter = 0; var notesRepositoryFake = new Mock<IRepository<Note>>(); notesRepositoryFake.Setup(x => x.Delete(It.IsAny<int>())).Callback(() => deleteCounter++); var dataFake = new Mock<IQmsData>(); dataFake.Setup(x => x.Notes).Returns(notesRepositoryFake.Object); var service = new NotesServices(dataFake.Object); service.delete(1); notesRepositoryFake.Verify(x => x.Delete(It.IsAny<int>())); }
public void CreateShouldWorkProperly() { var notesCollection = new List<Note>(); var notesRepositoryFake = new Mock<IRepository<Note>>(); notesRepositoryFake.Setup(x => x.All()).Returns(notesCollection.AsQueryable()); notesRepositoryFake.Setup(x => x.Add(It.IsAny<Note>())).Callback<Note>((note) => notesCollection.Add(note)); var dataFake = new Mock<IQmsData>(); dataFake.Setup(x => x.Notes).Returns(notesRepositoryFake.Object); var service = new NotesServices(dataFake.Object); service.Create(1, "title", "text"); Assert.AreEqual(1, notesCollection.Count()); dataFake.Verify(x => x.SaveChanges()); }