Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
            });
        }
Esempio n. 3
0
        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>());
        }
Esempio n. 4
0
        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));
        }