public void CallRepositoriesGetById_OnlyOnce() { //Arrange var mockedToDoListTaskRepository = new Mock <IEFGenericRepository <ToDoListTask> >(); var mockedUserRepository = new Mock <IEFGenericRepository <ApplicationUser> >(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var taskService = new ToDoListTaskService(mockedToDoListTaskRepository.Object, mockedUserRepository.Object, mockedUnitOfWork.Object); //Act taskService.FindTaskById(Guid.NewGuid()); //Assert mockedToDoListTaskRepository.Verify(r => r.GetById(It.IsAny <Guid>()), Times.Once); }
public void Throw_WheTaskIdIsNull() { //Arrange var mockedToDoListTaskRepository = new Mock <IEFGenericRepository <ToDoListTask> >(); var mockedUserRepository = new Mock <IEFGenericRepository <ApplicationUser> >(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var taskService = new ToDoListTaskService(mockedToDoListTaskRepository.Object, mockedUserRepository.Object, mockedUnitOfWork.Object); //Act & Assert Assert.Throws <ArgumentNullException>(() => { taskService.FindTaskById(null); }); }
public void ReturnsCorrectType_WhenGivenValidParameters() { //Arrange var mockedToDoListTaskRepository = new Mock <IEFGenericRepository <ToDoListTask> >(); var mockedUserRepository = new Mock <IEFGenericRepository <ApplicationUser> >(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); mockedToDoListTaskRepository.Setup(r => r.GetById(It.IsAny <Guid>())).Returns(new ToDoListTask()); var taskService = new ToDoListTaskService(mockedToDoListTaskRepository.Object, mockedUserRepository.Object, mockedUnitOfWork.Object); //Act var actualResult = taskService.FindTaskById(Guid.NewGuid()); //Assert Assert.That(actualResult, Is.InstanceOf <ToDoListTask>()); }
public void Retrun_WhenGiveValidParameters() { //Arrange var mockedToDoListTaskRepository = new Mock <IEFGenericRepository <ToDoListTask> >(); var mockedUserRepository = new Mock <IEFGenericRepository <ApplicationUser> >(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var expectedTask = new ToDoListTask() { Task = "sample task" }; mockedToDoListTaskRepository.Setup(r => r.GetById(It.IsAny <Guid>())).Returns(expectedTask); var taskService = new ToDoListTaskService(mockedToDoListTaskRepository.Object, mockedUserRepository.Object, mockedUnitOfWork.Object); //Act var actualResult = taskService.FindTaskById(Guid.NewGuid()); //Assert Assert.That(actualResult, Is.EqualTo(expectedTask)); }