public void ReturnCorrectType_WhenCalled() { //Arrange var mockedUserRepository = new Mock <IEFGenericRepository <ApplicationUser> >(); var mockedToDoListModelRepository = new Mock <IEFGenericRepository <ToDoListModel> >(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var toDoListModelService = new ToDoList.Services.ToDoListModelService(mockedToDoListModelRepository.Object, mockedUserRepository.Object, mockedUnitOfWork.Object); var expectedCollection = new List <ToDoListModel>() { new ToDoListModel() { Name = "Sample List" } }; mockedToDoListModelRepository.Setup(r => r.All).Returns(() => { return(expectedCollection.AsQueryable()); }); //Act var actualResult = toDoListModelService.GetAll(); //Assert Assert.That(actualResult, Is.InstanceOf <IEnumerable <ToDoListModel> >()); }
public void CallRepositoryAll_OnlyOnce() { //Arrange var mockedUserRepository = new Mock <IEFGenericRepository <ApplicationUser> >(); var mockedToDoListModelRepository = new Mock <IEFGenericRepository <ToDoListModel> >(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var toDoListModelService = new ToDoList.Services.ToDoListModelService(mockedToDoListModelRepository.Object, mockedUserRepository.Object, mockedUnitOfWork.Object); //Act toDoListModelService.GetAll(); //Assert mockedToDoListModelRepository.Verify(x => x.All, Times.Once); }
public void ReturnNull_WhenCalledAndCollectionIsNull() { //Arrange var mockedUserRepository = new Mock <IEFGenericRepository <ApplicationUser> >(); var mockedToDoListModelRepository = new Mock <IEFGenericRepository <ToDoListModel> >(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var toDoListModelService = new ToDoList.Services.ToDoListModelService(mockedToDoListModelRepository.Object, mockedUserRepository.Object, mockedUnitOfWork.Object); mockedToDoListModelRepository.Setup(r => r.All).Returns(() => { return(null); }); //Act var actualResult = toDoListModelService.GetAll(); //Assert Assert.IsNull(actualResult); }