public void TestEditLog_RepositoryReturnsLog_ShouldSetLogName(int logId, string newDescription, string newName) { // Arrange var log = new TrainingLog(); 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.EditLog(logId, newDescription, newName); // Assert Assert.AreEqual(newName, log.Name); }
public void TestEditLog_RepositoryReturnsNull_ShouldNotCallUnitOfWorkCommit(int logId, string newDescription, string newName) { // 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.EditLog(logId, newDescription, newName); // Assert mockedUnitOfWork.Verify(u => u.Commit(), Times.Never); }
public void TestEditLog_ShouldCallRepositoryGetById(int logId, string newDescription, string newName) { // 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.EditLog(logId, newDescription, newName); // Assert mockedLogRepository.Verify(r => r.GetById(logId), Times.Once); }