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 All_IfTaskStatusIsStopped_SpentEqualsToActualWork()
        {
            // 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);

            date.Setup(d => d.UtcNow).Returns(DateTime.UtcNow);
            service.Setup(s => s.GetUserByApiToken(token)).Returns(new User {
                Id = userId
            });

            // act
            var     results = api.All(token) as JsonResult;
            dynamic data    = results.Data;

            var tasksList = data.data.tasks as IList <TaskDescriptor>;

            Assert.That(tasksList, Is.Not.Null);
            Assert.That(tasksList[2].spent, Is.EqualTo(20), "spend equal to task ActualWork field");
        }
        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");
        }
        public void Smoke()
        {
            // assert
            var repository   = ApiTestsCommonSetup.SetupMockRepository(0);
            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);

            // act / assert
            Assert.That(api, Is.Not.Null);
        }
        public void Autenticate_PasswordIsNull_ExceptionThrown()
        {
            // arrange
            var userId       = 100;
            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);

            // act
            api.Authenticate("aa", null);
        }
        public void Authenticate_ApiTokenNotLinkedToUser_ExceptionThrow()
        {
            // arrange
            var userId       = 100;
            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.GetApiToken("email", "password")).Returns((string)null);

            // act
            api.Authenticate("email", "token");
        }
        public void Add_CheckAuthentication_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)).Throws(new Exception());

            // act
            api.Add(token, "desc");
        }
        public void UpdatePlannedDate_WrongFormat_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.UpdatePlannedDate(token, 1, "12-17-2011");
        }
        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 Undo_DoneTaskUndo()
        {
            // 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.Undo(token, 7);

            // assert
            ApiTestsCommonSetup.AllTasks.Where(t => t.Id == 7).Single().Done.Should().Be.False();
        }
        public void DeleteAllDone_DeletesAllDoneTasks()
        {
            // 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.DeleteAllDone(token);

            // assert
            ApiTestsCommonSetup.DeletedTasks.Count.Should().Be(1);
        }
        public void CheckArguments_ApiTokenWrong()
        {
            // arrange
            var userId       = 100;
            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("bad_token")).Returns(new User {
                Id = userId
            });


            // act
            var     results = api.All("bad_token") as JsonResult;
            dynamic data    = results.Data;

            // assert
        }
        public void UpdatePlannedDate_CheckFormat_Planned()
        {
            // 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.UpdatePlannedDate(token, 1, "12-12-2011");

            // assert
            var task = ApiTestsCommonSetup.SubmittedTasks[0];

            task.PlannedDate.Should().Be(new DateTime(2011, 12, 12));
        }
        public void UpdateDescription_UpdateTaskDescription()
        {
            // 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.UpdateDescription(token, 1, "new description");

            // assert
            var task = ApiTestsCommonSetup.SubmittedTasks[0];

            Assert.That(task.Description, Is.EqualTo("new description"));
        }