public void Stop_IfStoppedTaskIsStartedAgainAndStopped_ActualWorkUpdated() { // arrange var userId = 100; var token = "4a891b4d0bb22f83482f9fb5bafeb4b8"; var repository = ApiTestsCommonSetup.SetupMockRepository(userId); var date = new Mock <IDateTimeProviderService>(); var service = new Mock <IApiService>(); var shareService = new Mock <IShareService>(); var api = new ApiV11Controller(service.Object, repository.Object, date.Object, shareService.Object); var currentDate = DateTime.UtcNow; date.Setup(d => d.UtcNow).Returns(currentDate); service.Setup(s => s.GetUserByApiToken(token)).Returns(new User { Id = userId }); // act api.Start(token, 1); date.Setup(d => d.UtcNow).Returns(currentDate.AddSeconds(1)); api.Stop(token, 1); api.Start(token, 1); date.Setup(d => d.UtcNow).Returns(currentDate.AddSeconds(2)); api.Stop(token, 1); // assert var task = ApiTestsCommonSetup.SubmittedTasks[0]; Assert.That(task.ActualWork, Is.EqualTo(2), "two seconds have to be stored as actual work"); }
public void Stop_StatedTaskStopped_StoppedInitialized() { // arrange var userId = 100; var token = "4a891b4d0bb22f83482f9fb5bafeb4b8"; var repository = ApiTestsCommonSetup.SetupMockRepository(userId); var date = new Mock <IDateTimeProviderService>(); var service = new Mock <IApiService>(); var shareService = new Mock <IShareService>(); var api = new ApiV11Controller(service.Object, repository.Object, date.Object, shareService.Object); service.Setup(s => s.GetUserByApiToken(token)).Returns(new User { Id = userId }); // act api.Start(token, 1); api.Stop(token, 1); // assert var task = ApiTestsCommonSetup.SubmittedTasks[0]; Assert.That(task.StartedDate, Is.Not.Null, "stated date has not been set"); Assert.That(task.StoppedDate, Is.Not.Null, "stopped date has not been set"); Assert.That(task.Status, Is.EqualTo(2), "task status is not <stopped>"); }
public void Stop_TaskWithSuchIdDoesNotExist_ExceptionThrown() { // arrange var userId = 100; var token = "4a891b4d0bb22f83482f9fb5bafeb4b8"; var repository = ApiTestsCommonSetup.SetupMockRepository(userId); var date = new Mock <IDateTimeProviderService>(); var service = new Mock <IApiService>(); var shareService = new Mock <IShareService>(); var api = new ApiV11Controller(service.Object, repository.Object, date.Object, shareService.Object); service.Setup(s => s.GetUserByApiToken(token)).Returns(new User { Id = userId }); // act api.Stop(token, 333); }
public void Stop_CheckArgumentsBadToken_ExceptionThrown() { // arrange var userId = 100; var token = "4a891b4d0bb22f83482f9fb5bafeb4b8"; var repository = ApiTestsCommonSetup.SetupMockRepository(userId); var date = new Mock <IDateTimeProviderService>(); var service = new Mock <IApiService>(); var shareService = new Mock <IShareService>(); var api = new ApiV11Controller(service.Object, repository.Object, date.Object, shareService.Object); service.Setup(s => s.GetUserByApiToken(token)).Returns(new User { Id = 0 }); // act api.Stop("bad_token", 0); }
public void Stop_StatedTaskStopped_StoppedInitialized() { // arrange var userId = 100; var token = "4a891b4d0bb22f83482f9fb5bafeb4b8"; var repository = ApiTestsCommonSetup.SetupMockRepository(userId); var date = new Mock<IDateTimeProviderService>(); var service = new Mock<IApiService>(); var shareService = new Mock<IShareService>(); var api = new ApiV11Controller(service.Object, repository.Object, date.Object, shareService.Object); service.Setup(s => s.GetUserByApiToken(token)).Returns(new User { Id = userId}); // act api.Start(token, 1); api.Stop(token, 1); // assert var task = ApiTestsCommonSetup.SubmittedTasks[0]; Assert.That(task.StartedDate, Is.Not.Null, "stated date has not been set"); Assert.That(task.StoppedDate, Is.Not.Null, "stopped date has not been set"); Assert.That(task.Status, Is.EqualTo(2), "task status is not <stopped>"); }
public void Stop_StatedTaskStopped_ActualWorkUpdated() { // arrange var userId = 100; var token = "4a891b4d0bb22f83482f9fb5bafeb4b8"; var repository = ApiTestsCommonSetup.SetupMockRepository(userId); var date = new Mock<IDateTimeProviderService>(); var service = new Mock<IApiService>(); var shareService = new Mock<IShareService>(); var api = new ApiV11Controller(service.Object, repository.Object, date.Object, shareService.Object); var currentDate = DateTime.UtcNow; date.Setup(d => d.UtcNow).Returns(currentDate); service.Setup(s => s.GetUserByApiToken(token)).Returns(new User { Id = userId}); // act api.Start(token, 1); date.Setup(d => d.UtcNow).Returns(currentDate.AddSeconds(1)); api.Stop(token, 1); // assert var task = ApiTestsCommonSetup.SubmittedTasks[0]; Assert.That(task.ActualWork, Is.EqualTo(1), "one second have to be stored as actual work"); }
public void Stop_TaskWithSuchIdDoesNotExist_ExceptionThrown() { // arrange var userId = 100; var token = "4a891b4d0bb22f83482f9fb5bafeb4b8"; var repository = ApiTestsCommonSetup.SetupMockRepository(userId); var date = new Mock<IDateTimeProviderService>(); var service = new Mock<IApiService>(); var shareService = new Mock<IShareService>(); var api = new ApiV11Controller(service.Object, repository.Object, date.Object, shareService.Object); service.Setup(s => s.GetUserByApiToken(token)).Returns(new User { Id = userId}); // act api.Stop(token, 333); }
public void Stop_CheckArgumentsBadToken_ExceptionThrown() { // arrange var userId = 100; var token = "4a891b4d0bb22f83482f9fb5bafeb4b8"; var repository = ApiTestsCommonSetup.SetupMockRepository(userId); var date = new Mock<IDateTimeProviderService>(); var service = new Mock<IApiService>(); var shareService = new Mock<IShareService>(); var api = new ApiV11Controller(service.Object, repository.Object, date.Object, shareService.Object); service.Setup(s => s.GetUserByApiToken(token)).Returns(new User { Id = 0 }); // act api.Stop("bad_token", 0); }
public void Stop_IfStoppedTaskIsStartedAgainAndStopped_StoppedUpdated() { // arrange var userId = 100; var token = "4a891b4d0bb22f83482f9fb5bafeb4b8"; var repository = ApiTestsCommonSetup.SetupMockRepository(userId); var date = new Mock<IDateTimeProviderService>(); var service = new Mock<IApiService>(); var shareService = new Mock<IShareService>(); var api = new ApiV11Controller(service.Object, repository.Object, date.Object, shareService.Object); var currentDate = DateTime.UtcNow; date.Setup(d => d.UtcNow).Returns(currentDate); service.Setup(s => s.GetUserByApiToken(token)).Returns(new User { Id = userId }); // act api.Start(token, 1); date.Setup(d => d.UtcNow).Returns(currentDate.AddSeconds(1)); api.Stop(token, 1); api.Start(token, 1); date.Setup(d => d.UtcNow).Returns(currentDate.AddSeconds(2)); api.Stop(token, 1); // assert var task = ApiTestsCommonSetup.SubmittedTasks[0]; Assert.That(task.StoppedDate, Is.Not.Null, "stopped date initialized"); }