Ejemplo n.º 1
0
        public void TestDeleteLog_RepositoryReturnsLog_ShouldSetUserLogToNull(int logId)
        {
            // Arrange
            var user = new User();

            var log = new TrainingLog {
                User = user
            };

            user.Log = log;

            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.DeleteLog(logId);

            // Assert
            Assert.IsNull(user.Log);
        }
Ejemplo n.º 2
0
        public void TestDeleteLog_ShouldCallRepositoryGetById(int logId)
        {
            // Arrange
            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.DeleteLog(logId);

            // Assert
            mockedLogRepository.Verify(r => r.GetById(logId), Times.Once);
        }
Ejemplo n.º 3
0
        public void TestDeleteLog_RepositoryReturnsNull_ShouldNotCallUnitOfWorkCommit(int logId)
        {
            // Arrange
            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.DeleteLog(logId);

            // Assert
            mockedUnitOfWork.Verify(u => u.Commit(), Times.Never);
        }
Ejemplo n.º 4
0
 public void Delete([FromBody] UserLogBindingViewModel model)
 {
     _logsService.DeleteLog(model.UserId, model.LogId);
 }