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.GetAllByUserId(It.IsAny <Guid>()); //Assert Assert.That(actualResult, Is.InstanceOf <IEnumerable <ToDoListModel> >()); }
public void ReturnCorrectResult_WhenCalled() { //Arrange var mockedUserRepository = new Mock <IEFGenericRepository <ApplicationUser> >(); var mockedToDoListModelRepository = new Mock <IEFGenericRepository <ToDoListModel> >(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var mockedUserOne = new Mock <ApplicationUser>(); mockedUserOne.Setup(s => s.Id).Returns("1"); var mockedUserTwo = new Mock <ApplicationUser>(); mockedUserOne.Setup(s => s.Id).Returns("2"); var toDoListModelService = new ToDoList.Services.ToDoListModelService(mockedToDoListModelRepository.Object, mockedUserRepository.Object, mockedUnitOfWork.Object); var expectedCollection = new List <ToDoListModel>() { new ToDoListModel() { Name = "Sample List", ApplicationUserId = mockedUserOne.Object }, new ToDoListModel() { Name = "Sample List 1", ApplicationUserId = mockedUserOne.Object }, new ToDoListModel() { Name = "Sample List 2", ApplicationUserId = mockedUserTwo.Object }, new ToDoListModel() { Name = "Sample List 3", ApplicationUserId = mockedUserTwo.Object }, new ToDoListModel() { Name = "Sample List 4", ApplicationUserId = mockedUserTwo.Object } }; mockedToDoListModelRepository.Setup(r => r.All).Returns(() => { return(expectedCollection.Where(l => l.ApplicationUserId == mockedUserOne.Object).AsQueryable()); }); //Act var actualResult = toDoListModelService.GetAllByUserId(mockedUserOne.Object); //Assert Assert.That(actualResult.Count(), Is.EqualTo(2)); }
public void Throw_WhenIdIsNull() { //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&Assert Assert.Throws <ArgumentNullException>(() => { toDoListModelService.GetAllByUserId(null); }); }
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 CallUnitOfWorkCommit_OnlyOnce() { //Arrange var mockedUserRepository = new Mock <IEFGenericRepository <ApplicationUser> >(); var mockedToDoListModelRepository = new Mock <IEFGenericRepository <ToDoListModel> >(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var mockedToDoList = new Mock <ToDoListModel>(); var toDoListModelService = new ToDoList.Services.ToDoListModelService(mockedToDoListModelRepository.Object, mockedUserRepository.Object, mockedUnitOfWork.Object); //Act toDoListModelService.UpdateToDoList(mockedToDoList.Object); //Assert mockedUnitOfWork.Verify(x => x.Commit(), Times.Once); }
public void CallRepositortDelete_OnlyOnce() { //Arrange var mockedUserRepository = new Mock <IEFGenericRepository <ApplicationUser> >(); var mockedToDoListModelRepository = new Mock <IEFGenericRepository <ToDoListModel> >(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var mockedToDoList = new Mock <ToDoListModel>(); var toDoListModelService = new ToDoList.Services.ToDoListModelService(mockedToDoListModelRepository.Object, mockedUserRepository.Object, mockedUnitOfWork.Object); //Act toDoListModelService.DeleteToDoList(mockedToDoList.Object); //Assert mockedToDoListModelRepository.Verify(r => r.Delete(It.IsAny <ToDoListModel>()), Times.Once); }
public void CallRepositortGetById_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); var obj = Guid.NewGuid(); //Act toDoListModelService.GetListById(obj); //Assert mockedToDoListModelRepository.Verify(r => r.GetById(It.IsAny <object>()), Times.Once); }
public void Throw_WhenNameIsNull() { //Arrange var mockedUserRepository = new Mock <IEFGenericRepository <ApplicationUser> >(); var mockedToDoListModelRepository = new Mock <IEFGenericRepository <ToDoListModel> >(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var mockedUser = new Mock <ApplicationUser>(); var toDoListModelService = new ToDoList.Services.ToDoListModelService(mockedToDoListModelRepository.Object, mockedUserRepository.Object, mockedUnitOfWork.Object); var isPublic = false; //Act&Assert Assert.Throws <ArgumentNullException>(() => { toDoListModelService.CreateToDoList(mockedUser.Object, null, isPublic); }); }
public void CallUnitOfWorkCommitOnlyOnce() { //Arrange var mockedUserRepository = new Mock <IEFGenericRepository <ApplicationUser> >(); var mockedToDoListModelRepository = new Mock <IEFGenericRepository <ToDoListModel> >(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var mockedUser = new Mock <ApplicationUser>(); var toDoListModelService = new ToDoList.Services.ToDoListModelService(mockedToDoListModelRepository.Object, mockedUserRepository.Object, mockedUnitOfWork.Object); var name = "Sample Name"; var isPublic = false; mockedUser.Setup(x => x.ToDoLists.Add(It.IsAny <ToDoListModel>())); //Act toDoListModelService.CreateToDoList(mockedUser.Object, name, isPublic); //Assert mockedUnitOfWork.Verify(x => x.Commit(), 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); }