Add() public method

https://www.toggl.com/public/api#post_time_entries
public Add ( TimeEntry obj ) : TimeEntry
obj TimeEntry
return TimeEntry
Ejemplo n.º 1
0
        public void GetDetailedReportSince()
        {
            var timeEntryService = new TimeEntryService(Constants.ApiToken);
            for (int i = 0; i < 6; i++)
            {
                var timeEntry = new TimeEntry()
                {
                    IsBillable = true,
                    CreatedWith = "TimeEntryTestAdd",
                    Description = "Test Desc" + DateTime.Now.Ticks,
                    Duration = 900,
                    Start = DateTime.Now.AddDays(-i).ToIsoDateStr(),
                    Stop = DateTime.Now.AddDays(-i).AddMinutes(20).ToIsoDateStr(),
                    ProjectId = DefaultProjectId,
                    WorkspaceId = DefaultWorkspaceId
                };
                var expTimeEntry = timeEntryService.Add(timeEntry);
                Assert.IsNotNull(expTimeEntry);
            }

			var standardParams = new DetailedReportParams()
			{
				UserAgent = "TogglAPI.Net",
				WorkspaceId = DefaultWorkspaceId				
			};

            var result = ReportService.Detailed(standardParams);
            Assert.AreEqual(result.Data.Count, 6);
            Assert.AreEqual(result.TotalCount, 6);

            var te = new TimeEntry()
            {
                IsBillable = true,
                CreatedWith = "TimeEntryTestAdd",
                Description = "Test Desc" + DateTime.Now.Ticks,
                Duration = 900,
                Start = DateTime.Now.AddDays(-7).ToIsoDateStr(),
                Stop = DateTime.Now.AddDays(-7).AddMinutes(20).ToIsoDateStr(),
                ProjectId = DefaultProjectId,
                WorkspaceId = DefaultWorkspaceId
            };
            var expTe = timeEntryService.Add(te);
            Assert.IsNotNull(expTe);

            result = ReportService.Detailed(standardParams);
            Assert.AreEqual(result.Data.Count, 6);
            Assert.AreEqual(result.TotalCount, 6);

            result = ReportService.Detailed(new DetailedReportParams()
                                            {
                                                UserAgent = "test_api",
                                                WorkspaceId = DefaultWorkspaceId,
                                                Since = DateTime.Now.AddDays(-7).ToIsoDateStr()
                                            });
            Assert.AreEqual(result.Data.Count, 7);
            Assert.AreEqual(result.TotalCount, 7);
        }
Ejemplo n.º 2
0
        public void GetTimeEntriesByTaskId()
        {
			var task1 = TaskService.Add(new Task
			{
				IsActive = true,
				Name = "task1",
				EstimatedSeconds = 3600,
				WorkspaceId = DefaultWorkspaceId,
				ProjectId = DefaultProjectId
			});
			Assert.IsNotNull(task1);

			var task2 = TaskService.Add(new Task
			{
				IsActive = true,
				Name = "task2",
				EstimatedSeconds = 3600,
				WorkspaceId = DefaultWorkspaceId,
				ProjectId = DefaultProjectId
			});
			Assert.IsNotNull(task2);

			var timeEntryService = new TimeEntryService(Constants.ApiToken);
            for (int i = 0; i < 3; i++)
            {
                var timeEntry = new TimeEntry()
                {
                    IsBillable = true,
                    CreatedWith = "TimeEntryTestAdd",
                    Description = "Test Desc" + DateTime.Now.Ticks,
                    Duration = 900,
                    Start = DateTime.Now.AddDays(-i).ToIsoDateStr(),
                    Stop = DateTime.Now.AddDays(-i).AddMinutes(20).ToIsoDateStr(),
                    WorkspaceId = DefaultWorkspaceId,
                    TaskId = task1.Id
                };
                var expTimeEntry = timeEntryService.Add(timeEntry);
                Assert.IsNotNull(expTimeEntry);
            }

			for (int i = 0; i < 3; i++)
			{
				var timeEntry = new TimeEntry()
				{
					IsBillable = true,
					CreatedWith = "TimeEntryTestAdd",
					Description = "Test Desc" + DateTime.Now.Ticks,
					Duration = 900,
					Start = DateTime.Now.AddDays(-i).ToIsoDateStr(),
					Stop = DateTime.Now.AddDays(-i).AddMinutes(20).ToIsoDateStr(),
					WorkspaceId = DefaultWorkspaceId,
					TaskId = task2.Id
				};
				var expTimeEntry = timeEntryService.Add(timeEntry);
				Assert.IsNotNull(expTimeEntry);
			}

			var standardParams = new DetailedReportParams()
			{
				UserAgent = "TogglAPI.Net",
				WorkspaceId = DefaultWorkspaceId,
				Since = DateTime.Now.AddYears(-1).ToIsoDateStr(),
				TaskIds = string.Format("{0},{1}", task1.Id.Value, task2.Id.Value)
			};

            var result = ReportService.Detailed(standardParams);
            Assert.AreEqual(result.Data.Count, 6);
            Assert.AreEqual(result.TotalCount, 6);

	        standardParams.TaskIds = task1.Id.Value.ToString();

			result = ReportService.Detailed(standardParams);
			Assert.AreEqual(result.Data.Count, 3);
			Assert.AreEqual(result.TotalCount, 3);

        }
Ejemplo n.º 3
0
		public void MergeMoreThanTwoTasks()
		{
			var task1 = TaskService.Add(new Task
			{
				IsActive = true,
				Name = "task1",
				EstimatedSeconds = 3600,
				WorkspaceId = DefaultWorkspaceId,
				ProjectId = DefaultProjectId
			});
			Assert.IsNotNull(task1);

			var task2 = TaskService.Add(new Task
			{
				IsActive = true,
				Name = "task2",
				EstimatedSeconds = 3600,
				WorkspaceId = DefaultWorkspaceId,
				ProjectId = DefaultProjectId
			});
			Assert.IsNotNull(task2);

			var task3 = TaskService.Add(new Task
			{
				IsActive = true,
				Name = "task3",
				EstimatedSeconds = 3600,
				WorkspaceId = DefaultWorkspaceId,
				ProjectId = DefaultProjectId
			});
			Assert.IsNotNull(task3);

			var timeEntryService = new TimeEntryService(Constants.ApiToken);
			for (int i = 0; i < 3; i++)
			{
				var timeEntry = new TimeEntry()
				{
					IsBillable = true,
					CreatedWith = "TimeEntryTestAdd",
					Description = "Test Desc" + DateTime.Now.Ticks,
					Duration = 900,
					Start = DateTime.Now.AddDays(-i).ToIsoDateStr(),
					Stop = DateTime.Now.AddDays(-i).AddMinutes(20).ToIsoDateStr(),
					WorkspaceId = DefaultWorkspaceId,
					TaskId = task1.Id
				};
				var expTimeEntry = timeEntryService.Add(timeEntry);
				Assert.IsNotNull(expTimeEntry);
			}

			for (int i = 0; i < 3; i++)
			{
				var timeEntry = new TimeEntry()
				{
					IsBillable = true,
					CreatedWith = "TimeEntryTestAdd",
					Description = "Test Desc" + DateTime.Now.Ticks,
					Duration = 900,
					Start = DateTime.Now.AddDays(-i).ToIsoDateStr(),
					Stop = DateTime.Now.AddDays(-i).AddMinutes(20).ToIsoDateStr(),
					WorkspaceId = DefaultWorkspaceId,
					TaskId = task2.Id
				};
				var expTimeEntry = timeEntryService.Add(timeEntry);
				Assert.IsNotNull(expTimeEntry);
			}

			for (int i = 0; i < 3; i++)
			{
				var timeEntry = new TimeEntry()
				{
					IsBillable = true,
					CreatedWith = "TimeEntryTestAdd",
					Description = "Test Desc" + DateTime.Now.Ticks,
					Duration = 900,
					Start = DateTime.Now.AddDays(-i).ToIsoDateStr(),
					Stop = DateTime.Now.AddDays(-i).AddMinutes(20).ToIsoDateStr(),
					WorkspaceId = DefaultWorkspaceId,
					TaskId = task3.Id
				};
				var expTimeEntry = timeEntryService.Add(timeEntry);
				Assert.IsNotNull(expTimeEntry);
			}

			Assert.AreEqual(3, TimeEntryService.List().Count(te => te.TaskId == task1.Id.Value));
			Assert.AreEqual(3, TimeEntryService.List().Count(te => te.TaskId == task2.Id.Value));
			Assert.AreEqual(3, TimeEntryService.List().Count(te => te.TaskId == task3.Id.Value));

			TaskService.Merge(task1.Id.Value, new [] { task2.Id.Value, task3.Id.Value}, DefaultWorkspaceId);

			Assert.AreEqual(9, TimeEntryService.List().Count(te => te.TaskId == task1.Id.Value));
			Assert.AreEqual(0, TimeEntryService.List().Count(te => te.TaskId == task2.Id.Value));
			Assert.AreEqual(0, TimeEntryService.List().Count(te => te.TaskId == task3.Id.Value));
			Assert.IsFalse(WorkspaceService.Tasks(DefaultWorkspaceId).Select(t => t.Id).Contains(task2.Id));
			Assert.IsFalse(WorkspaceService.Tasks(DefaultWorkspaceId).Select(t => t.Id).Contains(task3.Id));
		}