Ejemplo n.º 1
0
        private async Task <int> setupTest()
        {
            // Create a project and time entry
            var mainProject = await projectController.CreateProject(new ProjectCreateDTO()
            {
                ClientName  = "Spongebob Squarepants",
                Description = "Eat spongebob's pineapple house",
                ProjectName = "Eat Pineapple",
                Tags        = new List <string>()
                {
                    "Food"
                }
            });

            var timeEntries = new List <TimeEntryDTO>()
            {
                new TimeEntryDTO()
                {
                    CreatedTime = DateTime.Now,
                    Day         = new DateTime(1999, 1, 10),
                    Length      = 5,
                    Notes       = "Consumed leafs",
                    ProjectId   = mainProject.Data
                },
                new TimeEntryDTO()
                {
                    CreatedTime = DateTime.Now,
                    Day         = new DateTime(1999, 1, 10),
                    Length      = 2,
                    Notes       = "Consumed Door",
                    ProjectId   = mainProject.Data
                },
                new TimeEntryDTO()
                {
                    CreatedTime = DateTime.Now,
                    Day         = new DateTime(1999, 1, 10),
                    Length      = 3,
                    Notes       = "Consumed back of pineapple",
                    ProjectId   = mainProject.Data
                }
            };

            foreach (var entry in timeEntries)
            {
                await timeEntryController.CreateTime(entry);
            }

            // Get project invite code
            var projectDetails = await projectController.GetProjectById(mainProject.Data);

            // Login as 2nd user
            TestAuthHelpers.LogInUser(database, configuration, new List <ControllerBase>()
            {
                timeEntryController,
                projectController,
                reportController
            }, projectDetails.Data.InviteCode).GetAwaiter().GetResult();

            var timeEntries2 = new List <TimeEntryDTO>()
            {
                new TimeEntryDTO()
                {
                    CreatedTime = DateTime.Now,
                    Day         = new DateTime(2000, 1, 10),
                    Length      = 1,
                    Notes       = "Consumed left window",
                    ProjectId   = mainProject.Data
                },
                new TimeEntryDTO()
                {
                    CreatedTime = DateTime.Now,
                    Day         = new DateTime(2000, 1, 10),
                    Length      = 1,
                    Notes       = "Consumed right window",
                    ProjectId   = mainProject.Data
                }
            };

            foreach (var entry in timeEntries2)
            {
                await timeEntryController.CreateTime(entry);
            }

            return(mainProject.Data);
        }
Ejemplo n.º 2
0
        public async Task TestTimeEntry()
        {
            var projectResults = await projectController.CreateProject(new ProjectCreateDTO()
            {
                ClientName  = "Test Client",
                Description = "Test Desciption",
                ProjectName = "Best project 10/10",
                Tags        = new List <string>()
                {
                    "AngryCarrot"
                }
            });

            database.ChangeTracker.Clear();

            var projectId = projectResults.Data;

            var testTimeEntry = new TimeEntryDTO()
            {
                Day       = new DateTime(1999, 6, 18),
                Length    = 5,
                Notes     = "Happy Birthday",
                ProjectId = projectId
            };

            // Create time
            var createTimeResults = await timeEntryController.CreateTime(testTimeEntry);

            Assert.IsTrue(createTimeResults.Success);
            Assert.IsTrue(createTimeResults.Data > 0);

            // Get the time entry
            var getCreatedTimeResults = await timeEntryController.Get(createTimeResults.Data);

            Assert.AreEqual(getCreatedTimeResults.Success, true);
            Assert.AreEqual(testTimeEntry.Day, getCreatedTimeResults.Data.Day);
            Assert.AreEqual(testTimeEntry.Length, getCreatedTimeResults.Data.Length);
            Assert.AreEqual(testTimeEntry.Notes, getCreatedTimeResults.Data.Notes);
            Assert.IsTrue(DateTime.UtcNow > getCreatedTimeResults.Data.CreatedTime);

            var updatedTimeEntry = new TimeEntryDTO()
            {
                Id     = createTimeResults.Data,
                Day    = new DateTime(1989, 10, 24),
                Notes  = "pewdiepie",
                Length = 5
            };

            // Update time
            var updateTimeResuls = await timeEntryController.UpdateTime(updatedTimeEntry);

            // Get the time entry
            var getUpdatedTimeResults = await timeEntryController.Get(updateTimeResuls.Data);

            Assert.AreEqual(getUpdatedTimeResults.Success, true);
            Assert.AreEqual(getUpdatedTimeResults.Data.Id, getCreatedTimeResults.Data.Id);
            Assert.AreEqual(updatedTimeEntry.Day, getUpdatedTimeResults.Data.Day);
            Assert.AreEqual(updatedTimeEntry.Length, getUpdatedTimeResults.Data.Length);
            Assert.AreEqual(updatedTimeEntry.Notes, getUpdatedTimeResults.Data.Notes);
            Assert.AreEqual(getUpdatedTimeResults.Data.CreatedTime, getCreatedTimeResults.Data.CreatedTime);
            Assert.IsTrue(getCreatedTimeResults.Data.LastModified < getUpdatedTimeResults.Data.LastModified);

            // Search for projects

            var singleDayNoResults = await timeEntryController.GetInDateRange(new DateRangeDTO()
            {
                StartDate = DateTime.Now,
                EndDate   = DateTime.Now
            });

            Assert.AreEqual(singleDayNoResults.Success, true);
            Assert.AreEqual(singleDayNoResults.Data.Count, 0);

            var singleDayResults = await timeEntryController.GetInDateRange(new DateRangeDTO()
            {
                StartDate = updatedTimeEntry.Day,
                EndDate   = updatedTimeEntry.Day
            });

            Assert.AreEqual(singleDayResults.Success, true);
            Assert.AreEqual(singleDayResults.Data.Count, 1);

            var multipleDayResults = await timeEntryController.GetInDateRange(new DateRangeDTO()
            {
                StartDate = updatedTimeEntry.Day.AddDays(-10),
                EndDate   = updatedTimeEntry.Day.AddDays(123)
            });

            Assert.AreEqual(multipleDayResults.Success, true);
            Assert.AreEqual(multipleDayResults.Data.Count, 1);
        }