public async Task ScenarioFromCakeContextExtension_SearchWorkItemByQueryId() { // Arrange var fakeResponse = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(JsonConvert.SerializeObject(this._fileContent), Encoding.UTF8, "application/json") }; var fakeCakeContext = new FakeCakeContext(logBehaviour: () => new FakeCakeLog()); var fakeClient = new HttpClient(new FakeHttpMessageHandler(fakeResponse)) { BaseAddress = new Uri($"https://dev.azure.com/{this._organization}") }; var board = new AzureBoards(fakeClient) { Project = this._project, Team = this._team }; // Act IEnumerable <IWorkItem> wits = await fakeCakeContext.GetWorkItemsByQueryIdAsync(board, this._queryId); // Assert IEnumerable <WorkItem> concreteWits = wits.Select(wit => Assert.IsType <WorkItem>(wit)).ToList(); for (int i = 0; i < this._workItems.Count(); i++) { Assert.Equal(this._workItems.ElementAt(i).Id, concreteWits.ElementAt(i).Id); Assert.Equal(this._workItems.ElementAt(i).Url, concreteWits.ElementAt(i).Url); } }
public async Task ScenarioFromCakeContextExtensionWithPatAndOrganization_SearchWorkItemByQueryId() { // Arrange var fakeResponse = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(JsonConvert.SerializeObject(this._fileContent), Encoding.UTF8, "application/json") }; var fakeCakeContext = new FakeCakeContext(logBehaviour: () => new FakeCakeLog()); var fakeClient = new HttpClient(new FakeHttpMessageHandler(fakeResponse)) { BaseAddress = new Uri($"https://dev.azure.com/{this._organization}") }; var board = new AzureBoards(fakeClient) { Project = this._project, Team = this._team }; FieldInfo commandBehaviour = typeof(WorkItemCommand).GetRuntimeFields().Single(p => p.Name == "_getWorkItemsByQueryIdBehaviourAsync"); object originBehaviour = commandBehaviour.GetValue(typeof(WorkItemCommand)); // Act commandBehaviour.SetValue(typeof(WorkItemCommand), (Func <IBoard, string, Task <IEnumerable <IWorkItem> > >)((azureBoard, id) => board.GetWorkItemsByQueryIdAsync(id))); IEnumerable <IWorkItem> wits = await fakeCakeContext.GetWorkItemsByQueryIdAsync(this._pat, this._organization, this._queryId, this._project, this._team); commandBehaviour.SetValue(typeof(WorkItemCommand), originBehaviour); // Assert IEnumerable <WorkItem> concreteWits = wits.Select(wit => Assert.IsType <WorkItem>(wit)).ToList(); for (int i = 0; i < this._workItems.Count(); i++) { Assert.Equal(this._workItems.ElementAt(i).Id, concreteWits.ElementAt(i).Id); Assert.Equal(this._workItems.ElementAt(i).Url, concreteWits.ElementAt(i).Url); } }