public void TestCreateTrainingLog_ShouldCallLogFactoryCreateTrainingLog(string name, string description, string userId) { // Arrange var mockedUser = new Mock <User>(); var mockedLogRepository = new Mock <IRepository <TrainingLog> >(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var mockedLogFactory = new Mock <ITrainingLogFactory>(); var currentDate = new DateTime(); var mockedDateTimeProvider = new Mock <IDateTimeProvider>(); mockedDateTimeProvider.Setup(p => p.GetCurrentTime()).Returns(currentDate); var mockedUserService = new Mock <IUserService>(); mockedUserService.Setup(s => s.GetUserById(It.IsAny <string>())).Returns(mockedUser.Object); var service = new LogsService(mockedLogRepository.Object, mockedUnitOfWork.Object, mockedLogFactory.Object, mockedUserService.Object, mockedDateTimeProvider.Object); // Act service.CreateTrainingLog(name, description, userId); // Assert mockedLogFactory.Verify(f => f.CreateTrainingLog(name, description, currentDate, mockedUser.Object)); }
public void TestCreateTrainingLog_ShouldCallProviderGetCurrentTime(string name, string description, string userId) { // 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.CreateTrainingLog(name, description, userId); // Assert mockedDateTimeProvider.Verify(p => p.GetCurrentTime(), Times.Once); }