public async Task GetWorkItemAsync_ReturnsWorkItem() { // Arrange WorkItemSummary summary = new WorkItemSummary { Id = 1 }; httpClientMock.WorkItemDetail = new WorkItemDetails { FileAttachments = new List <WorkItemFileAttachment>(), Comments = new List <WorkItemComment>(), WorkItem = new WorkItem() { Id = summary.Id }, CanDeleteComments = true, CanDeleteWorkItem = true }; httpClientMock.SetupMock(); // Act WorkItemDetails details = await codePlexReader.GetWorkItemAsync(summary); // Assert // Spot check. Really the method should just be returning the serialized object from the endpoint // so doing a deep check on the item would be a lot of verification of Newtonsoft.Json Assert.True(details.WorkItem.Id == summary.Id); }
public async Task GetWorkItems_DoesNotIncludeFilteredItems() { // Arrange PagedWorkItemList list = BuildPagedList(2); httpClientMock.Summaries = list; httpClientMock.PageSize = 2; httpClientMock.SetupMock(); // Act IReadOnlyList <WorkItemSummary> readerItems = await codePlexReader.GetWorkItemsAsync( id => { if (id == 0) { return(false); } return(true); }); // Assert Assert.True(readerItems.Count() == 1); WorkItemSummary item = readerItems.First(); Assert.True(item.Id == 1); }
/// <summary> /// Searches TFS using the query provided by the 'q' parameter. /// </summary> public override ActionResult Index(string q, string sortBy, bool?desc, int?page, int?pageSize, string title, string assignedTo, string startDate, string endDate, string status) { IList <WorkItemSummary> summaries = new List <WorkItemSummary>(); ListData data = new ListData(); if (!string.IsNullOrEmpty(q)) { SearchManager manager = new SearchManager(); if (manager.IsId(q)) { // For single work item ids (that exist), redirect straight to their view page int id = int.Parse(q); QueryManager queryManager = new QueryManager(); WorkItemSummary summary = queryManager.ItemById(id); if (summary != null) { return(Redirect(SpruceSettings.SiteUrl + "/" + summary.Controller + "/View/" + id)); } } else { data.WorkItems = manager.Search(q).ToList(); PageList(data, sortBy, desc, page, pageSize); ViewData["search"] = q; } } return(View(data)); }
public void BuildWorkItemLists(int numberOfWorkItems) { Summaries = new List <WorkItemSummary>(); WorkItems = new List <WorkItemDetails>(); for (int i = 0; i < numberOfWorkItems; i++) { WorkItemSummary newSummary = new WorkItemSummary { Id = i }; Summaries.Add(newSummary); WorkItemDetails newDetails = new WorkItemDetails { WorkItem = new WorkItem { Id = i } }; WorkItems.Add(newDetails); } SetupMock(); }
private static void VerifyWorkItemsReturnedAreSameAsSetOnMock(IEnumerable <WorkItemSummary> workItems, PagedWorkItemList mockSetItems) { Assert.True(workItems.Count() == mockSetItems.TotalItems); foreach (WorkItemSummary summary in workItems) { WorkItemSummary sentItem = mockSetItems.WorkItemSummaries.Find(x => x.Id == summary.Id); Assert.NotNull(sentItem); Assert.Equal(sentItem.Title, summary.Title); } }
/// <summary> /// Gets a work item using its id as the lookup. /// </summary> protected virtual WorkItemSummary GetItem(int id) { // We can get away with using the base class here, as no WorkItemType filter is used just an id. QueryManager manager = new QueryManager(); WorkItemSummary item = manager.ItemById(id); // Change the user's current project if this work item is different. // The project can be different if they've come from the stored queries page. if (item.ProjectName != UserContext.Current.CurrentProject.Name) { UserContext.Current.ChangeCurrentProject(item.ProjectName); } return(item); }
/// <summary> /// A helper action that creates a new (dummy) work item using the <see cref="GetManager()"/> method and displays /// all the fields for this work item and the allowed values. This action returns plain text. /// </summary> /// <returns></returns> public ActionResult ShowFields() { WorkItemSummary summary = GetManager().NewItem(); IEnumerable <Field> list = summary.Fields.Cast <Field>().OrderBy(f => f.Name); // This HTML should be moved into a view StringBuilder builder = new StringBuilder(); builder.AppendLine("<html><style>body { font-family:Segoe UI, helvetica } .border { font-size:8pt;border:solid #CCC 1px; margin:5px;padding:5px; } "); builder.AppendLine(".name { font-weight:bold; }"); builder.AppendLine("</style><body>"); builder.AppendFormat("<h1>{0}</h1>", summary.Fields[0].WorkItem.Type.Name); foreach (Field field in list) { builder.AppendLine("<div class=\"border\">"); builder.AppendLine(string.Format("<div class=\"name\">{0}</div><div>[{1}]</div>", field.Name, field.ReferenceName)); builder.AppendLine(string.Format("<div>IsRequired: {0}</div>", field.IsRequired)); if (field.HasAllowedValuesList) { builder.AppendLine("<div>Allowed values: <ul>"); foreach (string item in field.AllowedValues) { builder.AppendLine(string.Format("<li>{0}</li>", item)); } builder.AppendLine("</ul></div>"); } builder.AppendLine("</div>"); } builder.AppendLine("</body></html>"); return(Content(builder.ToString(), "text/html")); }