public async Task ScenarioFromCakeContextExtensionWithBoard_SearchTaskById()
        {
            // Arrange
            HttpResponseMessage fakeResponse = new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent(JsonConvert.SerializeObject(this._fileContent), Encoding.UTF8, "application/json")
            };
            FakeCakeContext fakeCakeContext = new FakeCakeContext(logBehaviour: () => new FakeCakeLog());
            HttpClient      fakeClient      = new HttpClient(new FakeHttpMessageHandler(fakeResponse))
            {
                BaseAddress = new Uri("https://app.asana.com/api/1.0")
            };
            Asana board = new Asana(fakeClient);

            // Act
            IWorkItem wit = await fakeCakeContext.GetWorkItemByIdAsync(board, this._taskid);

            // Assert
            Assert.IsType <Models.Task>(wit);

            Assert.Equal(this._taskid, wit.Id);
            Assert.Equal(this._taskState, ((Models.Task)wit).State);
            Assert.Equal(this._taskTitle, wit.Title);
            Assert.Equal(this._taskType, wit.Type);
            Assert.Equal(this._taskDescription, wit.Description);
        }
Ejemplo n.º 2
0
        public async Task ScenarioFromCakeContextExtensionWithPatAndProject_SearchTasksByProject()
        {
            // Arrange
            HttpResponseMessage fakeResponse = new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent(JsonConvert.SerializeObject(this._fileContent), Encoding.UTF8, "application/json")
            };
            FakeCakeContext fakeCakeContext = new FakeCakeContext(logBehaviour: () => new FakeCakeLog());
            HttpClient      fakeClient      = new HttpClient(new FakeHttpMessageHandler(fakeResponse))
            {
                BaseAddress = new Uri("https://app.asana.com/api/1.0")
            };
            Asana board = new Asana(fakeClient)
            {
                ProjectId = this._projectId
            };

            FieldInfo commandBehaviour = typeof(AsanaCommandAliases).GetRuntimeFields().Single(p => p.Name == "_getTasksByProjectIdBehaviourAsync");
            object    originBehaviour  = commandBehaviour.GetValue(typeof(AsanaCommandAliases));

            // Act
            commandBehaviour.SetValue(typeof(AsanaCommandAliases), (Func <IBoard, string, Task <IEnumerable <IWorkItem> > >)((azureBoard, id) => ((Asana)board).GetWorkItemsByProjectIdAsync(id)));
            IEnumerable <IWorkItem> wits = await fakeCakeContext.GetTasksByProjectIdAsync(this._pat, this._projectId);

            commandBehaviour.SetValue(typeof(AsanaCommandAliases), originBehaviour);

            // Assert
            IEnumerable <Models.Task> concreteWits = wits.Select(wit => Assert.IsType <Models.Task>(wit)).ToList();

            for (int i = 0; i < this._workItems.Count(); i++)
            {
                Assert.Equal(this._workItems.ElementAt(i).Id, concreteWits.ElementAt(i).Id);
            }
        }
        public async Task ScenarioFromCakeContextExtensionWithPatAndOrganization_SearchTaskById()
        {
            // Arrange
            HttpResponseMessage fakeResponse = new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent(JsonConvert.SerializeObject(this._fileContent), Encoding.UTF8, "application/json")
            };
            FakeCakeContext fakeCakeContext = new FakeCakeContext(logBehaviour: () => new FakeCakeLog());
            HttpClient      fakeClient      = new HttpClient(new FakeHttpMessageHandler(fakeResponse))
            {
                BaseAddress = new Uri("https://app.asana.com/api/1.0")
            };
            Asana board = new Asana(fakeClient);

            FieldInfo commandBehaviour = typeof(BoardCommandAliases).GetRuntimeFields().Single(p => p.Name == "_getWorkItemByIdBehaviourAsync");
            object    originBehaviour  = commandBehaviour.GetValue(typeof(BoardCommandAliases));

            // Act
            commandBehaviour.SetValue(typeof(BoardCommandAliases), (Func <IBoard, string, Task <IWorkItem> >)((azureBoard, id) => board.GetWorkItemByIdAsync(id)));
            IWorkItem wit = await fakeCakeContext.GetTaskByIdAsync(this._pat, this._taskid);

            commandBehaviour.SetValue(typeof(BoardCommandAliases), originBehaviour);

            // Assert
            Assert.IsType <Models.Task>(wit);

            Assert.Equal(this._taskid, wit.Id);
            Assert.Equal(this._taskState, ((Models.Task)wit).State);
            Assert.Equal(this._taskTitle, wit.Title);
            Assert.Equal(this._taskType, wit.Type);
            Assert.Equal(this._taskDescription, wit.Description);
        }
Ejemplo n.º 4
0
        public async Task ScenarioFromCakeContextExtension_SearchTasksByProjectId()
        {
            // Arrange
            HttpResponseMessage fakeResponse = new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent(JsonConvert.SerializeObject(this._fileContent), Encoding.UTF8, "application/json")
            };
            FakeCakeContext fakeCakeContext = new FakeCakeContext(logBehaviour: () => new FakeCakeLog());
            HttpClient      fakeClient      = new HttpClient(new FakeHttpMessageHandler(fakeResponse))
            {
                BaseAddress = new Uri("https://app.asana.com/api/1.0")
            };
            Asana board = new Asana(fakeClient)
            {
                ProjectId = this._projectId
            };

            // Act
            IEnumerable <IWorkItem> wits = await fakeCakeContext.GetTasksByProjectIdAsync(board, this._projectId);

            // Assert
            IEnumerable <Models.Task> concreteWits = wits.Select(wit => Assert.IsType <Models.Task>(wit)).ToList();

            for (int i = 0; i < this._workItems.Count(); i++)
            {
                Assert.Equal(this._workItems.ElementAt(i).Id, concreteWits.ElementAt(i).Id);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Old API format
        /// </summary>
        /// <returns></returns>
        private static void ExecuteWithTasks()
        {
            // CONFIGURE YOUR ASANA API TOKEN IN APPSETTINGS.CONFIG FILE
            var startTime = DateTime.Now;

            Console.WriteLine("# Asana - Task Method #");
            var apiToken = GetApiToken();
            var asana    = new Asana(apiToken, AuthenticationType.Basic, errorCallback);

            asana.GetMe(response =>
            {
                var me = (AsanaUser)response;
                Console.WriteLine("Hello, " + me.Name);
            }).Wait();

            asana.GetWorkspaces(o =>
            {
                foreach (AsanaWorkspace workspace in o)
                {
                    Console.WriteLine("Workspace: " + workspace.Name);

                    // Times
                    asana.GetTeamsInWorkspace(workspace, teams =>
                    {
                        foreach (AsanaTeam team in teams)
                        {
//                            if (team.Name != "Projetos Especiais")
//                                continue;

                            Console.WriteLine("  Team: " + team.Name);

                            // Projetos
                            asana.GetProjectsInTeam(team, projects =>
                            {
                                foreach (AsanaProject project in projects)
                                {
                                    Console.WriteLine("    Project: " + project.Name);

                                    asana.GetTasksInAProject(project, tasks =>
                                    {
                                        foreach (AsanaTask task in tasks)
                                        {
                                            Console.WriteLine("      Task: " + task.Name);
                                        }
                                    }).Wait();
                                }
                            }).Wait();
                        }
                    }).Wait();
                }
            }).Wait();


            Console.WriteLine();
            Console.WriteLine("Execution time " + (DateTime.Now - startTime));
            Console.ReadLine();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// New API format
        /// </summary>
        /// <returns></returns>
        private static async Task ExecuteAsync()
        {
            // CONFIGURE YOUR ASANA API TOKEN IN APPSETTINGS.CONFIG FILE
            var startTime = DateTime.Now;

            Console.WriteLine("# Asana - Async Method #");
            var apiToken = GetApiToken();
            var asana    = new Asana(apiToken, AuthenticationType.Basic, errorCallback);

            var me = await asana.GetMeAsync();

            Console.WriteLine("Hello, " + me.Name);

            var workspaces = await asana.GetWorkspacesAsync();

            foreach (var workspace in workspaces)
            {
                Console.WriteLine("Workspace: " + workspace.Name);

                var teams = await asana.GetTeamsInWorkspaceAsync(workspace);

                foreach (var team in teams)
                {
//                    if (team.Name != "Projetos Especiais")
//                        continue;

                    Console.WriteLine("  Team: " + team.Name);

                    // Projects
                    var projects = await asana.GetProjectsInTeamAsync(team);

                    foreach (AsanaProject project in projects)
                    {
                        Console.WriteLine("    Project: " + project.Name);

                        var tasks = await asana.GetTasksInAProjectAsync(project);

                        foreach (AsanaTask task in tasks)
                        {
                            Console.WriteLine("      Task: " + task.Name);
                        }
                    }
                }
            }


            Console.WriteLine();
            Console.WriteLine("Execution time " + (DateTime.Now - startTime));
            Console.ReadLine();
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            CreateMenus();

            Console.WriteLine("Welcome to the Asana API.");
            Console.WriteLine("-------------------------");

            _accessToken = ConfigurationManager.AppSettings.Get("AsanaToken");
            _asana       = new Asana(_accessToken);

            GetSelf();

            //show the main menu
            menuCollection.ShowMenu(1);
        }
Ejemplo n.º 8
0
        private static async Task MonitorProjectChanges(long projectId, TimeSpan interval)
        {
            var apiToken = GetApiToken();
            var asana    = new Asana(apiToken, AuthenticationType.Basic, errorCallback);

            //var project = await asana.GetProjectByIdAsync(projectId);
            //var events = await asana.GetEventsInAProjectAsync(project, "8233e364b4a1a439d0ace299e825a47b:2");

            var lastToken = string.Empty;

            while (true)
            {
                var events = await asana.GetEventsInAProjectAsync(projectId, lastToken);

                lastToken = events.Sync;
                if (events.Data != null)
                {
                    foreach (var item in events.Data)
                    {
                        Console.WriteLine($"{item.CreatedAt} - {item.Type}: {item.Action}");
                        if (item.Resource != null)
                        {
                            var line1 =
                                $"    {item.Resource.CreatedAt} - {item.Resource.Name} - {item.Resource.CreatedBy?.Name}";
                            var line2 = $"    {item.Resource.Type} - {item.Resource.Text}";
                            if (line1.Trim().Length > 2)
                            {
                                Console.WriteLine(line1);
                            }
                            if (line2.Trim().Length > 1)
                            {
                                Console.WriteLine(line2);
                            }
                        }
                    }
                }
                Thread.Sleep(interval);
            }
        }
Ejemplo n.º 9
0
        public AsanaWorkSpace(string workspaceName)
        {
            _asanaRef = new Asana(key, AuthenticationType.Basic, errorCallback);


            _asanaRef.GetMe(o =>
            {
                _user = o as AsanaUser;
            });

            _asanaRef.GetWorkspaces(o =>
            {
                foreach (AsanaWorkspace workspace in o)
                {
                    Debug.WriteLine("Found Workspace: " + workspace.Name);
                    if (workspace.Name.Equals(workspaceName, StringComparison.OrdinalIgnoreCase))
                    {
                        _workspace = workspace;
                    }
                }
                Debug.WriteLine("Active Workspace: " + _workspace.Name);
            }).Wait();
        }
Ejemplo n.º 10
0
        /// <summary>
        /// New API format - Parallel execution
        /// </summary>
        /// <returns></returns>
        private static async Task ExecuteParallelAsync()
        {
            // CONFIGURE YOUR ASANA API TOKEN IN APPSETTINGS.CONFIG FILE
            var startTime = DateTime.Now;

            Console.WriteLine("# Asana - Async Method #");
            var apiToken = GetApiToken();
            var asana    = new Asana(apiToken, AuthenticationType.Basic, errorCallback);

            // Parallel tasks
            var meTask = asana.GetMeAsync();

            var workspaces = await asana.GetWorkspacesAsync();

//            var workspacesConcurrentList = new ConcurrentQueue<AsanaWorkspace>(workspaces);
            var workspaceTasks = workspaces.Select(async workspace =>
            {
                var workSpaceInfo = new HierarchicalParallelExecutionData
                {
                    Info   = "Workspace: " + workspace.Name,
                    Object = workspace
                };

                // Teams
                var teams = await asana.GetTeamsInWorkspaceAsync(workspace);
//                var teamsConcurrentList = new ConcurrentQueue<AsanaTeam>(teams);
                var teamTasks = teams.Select(async team =>
                {
//                    if (team.Name != "Projetos Especiais")
//                        return;

                    var teamInfo = new HierarchicalParallelExecutionData
                    {
                        Info   = "  Team: " + team.Name,
                        Object = team
                    };
                    workSpaceInfo.Items.Add(teamInfo);

                    // Projects
                    var projects = await asana.GetProjectsInTeamAsync(team);
//                    var projectsConcurrentList = new ConcurrentQueue<AsanaProject>(projects);
                    var projectTasks = projects.Select(async project =>
                    {
                        var projectInfo = new HierarchicalParallelExecutionData
                        {
                            Info   = "    Project: " + project.Name,
                            Object = team
                        };
                        teamInfo.Items.Add(projectInfo);

                        // Taks
                        var tasks = await asana.GetTasksInAProjectAsync(project);
                        foreach (var task in tasks)
                        {
                            var taskInfo = new HierarchicalParallelExecutionData
                            {
                                Info   = "      Task: " + task.Name,
                                Object = team
                            };
                            projectInfo.Items.Add(taskInfo);
                        }
                    });
                    await Task.WhenAll(projectTasks);
                });
                await Task.WhenAll(teamTasks);

                return(workSpaceInfo);
            });
            var hierarchicalCall = await Task.WhenAll(workspaceTasks);

            var me = meTask.Result;

            Console.WriteLine("Hello, " + me.Name);

            foreach (var item in hierarchicalCall)
            {
                item.WriteToConsole();
            }

            Console.WriteLine();
            Console.WriteLine("Execution time " + (DateTime.Now - startTime));
            Console.ReadLine();
        }