public async Task ScenarioFromCakeContextExtensionWithBoard_SearchWorkItemById() { // 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); // Act IWorkItem wit = await fakeCakeContext.GetWorkItemByIdAsync(board, this._witId); // Assert Assert.IsType <WorkItem>(wit); Assert.Equal(this._witId, wit.Id); Assert.Equal(this._witState, wit.State); Assert.Equal(this._witTitle, wit.Title); Assert.Equal(this._witType, wit.Type); Assert.Equal(this._witDescription, wit.Description); Assert.Equal(this._witUrl, ((WorkItem)wit).Url); }
public async Task ScenarioFromCakeContextExtensionWithPatAndOrganization_SearchWorkItemById() { // 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); FieldInfo commandBehaviour = typeof(WorkItemCommand).GetRuntimeFields().Single(p => p.Name == "_getWorkItemByIdBehaviourAsync"); object originBehaviour = commandBehaviour.GetValue(typeof(WorkItemCommand)); // Act commandBehaviour.SetValue(typeof(WorkItemCommand), (Func <IBoard, string, Task <IWorkItem> >)((azureBoard, id) => board.GetWorkItemByIdAsync(id))); IWorkItem wit = await fakeCakeContext.GetWorkItemByIdAsync(this._pat, this._organization, this._witId); commandBehaviour.SetValue(typeof(WorkItemCommand), originBehaviour); // Assert Assert.IsType <WorkItem>(wit); Assert.Equal(this._witId, wit.Id); Assert.Equal(this._witState, wit.State); Assert.Equal(this._witTitle, wit.Title); Assert.Equal(this._witType, wit.Type); Assert.Equal(this._witDescription, wit.Description); Assert.Equal(this._witUrl, ((WorkItem)wit).Url); }
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 void Scenario_CtorWithPersonalAccessTokenAndOrganization() { // Arrange string pat = "someone-pat"; string organization = "someone-organization"; // Act var board = new AzureBoards(pat, organization); var client = (HttpClient)typeof(AzureBoards).GetField("_client", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(board); // Assert Assert.Equal(new Uri($"https://dev.azure.com/{organization}"), client.BaseAddress); Assert.Equal(Convert.ToBase64String(Encoding.UTF8.GetBytes($":{pat}")), client.DefaultRequestHeaders.Authorization.Parameter); }
public static async Task <IEnumerable <IWorkItem> > GetWorkItemsByQueryIdAsync( this ICakeContext context, string personalAccessToken, string organization, string id, string project, string team) { var board = new AzureBoards( personalAccessToken.ArgumentNotEmptyOrWhitespace(nameof(personalAccessToken)), organization.ArgumentNotEmptyOrWhitespace(nameof(organization))) { Project = project.ArgumentNotEmptyOrWhitespace(nameof(project)), Team = team.ArgumentNotEmptyOrWhitespace(nameof(team)) }; return(await context.GetWorkItemsByQueryIdAsync( board, id.ArgumentNotEmptyOrWhitespace(nameof(id)))); }
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); } }