Ejemplo n.º 1
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>");
        }
Ejemplo n.º 2
0
        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");
        }
Ejemplo n.º 3
0
        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");
        }
Ejemplo n.º 4
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");
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        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");
        }
Ejemplo n.º 8
0
        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");
        }
Ejemplo n.º 9
0
        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");
        }
Ejemplo n.º 10
0
        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);
        }
Ejemplo n.º 11
0
        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);
        }
Ejemplo n.º 12
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();
        }
Ejemplo n.º 13
0
        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);
        }
Ejemplo n.º 14
0
        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
        }
Ejemplo n.º 15
0
        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));
        }
Ejemplo n.º 16
0
        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"));
        }