Example #1
0
        public void Throw_WhenToDoListIsNull()
        {
            //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);

            var category       = CategoryTypes.Errands;
            var priority       = PriorityTypes.Low;
            var expirationDate = DateTime.Now.AddDays(1);
            var task           = "sample task";

            //Act & Assert
            Assert.Throws <ArgumentNullException>(() =>
            {
                taskService.CreateTask(null, category, priority, expirationDate, task);
            });
        }
Example #2
0
        public void CallUnitOfWorkCommit_OnlyOnce()
        {
            //Arrange
            var mockedToDoListTaskRepository = new Mock <IEFGenericRepository <ToDoListTask> >();
            var mockedUserRepository         = new Mock <IEFGenericRepository <ApplicationUser> >();
            var mockedUnitOfWork             = new Mock <IUnitOfWork>();
            var mockedToDoListModel          = new Mock <ToDoListModel>();

            var taskService = new ToDoListTaskService(mockedToDoListTaskRepository.Object, mockedUserRepository.Object, mockedUnitOfWork.Object);

            mockedToDoListModel.Setup(l => l.Tasks.Add(It.IsAny <ToDoListTask>()));

            var category       = CategoryTypes.Errands;
            var priority       = PriorityTypes.Low;
            var expirationDate = DateTime.Now.AddDays(1);
            var task           = "sample task";

            //Act
            taskService.CreateTask(mockedToDoListModel.Object, category, priority, expirationDate, task);

            // Assert
            mockedUnitOfWork.Verify(u => u.Commit(), Times.Once);
        }
Example #3
0
        public void Throw_WhenExpirationDateIsInThePast()
        {
            //Arrange
            var mockedToDoListTaskRepository = new Mock <IEFGenericRepository <ToDoListTask> >();
            var mockedUserRepository         = new Mock <IEFGenericRepository <ApplicationUser> >();
            var mockedUnitOfWork             = new Mock <IUnitOfWork>();
            var mockedToDoListModel          = new Mock <ToDoListModel>();

            var taskService = new ToDoListTaskService(mockedToDoListTaskRepository.Object, mockedUserRepository.Object, mockedUnitOfWork.Object);


            mockedToDoListModel.Setup(l => l.Tasks.Add(It.IsAny <ToDoListTask>()));

            var category       = CategoryTypes.Errands;
            var priority       = PriorityTypes.Low;
            var expirationDate = DateTime.Parse("10/10/1992");
            var task           = "sample task";

            //Act & Assert
            Assert.Throws <ArgumentOutOfRangeException>(() =>
            {
                taskService.CreateTask(mockedToDoListModel.Object, category, priority, expirationDate, task);
            });
        }