Exemplo n.º 1
0
        public void TestAddEntryToLog_UserIdsDoNotEqual_ShouldNotCallUnitOfWorkCommit(int logId, string userId, string requestUserId)
        {
            // Arrange
            var entry = new LogEntry();

            var user = new User {
                Id = userId
            };
            var log = new TrainingLog {
                User = user
            };

            var mockedLogRepository = new Mock <IRepository <TrainingLog> >();

            mockedLogRepository.Setup(r => r.GetById(It.IsAny <object>())).Returns(log);

            var mockedUnitOfWork       = new Mock <IUnitOfWork>();
            var mockedLogFactory       = new Mock <ITrainingLogFactory>();
            var mockedUserService      = new Mock <IUserService>();
            var mockedDateTimeProvider = new Mock <IDateTimeProvider>();

            var service = new LogsService(mockedLogRepository.Object,
                                          mockedUnitOfWork.Object,
                                          mockedLogFactory.Object,
                                          mockedUserService.Object,
                                          mockedDateTimeProvider.Object);

            // Act
            service.AddEntryToLog(logId, entry, requestUserId);

            // Assert
            mockedUnitOfWork.Verify(u => u.Commit(), Times.Never);
        }
Exemplo n.º 2
0
        public void TestAddEntryToLog_RepositoryReturnsLog_ShouldCallUnitOfWorkCommit(int logId, string username, string userId)
        {
            // Arrange
            var user = new User {
                UserName = username, Id = userId
            };
            var entry = new LogEntry {
                EntryDate = new DateTime()
            };
            var log = new TrainingLog {
                User = user
            };

            var mockedLogRepository = new Mock <IRepository <TrainingLog> >();

            mockedLogRepository.Setup(r => r.GetById(It.IsAny <object>()))
            .Returns(log);

            var mockedUnitOfWork       = new Mock <IUnitOfWork>();
            var mockedLogFactory       = new Mock <ITrainingLogFactory>();
            var mockedUserService      = new Mock <IUserService>();
            var mockedDateTimeProvider = new Mock <IDateTimeProvider>();

            var service = new LogsService(mockedLogRepository.Object,
                                          mockedUnitOfWork.Object,
                                          mockedLogFactory.Object,
                                          mockedUserService.Object,
                                          mockedDateTimeProvider.Object);

            // Act
            service.AddEntryToLog(logId, entry, userId);

            // Assert
            mockedUnitOfWork.Verify(u => u.Commit(), Times.Once);
        }
Exemplo n.º 3
0
        public void TestAddEntryToLog_RepositoryReturnsLog_ShouldSetLogLastEntryDate(int logId, string username)
        {
            // Arrange
            var user = new User {
                UserName = username
            };
            var entry = new LogEntry {
                EntryDate = new DateTime()
            };
            var log = new TrainingLog {
                User = user
            };

            var mockedLogRepository = new Mock <IRepository <TrainingLog> >();

            mockedLogRepository.Setup(r => r.GetById(It.IsAny <object>()))
            .Returns(log);

            var mockedUnitOfWork       = new Mock <IUnitOfWork>();
            var mockedLogFactory       = new Mock <ITrainingLogFactory>();
            var mockedUserService      = new Mock <IUserService>();
            var mockedDateTimeProvider = new Mock <IDateTimeProvider>();

            var service = new LogsService(mockedLogRepository.Object,
                                          mockedUnitOfWork.Object,
                                          mockedLogFactory.Object,
                                          mockedUserService.Object,
                                          mockedDateTimeProvider.Object);

            // Act
            service.AddEntryToLog(logId, entry, null);

            // Assert
            Assert.AreEqual(entry.EntryDate, log.LastEntryDate);
        }
Exemplo n.º 4
0
        public void TestAddEntryToLog_RepositoryReturnsLog_ShouldAddEntryToLogEntries(int logId, string username, string userId)
        {
            // Arrange
            var user = new User {
                UserName = username, Id = userId
            };
            var entry = new LogEntry();
            var log   = new TrainingLog {
                User = user
            };

            var mockedLogRepository = new Mock <IRepository <TrainingLog> >();

            mockedLogRepository.Setup(r => r.GetById(It.IsAny <object>()))
            .Returns(log);

            var mockedUnitOfWork       = new Mock <IUnitOfWork>();
            var mockedLogFactory       = new Mock <ITrainingLogFactory>();
            var mockedUserService      = new Mock <IUserService>();
            var mockedDateTimeProvider = new Mock <IDateTimeProvider>();

            var service = new LogsService(mockedLogRepository.Object,
                                          mockedUnitOfWork.Object,
                                          mockedLogFactory.Object,
                                          mockedUserService.Object,
                                          mockedDateTimeProvider.Object);

            // Act
            service.AddEntryToLog(logId, entry, userId);

            // Assert
            CollectionAssert.Contains(log.LogEntries, entry);
        }
Exemplo n.º 5
0
        public void TestAddEntryToLog_RepositoryReturnsNull_ShouldNotCallUnitOfWorkCommit(int logId)
        {
            // Arrange
            var entry = new LogEntry();

            var mockedLogRepository    = new Mock <IRepository <TrainingLog> >();
            var mockedUnitOfWork       = new Mock <IUnitOfWork>();
            var mockedLogFactory       = new Mock <ITrainingLogFactory>();
            var mockedUserService      = new Mock <IUserService>();
            var mockedDateTimeProvider = new Mock <IDateTimeProvider>();

            var service = new LogsService(mockedLogRepository.Object,
                                          mockedUnitOfWork.Object,
                                          mockedLogFactory.Object,
                                          mockedUserService.Object,
                                          mockedDateTimeProvider.Object);

            // Act
            service.AddEntryToLog(logId, entry, null);

            // Assert
            mockedUnitOfWork.Verify(u => u.Commit(), Times.Never);
        }
Exemplo n.º 6
0
        public void TestAddEntryToLog_ShouldCallRepositoryGetByIdCorrectly(int logId)
        {
            // Arrange
            var entry = new LogEntry();

            var mockedLogRepository    = new Mock <IRepository <TrainingLog> >();
            var mockedUnitOfWork       = new Mock <IUnitOfWork>();
            var mockedLogFactory       = new Mock <ITrainingLogFactory>();
            var mockedUserService      = new Mock <IUserService>();
            var mockedDateTimeProvider = new Mock <IDateTimeProvider>();

            var service = new LogsService(mockedLogRepository.Object,
                                          mockedUnitOfWork.Object,
                                          mockedLogFactory.Object,
                                          mockedUserService.Object,
                                          mockedDateTimeProvider.Object);

            // Act
            service.AddEntryToLog(logId, entry, null);

            // Assert
            mockedLogRepository.Verify(r => r.GetById(logId), Times.Once);
        }