Exemplo n.º 1
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);
            }
        }
Exemplo 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);
            }
        }