зеркало из
1
0
Форкнуть 0

Merge branch 'master' into users/jmarks

This commit is contained in:
Justin Marks 2017-01-19 16:09:29 -08:00 коммит произвёл GitHub
Родитель 6fcc28d433 8cd5e8e64c
Коммит 16cf1d3cba
122 изменённых файлов: 8459 добавлений и 1264 удалений

4
.gitignore поставляемый
Просмотреть файл

@ -20,3 +20,7 @@
/VstsClientLibrariesSamples.Tests/app.Release.config
/VSTSRestApiSamples.UnitTests/app.Debug.config
/VSTSRestApiSamples.UnitTests/app.Release.config
/VstsClientLibrariesSamples.Tests/obj/Release
/VstsClientLibrariesSamples/obj/Release
/VSTSRestApiSamples/obj/Release
/VSTSRestApiSamples.UnitTests/obj/Release

Просмотреть файл

@ -0,0 +1,5 @@
{
"ExpandedNodes": [
""
]
}

Двоичные данные
.vs/slnx.sqlite Normal file

Двоичный файл не отображается.

Просмотреть файл

@ -1,12 +1,15 @@
namespace VstsRestApiSamples.Tests
namespace VstsRestApiSamples.Tests
{
public class Configuration : IConfiguration
{
public string AccountName { get; set; }
public string ApplicationId { get; set; }
public string UriString { get { return string.Format("https://{0}.visualstudio.com", AccountName); } }
public string CollectionId { get; set; }
public string PersonalAccessToken { get; set; }
public string Project { get; set; }
public string Team { get; set; }
public string MoveToProject { get; set; }
public string Query { get; set; }
public string Identity { get; set; }
@ -16,5 +19,6 @@
public string PickListId { get; set; }
public string QueryId { get; set; }
public string FilePath { get; set; }
public string GitRepositoryId { get; set; }
}
}

Просмотреть файл

@ -0,0 +1,86 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using VstsRestApiSamples.Git;
using System.Net;
namespace VstsRestApiSamples.Tests.Git
{
[TestClass]
public class GitRepositoryTest
{
private IConfiguration _configuration = new Configuration();
[TestInitialize]
public void TestInitialize()
{
InitHelper.GetConfiguration(_configuration);
}
[TestCleanup]
public void TestCleanup()
{
_configuration = null;
}
[TestMethod, TestCategory("REST API")]
public void Git_Repository_GetAllRepositories_Success()
{
//arrange
GitRepository request = new GitRepository(_configuration);
//act
var response = request.GetAllRepositories();
//assert
Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode);
request = null;
}
[TestMethod, TestCategory("REST API")]
public void Git_Repository_GetAllRepositoryById_Success()
{
//arrange
GitRepository request = new GitRepository(_configuration);
//act
var response = request.GetRepositoryById(_configuration.GitRepositoryId);
//assert
Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode);
request = null;
}
[TestMethod, TestCategory("REST API")]
public void Git_Repository_GetFolderAndChildren_Success()
{
//arrange
GitRepository request = new GitRepository(_configuration);
//act
var response = request.GetFolderAndChildren(_configuration.GitRepositoryId, "/");
//assert
Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode);
request = null;
}
[TestMethod, TestCategory("REST API")]
public void Git_Repository_GetCommitsByRepositoryId_Success()
{
//arrange
GitRepository request = new GitRepository(_configuration);
//act
var response = request.GetCommitsByRepositoryId(_configuration.GitRepositoryId);
//assert
Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode);
request = null;
}
}
}

Просмотреть файл

@ -6,10 +6,13 @@ namespace VstsRestApiSamples.Tests
{
public static IConfiguration GetConfiguration(IConfiguration configuration)
{
configuration.AccountName = ConfigurationSettings.AppSettings["appsetting.accountname"].ToString();
configuration.ApplicationId = ConfigurationSettings.AppSettings["appsetting.applicationId"].ToString();
configuration.CollectionId = ConfigurationSettings.AppSettings["appsetting.collectionid"].ToString();
configuration.PersonalAccessToken = ConfigurationSettings.AppSettings["appsetting.pat"].ToString();
configuration.Project = ConfigurationSettings.AppSettings["appsetting.project"].ToString();
configuration.Team = ConfigurationSettings.AppSettings["appsetting.team"].ToString();
configuration.MoveToProject = ConfigurationSettings.AppSettings["appsetting.movetoproject"].ToString();
configuration.Query = ConfigurationSettings.AppSettings["appsetting.query"].ToString();
configuration.Identity = ConfigurationSettings.AppSettings["appsetting.identity"].ToString();
@ -19,6 +22,7 @@ namespace VstsRestApiSamples.Tests
configuration.PickListId = ConfigurationSettings.AppSettings["appsetting.picklistid"].ToString();
configuration.QueryId = ConfigurationSettings.AppSettings["appsetting.queryid"].ToString();
configuration.FilePath = ConfigurationSettings.AppSettings["appsetting.filepath"].ToString();
configuration.GitRepositoryId = ConfigurationSettings.AppSettings["appsetting.git.repositoryid"].ToString();
return configuration;
}

Просмотреть файл

@ -31,7 +31,7 @@ namespace VstsRestApiSamples.Tests.ProjectsAndTeams
Processes request = new Processes(_configuration);
// act
var response = request.GetListOfProcesses();
var response = request.GetProcesses();
// assert
Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode);
@ -46,7 +46,7 @@ namespace VstsRestApiSamples.Tests.ProjectsAndTeams
Processes request = new Processes(_configuration);
// act
var listResponse = request.GetListOfProcesses(); // get list of processes
var listResponse = request.GetProcesses(); // get list of processes
IList<ListofProcessesResponse.Value> vm = listResponse.value; // bind to list
string processId = vm[0].id; // get a process id so we can look that up

Просмотреть файл

@ -0,0 +1,42 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
using System.Net;
using VstsRestApiSamples.ProjectsAndTeams;
using VstsRestApiSamples.ViewModels.ProjectsAndTeams;
namespace VstsRestApiSamples.Tests.ProjectsAndTeams
{
[TestClass]
public class ProjectCollectionsTest
{
private IConfiguration _configuration = new Configuration();
[TestInitialize]
public void TestInitialize()
{
InitHelper.GetConfiguration(_configuration);
}
[TestCleanup]
public void TestCleanup()
{
_configuration = null;
}
[TestMethod, TestCategory("REST API")]
public void ProjectsAndTeams_ProjectCollections_GetProcess_Success()
{
// arrange
ProjectCollections request = new ProjectCollections(_configuration);
// act
var response = request.GetProjectCollection(_configuration.CollectionId);
// assert
Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode);
request = null;
}
}
}

Просмотреть файл

@ -0,0 +1,143 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Net;
using VstsRestApiSamples.ProjectsAndTeams;
namespace VstsRestApiSamples.Tests.ProjectsAndTeams
{
[TestClass]
public class SamplesTest
{
private IConfiguration _configuration = new Configuration();
[TestInitialize]
public void TestInitialize()
{
InitHelper.GetConfiguration(_configuration);
}
[TestCleanup]
public void TestCleanup()
{
_configuration = null;
}
[TestMethod, TestCategory("REST API")]
public void Samples_Teams_GetTeams_Success()
{
// arrange
Samples request = new Samples(_configuration);
// act
string response = request.GetTeams();
// assert
if (response == "not found")
{
Assert.Inconclusive("project not found");
}
else
{
Assert.AreEqual("success", response);
}
request = null;
}
[TestMethod, TestCategory("REST API")]
public void Samples_Teams_GetTeam_Success()
{
// arrange
Samples request = new Samples(_configuration);
// act
string response = request.GetTeam();
// assert
if (response == "not found")
{
Assert.Inconclusive("team not found");
}
else
{
Assert.AreEqual("success", response);
}
request = null;
}
[TestMethod, TestCategory("REST API")]
public void Samples_Teams_GetTeamMembers_Success()
{
// arrange
Samples request = new Samples(_configuration);
// act
string response = request.GetTeamMembers();
// assert
if (response == "not found")
{
Assert.Inconclusive("team not found");
}
else
{
Assert.AreEqual("success", response);
}
request = null;
}
[TestMethod, TestCategory("REST API")]
public void Samples_Teams_CreateTeam_Success()
{
// arrange
Samples request = new Samples(_configuration);
// act
string response = request.CreateTeam();
// assert
Assert.AreEqual("success", response);
request = null;
}
[TestMethod, TestCategory("REST API")]
public void Samples_Teams_UpdateTeam_Success()
{
// arrange
Samples request = new Samples(_configuration);
// act
string response = request.UpdateTeam();
// assert
if (response == "not found")
{
Assert.Inconclusive("team not found for update");
}
else
{
Assert.AreEqual("success", response);
}
request = null;
}
[TestMethod, TestCategory("REST API")]
public void Samples_Teams_DeleteTeam_Success()
{
// arrange
Samples request = new Samples(_configuration);
// act
string response = request.DeleteTeam();
// assert
Assert.AreEqual("success", response);
request = null;
}
}
}

Просмотреть файл

@ -0,0 +1,181 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
using System.Net;
using VstsRestApiSamples.ProjectsAndTeams;
using VstsRestApiSamples.ViewModels.ProjectsAndTeams;
namespace VstsRestApiSamples.Tests.ProjectsAndTeams
{
[TestClass]
public class ProjectsTest
{
private IConfiguration _configuration = new Configuration();
[TestInitialize]
public void TestInitialize()
{
InitHelper.GetConfiguration(_configuration);
}
[TestCleanup]
public void TestCleanup()
{
_configuration = null;
}
[TestMethod, TestCategory("REST API")]
public void ProjectsAndTeams_Projects_GetListOfProjects_Success()
{
// arrange
TeamProjects request = new TeamProjects(_configuration);
// act
var response = request.GetTeamProjects();
// assert
Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode);
request = null;
}
[TestMethod, TestCategory("REST API")]
public void ProjectsAndTeams_Projects_GetListOfProjectsByState_Success()
{
// arrange
TeamProjects request = new TeamProjects(_configuration);
// act
var response = request.GetTeamProjectsByState();
// assert
Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode);
request = null;
}
[TestMethod, TestCategory("REST API")]
public void ProjectsAndTeams_Projects_GetProject_Success()
{
// arrange
TeamProjects request = new TeamProjects(_configuration);
// act
var response = request.GetTeamProjectWithCapabilities(_configuration.Project);
// assert
Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode);
request = null;
}
[TestMethod, TestCategory("REST API")]
public void ProjectsAndTeams_Projects_CreateProject_Success()
{
// arrange
TeamProjects request = new TeamProjects(_configuration);
string projectName = System.Guid.NewGuid().ToString().ToLower().Substring(0, 30);
// act
var createResponse = request.CreateTeamProject(projectName);
// assert
Assert.AreEqual(HttpStatusCode.Accepted, createResponse.HttpStatusCode);
request = null;
}
[TestMethod, TestCategory("REST API")]
public void ProjectsAndTeams_Projects_CreateProjectWithOperation_Success()
{
// arrange
TeamProjects request = new TeamProjects(_configuration);
string projectName = System.Guid.NewGuid().ToString().ToLower().Substring(0, 30);
// act
var createResponse = request.CreateTeamProject(projectName);
var url = createResponse.url;
var operationResponse = request.GetOperation(url);
// assert
Assert.AreEqual(HttpStatusCode.Accepted, createResponse.HttpStatusCode);
Assert.AreEqual(HttpStatusCode.OK, operationResponse.HttpStatusCode);
request = null;
}
[TestMethod, TestCategory("REST API")]
public void ProjectsAndTeams_Projects_CreateAndRenameProject_Success()
{
// arrange
TeamProjects request = new TeamProjects(_configuration);
string projectName = System.Guid.NewGuid().ToString().ToLower().Substring(0, 30);
// act
var createResponse = request.CreateTeamProject(projectName);
//TODO: Instead of sleep, monitor the status
System.Threading.Thread.Sleep(5000);
var getResponse = request.GetTeamProjectWithCapabilities(projectName);
var projectId = getResponse.id;
var renameResponse = request.RenameTeamProject(projectId, "Art Vandelay Project");
// assert
Assert.AreEqual(HttpStatusCode.Accepted, createResponse.HttpStatusCode);
Assert.AreEqual(HttpStatusCode.Accepted, renameResponse.HttpStatusCode);
request = null;
}
[TestMethod, TestCategory("REST API")]
public void ProjectsAndTeams_Projects_CreatedAndChangeProjectDescription_Success()
{
// arrange
TeamProjects request = new TeamProjects(_configuration);
string projectName = System.Guid.NewGuid().ToString().ToLower().Substring(0, 30);
// act
var createResponse = request.CreateTeamProject(projectName);
//TODO: Instead of sleep, monitor the status
System.Threading.Thread.Sleep(5000);
var getResponse = request.GetTeamProjectWithCapabilities(projectName);
var projectId = getResponse.id;
var renameResponse = request.ChangeTeamProjectDescription(projectId, "New project description");
// assert
Assert.AreEqual(HttpStatusCode.Accepted, createResponse.HttpStatusCode);
Assert.AreEqual(HttpStatusCode.Accepted, renameResponse.HttpStatusCode);
request = null;
}
[TestMethod, TestCategory("REST API")]
public void ProjectsAndTeams_Projects_CreatedAndDeleteProject_Success()
{
// arrange
TeamProjects request = new TeamProjects(_configuration);
string projectName = System.Guid.NewGuid().ToString().ToLower().Substring(0, 30);
// act
var createResponse = request.CreateTeamProject(projectName);
//TODO: Instead of sleep, monitor the status ("online")
System.Threading.Thread.Sleep(5000);
var getResponse = request.GetTeamProjectWithCapabilities(projectName);
var projectId = getResponse.id;
var deleteResponse = request.DeleteTeamProject(projectId);
// assert
Assert.AreEqual(HttpStatusCode.Accepted, deleteResponse);
request = null;
}
}
}

Просмотреть файл

@ -0,0 +1,158 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
using System.Net;
using VstsRestApiSamples.ProjectsAndTeams;
using VstsRestApiSamples.ViewModels.ProjectsAndTeams;
namespace VstsRestApiSamples.Tests.ProjectsAndTeams
{
[TestClass]
public class TeamsTest
{
private IConfiguration _configuration = new Configuration();
[TestInitialize]
public void TestInitialize()
{
InitHelper.GetConfiguration(_configuration);
}
[TestCleanup]
public void TestCleanup()
{
_configuration = null;
}
[TestMethod, TestCategory("REST API")]
public void ProjectsAndTeams_Teams_GetListOfTeams_Success()
{
// arrange
Teams request = new Teams(_configuration);
// act
ListofTeamsResponse.Teams response = request.GetTeams(_configuration.Project);
// assert
if (response.HttpStatusCode == HttpStatusCode.NotFound)
{
Assert.Inconclusive("teams not found for project '" + _configuration.Project + "'");
}
else
{
Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode);
}
request = null;
}
[TestMethod, TestCategory("REST API")]
public void ProjectsAndTeams_Teams_GetTeam_Success()
{
// arrange
Teams request = new Teams(_configuration);
// act
GetTeamResponse.Team response = request.GetTeam(_configuration.Project, _configuration.Team);
// assert
if (response.HttpStatusCode == HttpStatusCode.NotFound)
{
Assert.Inconclusive("team '" + _configuration.Team + "' not found");
}
else
{
Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode);
}
request = null;
}
[TestMethod, TestCategory("REST API")]
public void ProjectsAndTeams_Teams_GetTeamMembers_Success()
{
// arrange
Teams request = new Teams(_configuration);
// act
GetTeamMembersResponse.Members response = request.GetTeamMembers(_configuration.Project, _configuration.Team);
// assert
if (response.HttpStatusCode == HttpStatusCode.NotFound)
{
Assert.Inconclusive("team '" + _configuration.Team + "' not found");
}
else
{
Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode);
}
request = null;
}
[TestMethod, TestCategory("REST API")]
public void ProjectsAndTeams_Teams_CreateTeam_Success()
{
// arrange
Teams request = new Teams(_configuration);
// act
GetTeamResponse.Team response = request.CreateTeam(_configuration.Project, "My Awesome Team");
// assert
if (response.HttpStatusCode == HttpStatusCode.NotFound)
{
Assert.Inconclusive("team '" + _configuration.Team + "' not found");
}
else
{
Assert.AreEqual(HttpStatusCode.Created, response.HttpStatusCode);
}
request = null;
}
[TestMethod, TestCategory("REST API")]
public void ProjectsAndTeams_Teams_UpdateTeam_Success()
{
// arrange
Teams request = new Teams(_configuration);
// act
GetTeamResponse.Team response = request.UpdateTeam(_configuration.Project, "My Awesome Team");
// assert
if (response.HttpStatusCode == HttpStatusCode.NotFound)
{
Assert.Inconclusive("team '" + _configuration.Team + "' not found");
}
else
{
Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode);
}
request = null;
}
[TestMethod, TestCategory("REST API")]
public void ProjectsAndTeams_Teams_DeleteTeam_Success()
{
// arrange
Teams request = new Teams(_configuration);
// act
string response = request.DeleteTeam(_configuration.Project, "My Awesome Team");
// assert
if (response == HttpStatusCode.NotFound.ToString())
{
Assert.Inconclusive("team '" + _configuration.Team + "' not found");
}
else
{
Assert.AreEqual(HttpStatusCode.NoContent.ToString(), response);
}
request = null;
}
}
}

Просмотреть файл

@ -36,7 +36,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<HintPath>..\packages\Newtonsoft.Json.9.0.2-beta1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
@ -64,18 +64,27 @@
<Compile Include="Build2\BuildTest.cs" />
<Compile Include="Configuration.cs" />
<Compile Include="GettingStarted\AuthenticationTest.cs" />
<Compile Include="Git\GitRepositoryTest.cs" />
<Compile Include="InitHelper.cs" />
<Compile Include="ProjectsAndTeams\TeamProjectsTests.cs" />
<Compile Include="ProjectsAndTeams\ProjectCollectionsTest.cs" />
<Compile Include="ProjectsAndTeams\ProcessesTest.cs" />
<Compile Include="ProjectsAndTeams\SamplesTest.cs" />
<Compile Include="ProjectsAndTeams\TeamsTest.cs" />
<Compile Include="WorkItemTracking\SamplesTest.cs" />
<Compile Include="WorkItemTracking\ClassificationNodesTest.cs" />
<Compile Include="WorkItemTracking\RecycleBinTest.cs" />
<Compile Include="WorkItemTracking\WIQLTest.cs" />
<Compile Include="WorkItemTracking\QueriesTest.cs" />
<Compile Include="WorkItemTracking\FieldsTest.cs" />
<Compile Include="WorkItemTracking\AttachmentsTest.cs" />
<Compile Include="WorkItemTracking\BatchTest.cs" />
<Compile Include="WorkItemTracking\ReportingTest.cs" />
<Compile Include="WorkItemTracking\WorkItemsTest.cs" />
<Compile Include="Work\ProcessConfiguration\ListsTest.cs" />
<Compile Include="Work\ProcessConfiguration\FieldsTest.cs" />
<Compile Include="Work\ListsTest.cs" />
<Compile Include="Work\FieldsTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Work\TeamSettingsTest.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config">
@ -95,6 +104,7 @@
<Name>VstsRestApiSamples</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup />
<Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
<ItemGroup>

Просмотреть файл

@ -1,8 +1,8 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using VstsRestApiSamples.Work.ProcessConfiguration;
using VstsRestApiSamples.Work;
using System.Net;
namespace VstsRestApiSamples.Tests.Work.ProcessConfiguration
namespace VstsRestApiSamples.Tests.Work
{
[TestClass]
public class FieldsTest

Просмотреть файл

@ -1,8 +1,8 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Net;
using VstsRestApiSamples.Work.ProcessConfiguration;
using VstsRestApiSamples.Work;
namespace VstsRestApiSamples.Tests.Work.ProcessConfiguration
namespace VstsRestApiSamples.Tests.Work
{
[TestClass]
public class ListTests

Просмотреть файл

@ -0,0 +1,42 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using VstsRestApiSamples.Work;
using VstsRestApiSamples.ViewModels.Work;
using System.Net;
namespace VstsRestApiSamples.Tests.Work
{
[TestClass]
public class TeamSettingsTest
{
private IConfiguration _configuration = new Configuration();
[TestInitialize]
public void TestInitialize()
{
InitHelper.GetConfiguration(_configuration);
}
[TestCleanup]
public void TestCleanup()
{
_configuration = null;
}
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_WorkItems_GetWorkItemsByIDs_Success()
{
// arrange
TeamSettings request = new TeamSettings(_configuration);
// act
GetTeamSettingsResponse.Settings response = request.GetTeamsSettings(_configuration.Project, _configuration.Team);
// assert
Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode);
request = null;
}
}
}

Просмотреть файл

@ -23,7 +23,7 @@ namespace VstsRestApiSamples.Tests.WorkItemTracking
}
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_WorkItems_DownloadAttachment_Success()
public void REST_WorkItemTracking_Attachments_DownloadAttachment_Success()
{
// arrange
string url = "";
@ -56,5 +56,34 @@ namespace VstsRestApiSamples.Tests.WorkItemTracking
}
}
}
[TestMethod, TestCategory("REST API")]
public void REST_WorkItemTracking_Attachments_UploadAttachmentBinaryFile_Success()
{
// arrange
string filePath = @"D:\Temp\test.jpg";
Attachments attachements = new Attachments(_configuration);
// act
var response = attachements.UploadAttachmentBinaryFile(@filePath);
//assert
Assert.AreEqual(HttpStatusCode.Created, response.HttpStatusCode);
}
[TestMethod, TestCategory("REST API")]
public void REST_WorkItemTracking_Attachments_UploadAttachmentTextFile_Success()
{
// arrange
string filePath = @"D:\Temp\test.txt";
Attachments attachements = new Attachments(_configuration);
// act
var response = attachements.UploadAttachmentTextFile(@filePath);
//assert
Assert.AreEqual(HttpStatusCode.Created, response.HttpStatusCode);
}
}
}

Просмотреть файл

@ -0,0 +1,278 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using VstsRestApiSamples.WorkItemTracking;
using VstsRestApiSamples.ViewModels.WorkItemTracking;
using System.Net;
namespace VstsRestApiSamples.Tests.WorkItemTracking
{
[TestClass]
public class ClassificationNodesTest
{
private IConfiguration _configuration = new Configuration();
[TestInitialize]
public void TestInitialize()
{
InitHelper.GetConfiguration(_configuration);
}
[TestCleanup]
public void TestCleanup()
{
_configuration = null;
}
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_Nodes_GetAreas_Success()
{
// arrange
ClassificationNodes request = new ClassificationNodes(_configuration);
// act
GetNodesResponse.Nodes response = request.GetAreas(_configuration.Project);
//assert
Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode);
request = null;
}
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_Nodes_GetIterations_Success()
{
// arrange
ClassificationNodes request = new ClassificationNodes(_configuration);
// act
GetNodesResponse.Nodes response = request.GetIterations(_configuration.Project);
//assert
Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode);
request = null;
}
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_Nodes_GetArea_Success()
{
// arrange
string path = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15);
ClassificationNodes request = new ClassificationNodes(_configuration);
// act
GetNodeResponse.Node createResponse = request.CreateArea(_configuration.Project, path);
GetNodesResponse.Nodes getResponse = request.GetArea(_configuration.Project, path);
//assert
Assert.AreEqual(HttpStatusCode.Created, createResponse.HttpStatusCode);
Assert.AreEqual(HttpStatusCode.OK, getResponse.HttpStatusCode);
request = null;
}
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_Nodes_GetIteration_Success()
{
// arrange
string path = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15);
ClassificationNodes request = new ClassificationNodes(_configuration);
// act
GetNodeResponse.Node createResponse = request.CreateIteration(_configuration.Project, path);
GetNodesResponse.Nodes getResponse = request.GetIteration(_configuration.Project, path);
//assert
Assert.AreEqual(HttpStatusCode.Created, createResponse.HttpStatusCode);
Assert.AreEqual(HttpStatusCode.OK, getResponse.HttpStatusCode);
request = null;
}
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_Nodes_CreateIteration_Success()
{
// arrange
ClassificationNodes request = new ClassificationNodes(_configuration);
string path = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15);
// act
GetNodeResponse.Node response = request.CreateIteration(_configuration.Project, path);
//assert
if (response.Message.Contains("VS402371: Classification node name " + path))
{
Assert.Inconclusive("Iteration '" + path + "' already exists");
}
else
{
Assert.AreEqual(HttpStatusCode.Created, response.HttpStatusCode);
}
request = null;
}
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_Nodes_CreateArea_Success()
{
// arrange
ClassificationNodes request = new ClassificationNodes(_configuration);
string path = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15);
// act
GetNodeResponse.Node response = request.CreateArea(_configuration.Project, path);
//assert
if (response.Message.Contains("VS402371:"))
{
Assert.Inconclusive("Area path '" + path + "' already exists");
}
else
{
Assert.AreEqual(HttpStatusCode.Created, response.HttpStatusCode);
}
request = null;
}
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_Nodes_UpdateIterationDates_Success()
{
// arrange
ClassificationNodes request = new ClassificationNodes(_configuration);
DateTime startDate = new DateTime(2016, 11, 29);
DateTime finishDate = new DateTime(2016, 12, 17);
string path = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15);
// act
GetNodeResponse.Node responseCreate = request.CreateIteration(_configuration.Project, path);
GetNodeResponse.Node responseUpdate = request.UpdateIterationDates(_configuration.Project, path, startDate, finishDate);
//assert
Assert.AreEqual(HttpStatusCode.Created, responseCreate.HttpStatusCode);
Assert.AreEqual(HttpStatusCode.OK, responseUpdate.HttpStatusCode);
request = null;
}
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_Nodes_RenameArea_Success()
{
// arrange
ClassificationNodes request = new ClassificationNodes(_configuration);
string path = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15);
string newName = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 10) + "-Rename";
// act
GetNodeResponse.Node responseCreate = request.CreateArea(_configuration.Project, path);
GetNodeResponse.Node responseUpdate = request.RenameArea(_configuration.Project, path, newName);
//assert
Assert.AreEqual(HttpStatusCode.Created, responseCreate.HttpStatusCode);
Assert.AreEqual(HttpStatusCode.OK, responseUpdate.HttpStatusCode);
request = null;
}
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_Nodes_RenameIteration_Success()
{
// arrange
ClassificationNodes request = new ClassificationNodes(_configuration);
string path = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15);
string newName = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 10) + "-Rename";
// act
GetNodeResponse.Node responseCreate = request.CreateIteration(_configuration.Project, path);
GetNodeResponse.Node responseUpdate = request.RenameIteration(_configuration.Project, path, newName);
//assert
Assert.AreEqual(HttpStatusCode.Created, responseCreate.HttpStatusCode);
Assert.AreEqual(HttpStatusCode.OK, responseUpdate.HttpStatusCode);
request = null;
}
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_Nodes_MoveIteration_Success()
{
// arrange
ClassificationNodes request = new ClassificationNodes(_configuration);
string parentIteration = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-PARENT";
string childIteration = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-child";
// act
GetNodeResponse.Node responseParent = request.CreateIteration(_configuration.Project, parentIteration);
GetNodeResponse.Node responseChild = request.CreateIteration(_configuration.Project, childIteration);
GetNodeResponse.Node responseMove = request.MoveIteration(_configuration.Project, parentIteration, responseChild.id);
//assert
Assert.AreEqual(HttpStatusCode.Created, responseParent.HttpStatusCode);
Assert.AreEqual(HttpStatusCode.Created, responseChild.HttpStatusCode);
Assert.AreEqual(HttpStatusCode.OK, responseMove.HttpStatusCode);
request = null;
}
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_Nodes_MoveArea_Success()
{
// arrange
ClassificationNodes request = new ClassificationNodes(_configuration);
string parent = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-PARENT";
string child = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-child";
// act
GetNodeResponse.Node responseParent = request.CreateArea(_configuration.Project, parent);
GetNodeResponse.Node responseChild = request.CreateArea(_configuration.Project, child);
GetNodeResponse.Node responseMove = request.MoveArea(_configuration.Project, parent, responseChild.id);
//assert
Assert.AreEqual(HttpStatusCode.Created, responseParent.HttpStatusCode);
Assert.AreEqual(HttpStatusCode.Created, responseChild.HttpStatusCode);
Assert.AreEqual(HttpStatusCode.OK, responseMove.HttpStatusCode);
request = null;
}
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_Nodes_DeleteArea_Success()
{
// arrange
ClassificationNodes request = new ClassificationNodes(_configuration);
string masterArea = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-MASTER";
string deleteArea = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-delete";
// act
GetNodeResponse.Node responseMaster = request.CreateArea(_configuration.Project, masterArea);
GetNodeResponse.Node responseDelete = request.CreateArea(_configuration.Project, deleteArea);
var responseMove = request.DeleteArea(_configuration.Project, deleteArea, responseMaster.id.ToString());
//assert
Assert.AreEqual(HttpStatusCode.Created, responseMaster.HttpStatusCode);
Assert.AreEqual(HttpStatusCode.Created, responseDelete.HttpStatusCode);
Assert.AreEqual(HttpStatusCode.NoContent, responseMove);
request = null;
}
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_Nodes_DeleteIteration_Success()
{
// arrange
ClassificationNodes request = new ClassificationNodes(_configuration);
string masterIteration = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-MASTER";
string deleteIteration = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-delete";
// act
GetNodeResponse.Node responseMaster = request.CreateIteration(_configuration.Project, masterIteration);
GetNodeResponse.Node responseDelete = request.CreateIteration(_configuration.Project, deleteIteration);
var responseMove = request.DeleteIteration(_configuration.Project, deleteIteration, responseMaster.id.ToString());
//assert
Assert.AreEqual(HttpStatusCode.Created, responseMaster.HttpStatusCode);
Assert.AreEqual(HttpStatusCode.Created, responseDelete.HttpStatusCode);
Assert.AreEqual(HttpStatusCode.NoContent, responseMove);
request = null;
}
}
}

Просмотреть файл

@ -22,7 +22,7 @@ namespace VstsRestApiSamples.Tests.WorkItemTracking
}
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_WorkItems_GetListOfWorkItemsByIDs_Success()
public void WorkItemTracking_Fields_GetListOfWorkItemFields_Success()
{
// arrange
Fields request = new Fields(_configuration);

Просмотреть файл

@ -30,7 +30,7 @@ namespace VstsRestApiSamples.Tests.WorkItemTracking
Queries request = new Queries(_configuration);
// act
ListofQueriesResponse.Queries response = request.GetListOfQueries(_configuration.Project);
GetQueriesResponse.Queries response = request.GetListOfQueries(_configuration.Project);
// assert
Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode);
@ -46,7 +46,7 @@ namespace VstsRestApiSamples.Tests.WorkItemTracking
string folderPath = "Shared%20Queries/Product%20Planning";
// act
ListofQueriesByFolderPath.Queries response = request.GetListOfQueriesByFolderPath(_configuration.Project, folderPath);
GetQueriesByFolderPath.Queries response = request.GetListOfQueriesByFolderPath(_configuration.Project, folderPath);
// assert
Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode);
@ -61,7 +61,7 @@ namespace VstsRestApiSamples.Tests.WorkItemTracking
Queries request = new Queries(_configuration);
// act
GetQueryResponse.Queries response = request.GetQueryById(_configuration.Project, _configuration.QueryId);
GetQueriesByIdResponse.Queries response = request.GetQueryById(_configuration.Project, _configuration.QueryId);
// assert
if (response.HttpStatusCode == HttpStatusCode.NotFound)
@ -83,7 +83,7 @@ namespace VstsRestApiSamples.Tests.WorkItemTracking
Queries request = new Queries(_configuration);
// act
GetQueryResponse.Queries response = request.GetQueryByPath(_configuration.Project, _configuration.Query);
GetQueriesByIdResponse.Queries response = request.GetQueryByPath(_configuration.Project, _configuration.Query);
// assert
if (response.HttpStatusCode == HttpStatusCode.NotFound)

Просмотреть файл

@ -0,0 +1,180 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using VstsRestApiSamples.WorkItemTracking;
using VstsRestApiSamples.ViewModels.WorkItemTracking;
using System.Net;
namespace VstsRestApiSamples.Tests.WorkItemTracking
{
[TestClass]
public class RecycleBinTest
{
private IConfiguration _configuration = new Configuration();
[TestInitialize]
public void TestInitialize()
{
InitHelper.GetConfiguration(_configuration);
}
[TestCleanup]
public void TestCleanup()
{
_configuration = null;
}
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_RecycleBin_GetDeletedItems_Success()
{
// arrange
RecycleBin request = new RecycleBin(_configuration);
// act
GetItemsFromRecycleBinResponse.WorkItems response = request.GetDeletedItems(_configuration.Project);
//assert
Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode);
request = null;
}
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_RecycleBin_GetDeletedItem_Success()
{
// arrange
WorkItems workItemsRequest = new WorkItems(_configuration);
RecycleBin recyclebinRequest = new RecycleBin(_configuration);
// act
WorkItemPatchResponse.WorkItem createResponse = workItemsRequest.CreateWorkItem(_configuration.Project);
WorkItemPatchResponse.WorkItem deleteResponse = workItemsRequest.DeleteWorkItem(createResponse.id.ToString());
GetItemFromRecycleBinResponse.WorkItem getDeletedItemResponse = recyclebinRequest.GetDeletedItem(_configuration.Project, createResponse.id.ToString());
//assert
Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode);
Assert.AreEqual(HttpStatusCode.OK, deleteResponse.HttpStatusCode);
Assert.AreEqual(HttpStatusCode.OK, getDeletedItemResponse.HttpStatusCode);
workItemsRequest = null;
recyclebinRequest = null;
}
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_RecycleBin_RestoreItem_Success()
{
// arrange
WorkItems workItemsRequest = new WorkItems(_configuration);
RecycleBin recyclebinRequest = new RecycleBin(_configuration);
// act
WorkItemPatchResponse.WorkItem createResponse = workItemsRequest.CreateWorkItem(_configuration.Project);
WorkItemPatchResponse.WorkItem deleteResponse = workItemsRequest.DeleteWorkItem(createResponse.id.ToString());
GetRestoredWorkItemResponse.WorkItem restoreResponse = recyclebinRequest.RestoreItem(createResponse.id.ToString());
////get restored item
GetWorkItemExpandAllResponse.WorkItem getRestoredItemResponse = workItemsRequest.GetWorkItem(createResponse.id.ToString());
//assert
Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode);
Assert.AreEqual(HttpStatusCode.OK, deleteResponse.HttpStatusCode);
Assert.AreEqual(HttpStatusCode.OK, restoreResponse.HttpStatusCode);
Assert.AreEqual(HttpStatusCode.OK, getRestoredItemResponse.HttpStatusCode);
workItemsRequest = null;
recyclebinRequest = null;
}
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_RecycleBin_RestoreMultipleItems_Success()
{
// arrange
WorkItems workItemsRequest = new WorkItems(_configuration);
RecycleBin recyclebinRequest = new RecycleBin(_configuration);
WorkItemPatchResponse.WorkItem createResponse;
string[] ids = new string[3];
// act
createResponse = workItemsRequest.CreateWorkItem(_configuration.Project);
ids[0] = createResponse.id.ToString();
createResponse = workItemsRequest.CreateWorkItem(_configuration.Project);
ids[1] = createResponse.id.ToString();
createResponse = workItemsRequest.CreateWorkItem(_configuration.Project);
ids[2] = createResponse.id.ToString();
foreach(var id in ids)
{
var deleteResponse = workItemsRequest.DeleteWorkItem(id);
}
var respond = recyclebinRequest.RestoreMultipleItems(ids);
//assert
Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode);
workItemsRequest = null;
recyclebinRequest = null;
}
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_RecycleBin_PermenentlyDeletedItem_Success()
{
// arrange
WorkItems workItemsRequest = new WorkItems(_configuration);
RecycleBin recyclebinRequest = new RecycleBin(_configuration);
// act
WorkItemPatchResponse.WorkItem createResponse = workItemsRequest.CreateWorkItem(_configuration.Project);
WorkItemPatchResponse.WorkItem deleteResponse = workItemsRequest.DeleteWorkItem(createResponse.id.ToString());
HttpStatusCode permDeleteResponse = recyclebinRequest.PermenentlyDeleteItem(createResponse.id.ToString());
////get delete item
GetWorkItemExpandAllResponse.WorkItem getDeletedWorkItem = workItemsRequest.GetWorkItem(createResponse.id.ToString());
//assert
Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode);
Assert.AreEqual(HttpStatusCode.OK, deleteResponse.HttpStatusCode);
Assert.AreEqual(HttpStatusCode.OK, permDeleteResponse);
Assert.AreEqual(HttpStatusCode.NoContent, getDeletedWorkItem.HttpStatusCode);
workItemsRequest = null;
recyclebinRequest = null;
}
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_RecycleBin_PermenentlyDeleteMultipleItems_Success()
{
// arrange
WorkItems workItemsRequest = new WorkItems(_configuration);
RecycleBin recyclebinRequest = new RecycleBin(_configuration);
WorkItemPatchResponse.WorkItem createResponse;
string[] ids = new string[3];
// act
createResponse = workItemsRequest.CreateWorkItem(_configuration.Project);
ids[0] = createResponse.id.ToString();
createResponse = workItemsRequest.CreateWorkItem(_configuration.Project);
ids[1] = createResponse.id.ToString();
createResponse = workItemsRequest.CreateWorkItem(_configuration.Project);
ids[2] = createResponse.id.ToString();
foreach (var id in ids)
{
var deleteResponse = workItemsRequest.DeleteWorkItem(id);
}
GetRestoreMultipleWorkItemsResponse.Items response = recyclebinRequest.PeremenentlyDeleteMultipleItems(ids);
//assert
Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode);
Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode);
workItemsRequest = null;
recyclebinRequest = null;
}
}
}

Просмотреть файл

@ -0,0 +1,86 @@
using System;
using System.Net;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using VstsRestApiSamples.WorkItemTracking;
using VstsRestApiSamples.ViewModels.WorkItemTracking;
namespace VstsRestApiSamples.Tests.WorkItemTracking
{
[TestClass]
public class ReportingTest
{
private IConfiguration _configuration = new Configuration();
[TestInitialize]
public void TestInitialize()
{
InitHelper.GetConfiguration(_configuration);
}
[TestCleanup]
public void TestCleanup()
{
_configuration = null;
}
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_Reporting_GetBatchOfWorkItemLinksByProjectAndDate_Success()
{
// arrange
Reporting request = new Reporting(_configuration);
// act
BatchOfWorkItemLinksResponse.WorkItemLinks response = request.GetBatchOfWorkItemLinks(_configuration.Project, new DateTime(2016, 3, 15));
// assert
Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode);
request = null;
}
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_Reporting_GetBatchOfWorkItemLinksForAll_Success()
{
// arrange
Reporting request = new Reporting(_configuration);
// act
BatchOfWorkItemLinksResponse.WorkItemLinks response = request.GetBatchOfWorkItemLinksAll();
// assert
Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode);
}
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_Reporting_GetBatchOfWorkItemRevisions_ByProjectAndDate_Success()
{
// arrange
Reporting request = new Reporting(_configuration);
// act
BatchOfWorkItemRevisionsResponse.WorkItemRevisions response = request.GetBatchOfWorkItemRevisionsByDate(_configuration.Project, new DateTime(2016, 4, 17));
// assert
Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode);
request = null;
response = null;
}
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_Reporting_GetBatchOfWorkItemRevisions_ForAll_Success()
{
// arrange
Reporting request = new Reporting(_configuration);
// act
BatchOfWorkItemRevisionsResponse.WorkItemRevisions response = request.GetBatchOfWorkItemRevisionsAll();
// assert
Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode);
request = null;
response = null;
}
}
}

Просмотреть файл

@ -111,6 +111,28 @@ namespace VstsRestApiSamples.Tests.WorkItemTracking
samples = null;
}
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_Samples_AddHyperLinkToBug_Success()
{
// arrange
Samples samples = new Samples(_configuration);
// act
var response = samples.AddHyperLinkToBug();
// assert
if (response.ToLower().Contains("relation already exists"))
{
Assert.Inconclusive("Link already exists on bug");
}
else
{
Assert.AreEqual("success", response);
}
samples = null;
}
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_Samples_AddAttachmentToBug_Success()
{
@ -120,8 +142,15 @@ namespace VstsRestApiSamples.Tests.WorkItemTracking
// act
var response = samples.AddAttachmentToBug();
// assert
Assert.AreEqual("success", response);
//assert
if (response.ToLower().Contains("file not found"))
{
Assert.Inconclusive(response);
}
else
{
Assert.AreEqual("success", response);
}
samples = null;
}
@ -140,5 +169,20 @@ namespace VstsRestApiSamples.Tests.WorkItemTracking
samples = null;
}
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_Samples_GetListOfWorkItemFields()
{
// arrange
Samples samples = new Samples(_configuration);
// act
var response = samples.GetListOfWorkItemFields("Title");
// assert
Assert.AreEqual("System.Title", response);
samples = null;
}
}
}

Просмотреть файл

@ -29,7 +29,7 @@ namespace VstsRestApiSamples.Tests.WorkItemTracking
WIQL request = new WIQL(_configuration);
// act
GetWorkItemsResponse.Results response = request.GetListOfWorkItems_ByQueryId(_configuration.Project, _configuration.QueryId);
GetWorkItemsWIQLResponse.Results response = request.GetListOfWorkItems_ByQueryId(_configuration.Project, _configuration.QueryId);
// assert
if (response.HttpStatusCode == HttpStatusCode.NotFound)
@ -51,7 +51,7 @@ namespace VstsRestApiSamples.Tests.WorkItemTracking
WIQL request = new WIQL(_configuration);
// act
GetWorkItemsResponse.Results response = request.GetListOfWorkItems_ByWiql(_configuration.Project);
GetWorkItemsWIQLResponse.Results response = request.GetListOfWorkItems_ByWiql(_configuration.Project);
// assert
if (response.HttpStatusCode == HttpStatusCode.NotFound)

Просмотреть файл

@ -3,6 +3,7 @@ using System.Net;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using VstsRestApiSamples.WorkItemTracking;
using VstsRestApiSamples.ViewModels.WorkItemTracking;
using System.IO;
namespace VstsRestApiSamples.Tests.WorkItemTracking
{
@ -24,13 +25,13 @@ namespace VstsRestApiSamples.Tests.WorkItemTracking
}
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_WorkItems_GetListOfWorkItemsByIDs_Success()
public void WorkItemTracking_WorkItems_GetWorkItemsByIDs_Success()
{
// arrange
WorkItems request = new WorkItems(_configuration);
// act
ListofWorkItemsResponse.WorkItems response = request.GetListOfWorkItems_ByIDs(_configuration.WorkItemIds);
GetWorkItemsResponse.WorkItems response = request.GetWorkItemsByIDs(_configuration.WorkItemIds);
// assert
if (response.HttpStatusCode == HttpStatusCode.NotFound)
@ -46,13 +47,13 @@ namespace VstsRestApiSamples.Tests.WorkItemTracking
}
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_WorkItems_GetListOfWorkItemsByIDs_WithSpecificFields_Success()
public void WorkItemTracking_WorkItems_GetWorkItemsWithSpecificFields_Success()
{
// arrange
WorkItems request = new WorkItems(_configuration);
// act
ListofWorkItemsResponse.WorkItems response = request.GetListOfWorkItems_ByIDsWithSpecificFields("2247, 2473");
GetWorkItemsResponse.WorkItems response = request.GetWorkItemsWithSpecificFields(_configuration.WorkItemIds);
// assert
Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode);
@ -61,13 +62,14 @@ namespace VstsRestApiSamples.Tests.WorkItemTracking
}
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_WorkItems_GetBatchOfWorkItemLinksByProjectAndDate_Success()
public void WorkItemTracking_WorkItems_GetWorkItemsAsOfDate_Success()
{
// arrange
WorkItems request = new WorkItems(_configuration);
DateTime asOfDate = DateTime.Now.AddDays(-90);
// act
BatchOfWorkItemLinksResponse.WorkItemLinks response = request.GetBatchOfWorkItemLinks(_configuration.Project, new DateTime(2016, 3, 15));
GetWorkItemsResponse.WorkItems response = request.GetWorkItemsAsOfDate(_configuration.WorkItemIds, asOfDate);
// assert
Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode);
@ -76,13 +78,123 @@ namespace VstsRestApiSamples.Tests.WorkItemTracking
}
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_WorkItems_GetWorkItemExpandAll_Success()
public void WorkItemTracking_WorkItems_GetWorkItemsWithLinksAndAttachments_Success()
{
// arrange
WorkItems request = new WorkItems(_configuration);
// act
var response = request.GetWorkItem("2583");
GetWorkItemsWithLinksAndAttachmentsResponse.WorkItems response = request.GetWorkItemsWithLinksAndAttachments(_configuration.WorkItemIds);
// assert
if (response.HttpStatusCode == HttpStatusCode.NotFound)
{
Assert.Inconclusive("work items '" + _configuration.WorkItemIds + "' not found");
}
else
{
Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode);
}
request = null;
}
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_WorkItems_GetWorkItem_Success()
{
// arrange
WorkItems request = new WorkItems(_configuration);
// act
var response = request.GetWorkItem(_configuration.WorkItemId);
// assert
if (response.HttpStatusCode == HttpStatusCode.NotFound)
{
Assert.Inconclusive("work item '" + _configuration.WorkItemId + "' not found");
}
else
{
Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode);
}
request = null;
}
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_WorkItems_GetWorkItemWithLinksAndAttachments_Success()
{
// arrange
WorkItems request = new WorkItems(_configuration);
// act
var response = request.GetWorkItemWithLinksAndAttachments(_configuration.WorkItemId);
// assert
if (response.HttpStatusCode == HttpStatusCode.NotFound)
{
Assert.Inconclusive("work item '" + _configuration.WorkItemId + "' not found");
}
else
{
Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode);
}
request = null;
}
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_WorkItems_GetWorkItemFullyExpanded_Success()
{
// arrange
WorkItems request = new WorkItems(_configuration);
// act
var response = request.GetWorkItemFullyExpanded(_configuration.WorkItemId);
// assert
if (response.HttpStatusCode == HttpStatusCode.NotFound)
{
Assert.Inconclusive("work item '" + _configuration.WorkItemId + "' not found");
}
else
{
Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode);
}
request = null;
}
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_WorkItems_GetDefaultValues_Success()
{
// arrange
WorkItems request = new WorkItems(_configuration);
// act
var response = request.GetDefaultValues("Task", _configuration.Project);
// assert
if (response.HttpStatusCode == HttpStatusCode.NotFound)
{
Assert.Inconclusive("work item type not found");
}
else
{
Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode);
}
request = null;
}
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_WorkItems_CreateWorkItem_Success()
{
// arrange
WorkItems request = new WorkItems(_configuration);
// act
WorkItemPatchResponse.WorkItem response = request.CreateWorkItem(_configuration.Project);
// assert
Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode);
@ -91,58 +203,13 @@ namespace VstsRestApiSamples.Tests.WorkItemTracking
}
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_WorkItems_Reporting_GetBatchOfWorkItemLinksForAll_Success()
public void WorkItemTracking_WorkItems_CreateWorkItemWithWorkItemLink_Success()
{
// arrange
WorkItems request = new WorkItems(_configuration);
// act
BatchOfWorkItemLinksResponse.WorkItemLinks response = request.GetBatchOfWorkItemLinksAll();
// assert
Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode);
}
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_WorkItems_Reporting_GetBatchOfWorkItemRevisions_ByProjectAndDate_Success()
{
// arrange
WorkItems request = new WorkItems(_configuration);
// act
BatchOfWorkItemRevisionsResponse.WorkItemRevisions response = request.GetBatchOfWorkItemRevisionsByDate(_configuration.Project, new DateTime(2016, 4, 17));
// assert
Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode);
request = null;
response = null;
}
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_WorkItems_Reporting_GetBatchOfWorkItemRevisions_ForAll_Success()
{
// arrange
WorkItems request = new WorkItems(_configuration);
// act
BatchOfWorkItemRevisionsResponse.WorkItemRevisions response = request.GetBatchOfWorkItemRevisionsAll();
// assert
Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode);
request = null;
response = null;
}
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_WorkItems_CreateWorkItemWithByPassRules_Success()
{
// arrange
WorkItems request = new WorkItems(_configuration);
// act
WorkItemPatchResponse.WorkItem response = request.CreateWorkItemUsingByPassRules(_configuration.Project);
WorkItemPatchResponse.WorkItem response = request.CreateWorkItemWithWorkItemLink(_configuration.Project, _configuration.WorkItemId);
// assert
Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode);
@ -151,13 +218,13 @@ namespace VstsRestApiSamples.Tests.WorkItemTracking
}
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_WorkItems_CreateBug_Success()
public void WorkItemTracking_WorkItems_CreateWorkItemByPassingRules_Success()
{
// arrange
WorkItems request = new WorkItems(_configuration);
// act
WorkItemPatchResponse.WorkItem response = request.CreateBug(_configuration.Project);
WorkItemPatchResponse.WorkItem response = request.CreateWorkItemByPassingRules(_configuration.Project);
// assert
Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode);
@ -166,88 +233,24 @@ namespace VstsRestApiSamples.Tests.WorkItemTracking
}
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_WorkItems_UpdateWorkItem_Success()
public void WorkItemTracking_WorkItems_UpdateWorkItemUpdateField_Success()
{
// arrange
WorkItems request = new WorkItems(_configuration);
// act
WorkItemPatchResponse.WorkItem response = request.UpdateWorkItemFields(_configuration.WorkItemId);
WorkItemPatchResponse.WorkItem createResponse = request.CreateWorkItem(_configuration.Project);
WorkItemPatchResponse.WorkItem updateResponse = request.UpdateWorkItemUpdateField(createResponse.id.ToString());
// assert
Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode);
Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode);
Assert.AreEqual(HttpStatusCode.OK, updateResponse.HttpStatusCode);
request = null;
}
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_WorkItems_UpdateWorkItemWithByPassRules_Success()
{
// arrange
WorkItems request = new WorkItems(_configuration);
// act
WorkItemPatchResponse.WorkItem response = request.UpdateWorkItemFieldsWithByPassRules(_configuration.WorkItemId);
// assert
Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode);
request = null;
}
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_WorkItems_AddLink_Success()
{
// arrange
WorkItems request = new WorkItems(_configuration);
string[] arr = _configuration.WorkItemIds.Split(',');
// act
WorkItemPatchResponse.WorkItem response = request.AddLink(arr[0].ToString(), arr[1].ToString());
// assert
Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode);
request = null;
}
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_WorkItems_UploadAttachment_Success()
{
// arrange
WorkItems workItemsRequest = new WorkItems(_configuration);
Attachments attachmentsRequest = new Attachments(_configuration);
// act
var attachmentReference = attachmentsRequest.UploadAttachment(_configuration.FilePath);
var response = workItemsRequest.AddAttachment(_configuration.WorkItemId, attachmentReference.url);
// assert
Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode);
workItemsRequest = null;
attachmentsRequest = null;
}
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_WorkItems_AddAndUpdateWorkItemTags_Success()
{
// arrange
WorkItems request = new WorkItems(_configuration);
// act
WorkItemPatchResponse.WorkItem result = request.AddWorkItemTags(_configuration.WorkItemId, "Technical Debt; Spike Needed");
// assert
Assert.AreEqual(HttpStatusCode.OK, result.HttpStatusCode);
request = null;
}
[TestMethod, TestCategory("REST API"), Ignore]
public void WorkItemTracking_WorkItems_MoveWorkItem_Success()
public void WorkItemTracking_WorkItems_UpdateWorkItemMoveWorkItem_Success()
{
// arrange
WorkItems request = new WorkItems(_configuration);
@ -255,29 +258,221 @@ namespace VstsRestApiSamples.Tests.WorkItemTracking
string iterationPath = _configuration.MoveToProject; // use project name for root iteration path
// act
WorkItemPatchResponse.WorkItem response = request.MoveWorkItem(_configuration.WorkItemId, _configuration.MoveToProject, areaPath, iterationPath);
WorkItemPatchResponse.WorkItem response = request.UpdateWorkItemMoveWorkItem(_configuration.WorkItemId, _configuration.MoveToProject, areaPath, iterationPath);
// assert
Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode);
Assert.AreEqual(response.fields.SystemAreaPath, areaPath);
Assert.AreEqual(response.fields.SystemIterationPath, iterationPath);
// move back
WorkItemPatchResponse.WorkItem movebackResponse = request.MoveWorkItem(_configuration.WorkItemId, _configuration.Project, _configuration.Project, _configuration.Project);
Assert.AreEqual(HttpStatusCode.OK, movebackResponse.HttpStatusCode);
request = null;
}
[TestMethod, TestCategory("REST API"), Ignore]
public void WorkItemTracking_WorkItems_ChangeType_Success()
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_WorkItems_UpdateWorkItemChangeWorkItemType_Success()
{
// arrange
WorkItems request = new WorkItems(_configuration);
// act
WorkItemPatchResponse.WorkItem response = request.ChangeType(_configuration.WorkItemId, "Bug");
var someme = response.ToString();
///create a task then change it to a user story
WorkItemPatchResponse.WorkItem createResponse = request.CreateWorkItem(_configuration.Project);
WorkItemPatchResponse.WorkItem changeResponse = request.UpdateWorkItemChangeWorkItemType(createResponse.id.ToString());
// assert
Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode);
Assert.AreEqual(HttpStatusCode.OK, changeResponse.HttpStatusCode);
request = null;
}
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_WorkItems_UpdateWorkItemAddTag_Success()
{
// arrange
WorkItems request = new WorkItems(_configuration);
// act
WorkItemPatchResponse.WorkItem result = request.UpdateWorkItemAddTag(_configuration.WorkItemId);
// assert
Assert.AreEqual(HttpStatusCode.OK, result.HttpStatusCode);
request = null;
}
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_WorkItems_UpdateWorkItemAddLink_Success()
{
// arrange
WorkItems request = new WorkItems(_configuration);
// act
WorkItemPatchResponse.WorkItem createResponse = request.CreateWorkItem(_configuration.Project);
WorkItemPatchResponse.WorkItem updateResponse = request.UpdateWorkItemAddLink(createResponse.id.ToString(), _configuration.WorkItemId);
// assert
Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode);
Assert.AreEqual(HttpStatusCode.OK, updateResponse.HttpStatusCode);
request = null;
}
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_WorkItems_UpdateWorkItemUpdateLink_Success()
{
// arrange
WorkItems request = new WorkItems(_configuration);
// act
WorkItemPatchResponse.WorkItem createResponse = request.CreateWorkItem(_configuration.Project);
WorkItemPatchResponse.WorkItem addLinkResponse = request.UpdateWorkItemAddLink(createResponse.id.ToString(), _configuration.WorkItemId);
WorkItemPatchResponse.WorkItem updateLinkResponse = request.UpdateWorkItemUpdateLink(createResponse.id.ToString(), _configuration.WorkItemId);
// assert
Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode);
Assert.AreEqual(HttpStatusCode.OK, addLinkResponse.HttpStatusCode);
Assert.AreEqual(HttpStatusCode.OK, updateLinkResponse.HttpStatusCode);
request = null;
}
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_WorkItems_UpdateWorkItemRemoveLink_Success()
{
// arrange
WorkItems request = new WorkItems(_configuration);
// act
WorkItemPatchResponse.WorkItem createResponse = request.CreateWorkItem(_configuration.Project);
WorkItemPatchResponse.WorkItem addLinkResponse = request.UpdateWorkItemAddLink(createResponse.id.ToString(), _configuration.WorkItemId);
WorkItemPatchResponse.WorkItem removeLinkResponse = request.UpdateWorkItemRemoveLink(createResponse.id.ToString());
// assert
Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode);
Assert.AreEqual(HttpStatusCode.OK, addLinkResponse.HttpStatusCode);
Assert.AreEqual(HttpStatusCode.OK, removeLinkResponse.HttpStatusCode);
request = null;
}
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_WorkItems_UpdateWorkItemAddAttachment_Success()
{
// arrange
if (! File.Exists(@_configuration.FilePath))
{
Assert.Inconclusive("file not found: " + @_configuration.FilePath);
}
WorkItems request = new WorkItems(_configuration);
Attachments attachmentsRequest = new Attachments(_configuration);
// act
//upload attachment
var attachmentReference = attachmentsRequest.UploadAttachmentBinaryFile(_configuration.FilePath);
//create work item then add attachment to that work item
WorkItemPatchResponse.WorkItem createResponse = request.CreateWorkItem(_configuration.Project);
WorkItemPatchResponse.WorkItem attachmentResponse = request.UpdateWorkItemAddAttachment(createResponse.id.ToString(), attachmentReference.url);
// assert
Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode);
Assert.AreEqual(HttpStatusCode.OK, attachmentResponse.HttpStatusCode);
request = null;
attachmentsRequest = null;
}
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_WorkItems_UpdateWorkItemRemoveAttachment_Success()
{
// arrange
WorkItems request = new WorkItems(_configuration);
Attachments attachmentsRequest = new Attachments(_configuration);
// act
//upload attachment
var attachmentReference = attachmentsRequest.UploadAttachmentBinaryFile(_configuration.FilePath);
//create work item then add attachment to that work item
WorkItemPatchResponse.WorkItem createResponse = request.CreateWorkItem(_configuration.Project);
WorkItemPatchResponse.WorkItem addAttachmentResponse = request.UpdateWorkItemAddAttachment(createResponse.id.ToString(), attachmentReference.url);
WorkItemPatchResponse.WorkItem removeAttachmentResponse = request.UpdateWorkItemRemoveAttachment(createResponse.id.ToString());
// assert
Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode);
Assert.AreEqual(HttpStatusCode.OK, addAttachmentResponse.HttpStatusCode);
Assert.AreEqual(HttpStatusCode.OK, removeAttachmentResponse.HttpStatusCode);
request = null;
attachmentsRequest = null;
}
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_WorkItems_UpdateWorkItemAddHyperLink_Success()
{
// arrange
WorkItems request = new WorkItems(_configuration);
// act
WorkItemPatchResponse.WorkItem createResponse = request.CreateWorkItem(_configuration.Project);
WorkItemPatchResponse.WorkItem addHyperLinkResponse = request.UpdateWorkItemAddHyperLink(createResponse.id.ToString());
// assert
Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode);
Assert.AreEqual(HttpStatusCode.OK, addHyperLinkResponse.HttpStatusCode);
request = null;
}
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_WorkItems_DeleteWorkItem_Success()
{
// arrange
WorkItems request = new WorkItems(_configuration);
// act
WorkItemPatchResponse.WorkItem createResponse = request.CreateWorkItem(_configuration.Project);
var deleteResponse = request.DeleteWorkItem(createResponse.id.ToString());
// assert
Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode);
Assert.AreEqual(HttpStatusCode.OK, deleteResponse.HttpStatusCode);
request = null;
}
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_WorkItems_AddCommitLink_Success()
{
// arrange
WorkItems request = new WorkItems(_configuration);
// act
WorkItemPatchResponse.WorkItem response = request.UpdateWorkItemAddCommitLink("3045");
// assert
if (response.Message.ToLower().Contains("relation already exists"))
{
Assert.Inconclusive("Commit link already exists on bug");
}
else
{
Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode);
}
request = null;
}
[TestMethod, TestCategory("REST API")]
public void WorkItemTracking_WorkItems_UpdateWorkItemByPassRules_Success()
{
// arrange
WorkItems request = new WorkItems(_configuration);
// act
WorkItemPatchResponse.WorkItem response = request.UpdateWorkItemByPassingRules(_configuration.WorkItemId);
// assert
Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode);

Просмотреть файл

@ -2,8 +2,10 @@
<configuration>
<appSettings>
<add key="appsetting.uri" value="" />
<add key="appsetting.collectionid" value="" />
<add key="appsetting.pat" value="" />
<add key="appsetting.project" value="" />
<add key="appsetting.team" value="" />
<add key="appsetting.movetoproject" value="" />
<add key="appsetting.query" value="Shared Queries/Current Iteration/Open User Stories" />
<add key="appsetting.identity" value="" />
@ -13,6 +15,7 @@
<add key="appsetting.picklistid" value="" />
<add key="appsetting.queryid" value="" />
<add key="appsetting.filepath" value="" />
<add key="appsetting.git.repositoryid" value="" />
</appSettings>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

Просмотреть файл

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net452" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net452" />

Просмотреть файл

@ -1,4 +1,3 @@

namespace VstsRestApiSamples
{
public class Configuration : IConfiguration
@ -6,8 +5,10 @@ namespace VstsRestApiSamples
public string AccountName { get; set; }
public string ApplicationId { get; set; }
public string UriString { get { return string.Format("https://{0}.visualstudio.com", AccountName); } }
public string CollectionId { get; set; }
public string PersonalAccessToken { get; set; }
public string Project { get; set; }
public string Team { get; set; }
public string MoveToProject { get; set; }
public string Query { get; set; }
public string Identity { get; set; }
@ -17,5 +18,6 @@ namespace VstsRestApiSamples
public string PickListId { get; set; }
public string QueryId { get; set; }
public string FilePath { get; set; }
public string GitRepositoryId { get; set; }
}
}

Просмотреть файл

@ -0,0 +1,115 @@
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using VstsRestApiSamples.ViewModels.Git;
namespace VstsRestApiSamples.Git
{
public class GitRepository
{
readonly IConfiguration _configuration;
readonly string _credentials;
public GitRepository(IConfiguration configuration)
{
_configuration = configuration;
_credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken)));
}
public GetAllRepositoriesResponse.Repositories GetAllRepositories()
{
GetAllRepositoriesResponse.Repositories viewModel = new GetAllRepositoriesResponse.Repositories();
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(_configuration.UriString);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);
HttpResponseMessage response = client.GetAsync("/_apis/git/repositories/?api-version=2.0").Result;
if (response.IsSuccessStatusCode)
{
viewModel = response.Content.ReadAsAsync<GetAllRepositoriesResponse.Repositories>().Result;
}
viewModel.HttpStatusCode = response.StatusCode;
return viewModel;
}
}
public GetRepositoryByIdResponse.Repository GetRepositoryById(string repositoryId)
{
GetRepositoryByIdResponse.Repository viewModel = new GetRepositoryByIdResponse.Repository();
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(_configuration.UriString);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);
HttpResponseMessage response = client.GetAsync("/_apis/git/repositories/" + repositoryId + "?api-version=2.0").Result;
if (response.IsSuccessStatusCode)
{
viewModel = response.Content.ReadAsAsync<GetRepositoryByIdResponse.Repository>().Result;
}
viewModel.HttpStatusCode = response.StatusCode;
return viewModel;
}
}
public GetFolderAndChildrenResponse.FolderAndChildren GetFolderAndChildren(string repositoryId, string scopePath)
{
GetFolderAndChildrenResponse.FolderAndChildren viewModel = new GetFolderAndChildrenResponse.FolderAndChildren();
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(_configuration.UriString);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);
HttpResponseMessage response = client.GetAsync("/_apis/git/repositories/" + repositoryId + "/items?scopePath=" + scopePath + "&recursionLevel=Full&includeContentMetadata=true&api-version=2.0").Result;
if (response.IsSuccessStatusCode)
{
viewModel = response.Content.ReadAsAsync<GetFolderAndChildrenResponse.FolderAndChildren>().Result;
}
viewModel.HttpStatusCode = response.StatusCode;
return viewModel;
}
}
public GetCommitsByRepositoryIdResponse.Commits GetCommitsByRepositoryId(string repositoryId)
{
GetCommitsByRepositoryIdResponse.Commits viewModel = new GetCommitsByRepositoryIdResponse.Commits();
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(_configuration.UriString);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);
HttpResponseMessage response = client.GetAsync("/_apis/git/repositories/" + repositoryId + "/commits?api-version=2.0").Result;
if (response.IsSuccessStatusCode)
{
viewModel = response.Content.ReadAsAsync<GetCommitsByRepositoryIdResponse.Commits>().Result;
}
viewModel.HttpStatusCode = response.StatusCode;
return viewModel;
}
}
}
}

Просмотреть файл

@ -1,4 +1,3 @@

namespace VstsRestApiSamples
{
public interface IConfiguration
@ -8,8 +7,10 @@ namespace VstsRestApiSamples
// Requirements: Application must have permissions to access the VSTS Resource
// Since this is currently not possible through the UX, using the VS client AppId
string ApplicationId { get; set; }
string CollectionId { get; set; }
string PersonalAccessToken { get; set; }
string Project { get; set; }
string Team { get; set; }
string MoveToProject { get; set; }
string UriString { get; }
string Query { get; set; }
@ -20,5 +21,6 @@ namespace VstsRestApiSamples
string PickListId { get; set; }
string QueryId { get; set; }
string FilePath { get; set; }
string GitRepositoryId { get; set; }
}
}

Просмотреть файл

@ -20,7 +20,7 @@ namespace VstsRestApiSamples.ProjectsAndTeams
// / get list of all processes
// / </summary>
// / <returns>ListofProcessesResponse.Processes</returns>
public ListofProcessesResponse.Projects GetListOfProcesses()
public ListofProcessesResponse.Projects GetProcesses()
{
ListofProcessesResponse.Projects viewModel = new ListofProcessesResponse.Projects();

Просмотреть файл

@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using VstsRestApiSamples.ViewModels.ProjectsAndTeams;
namespace VstsRestApiSamples.ProjectsAndTeams
{
public class ProjectCollections
{
readonly IConfiguration _configuration;
readonly string _credentials;
public ProjectCollections(IConfiguration configuration)
{
_configuration = configuration;
_credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken)));
}
public GetProjectCollectionResponse.ProjectCollection GetProjectCollection(string id)
{
GetProjectCollectionResponse.ProjectCollection viewModel = new GetProjectCollectionResponse.ProjectCollection();
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(_configuration.UriString);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);
HttpResponseMessage response = client.GetAsync("_apis/projectCollections/" + id + "?api-version=2.2").Result;
if (response.IsSuccessStatusCode)
{
viewModel = response.Content.ReadAsAsync<GetProjectCollectionResponse.ProjectCollection>().Result;
}
viewModel.HttpStatusCode = response.StatusCode;
return viewModel;
}
}
}
}

Просмотреть файл

@ -0,0 +1,231 @@
using Newtonsoft.Json;
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
namespace VstsRestApiSamples.ProjectsAndTeams
{
public class Samples
{
readonly IConfiguration _configuration;
readonly string _credentials;
public Samples(IConfiguration configuration)
{
_configuration = configuration;
_credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken)));
}
public string GetTeams()
{
var project = _configuration.Project;
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(_configuration.UriString);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);
HttpResponseMessage response = client.GetAsync("_apis/projects/" + project + "/teams?api-version=2.2").Result;
if (response.IsSuccessStatusCode)
{
var teams = response.Content.ReadAsAsync<WebApiTeams>().Result;
return "success";
}
if (response.StatusCode == System.Net.HttpStatusCode.NotFound)
{
return "not found";
}
return "failed";
}
}
public string GetTeam()
{
var project = _configuration.Project;
var team = _configuration.Team;
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(_configuration.UriString);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);
HttpResponseMessage response = client.GetAsync("_apis/projects/" + project + "/teams/" + team + "?api-version=2.2").Result;
if (response.IsSuccessStatusCode)
{
var teams = response.Content.ReadAsAsync<WebApiTeams>().Result;
return "success";
}
if (response.StatusCode == System.Net.HttpStatusCode.NotFound)
{
return "not found";
}
return "failed";
}
}
public string GetTeamMembers()
{
var project = _configuration.Project;
var team = _configuration.Team;
Members members;
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(_configuration.UriString);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);
HttpResponseMessage response = client.GetAsync("_apis/projects/" + project + "/teams/" + team + "/members?api-version=2.2").Result;
if (response.IsSuccessStatusCode)
{
members = response.Content.ReadAsAsync<Members>().Result;
return "success";
}
if (response.StatusCode == System.Net.HttpStatusCode.NotFound)
{
return "not found";
}
return "failed";
}
}
public string CreateTeam()
{
var project = _configuration.Project;
Object teamData = new { name = "My new team" };
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);
// serialize the fields array into a json string
var patchValue = new StringContent(JsonConvert.SerializeObject(teamData), Encoding.UTF8, "application/json"); // mediaType needs to be application/json-patch+json for a patch call
var method = new HttpMethod("POST");
var request = new HttpRequestMessage(method, _configuration.UriString + "/_apis/projects/" + project + "/teams?api-version=2.2") { Content = patchValue };
var response = client.SendAsync(request).Result;
if (response.IsSuccessStatusCode)
{
WebApiTeam teamResponse = response.Content.ReadAsAsync<WebApiTeam>().Result;
return "success";
}
return "failed";
}
}
public string UpdateTeam()
{
var project = _configuration.Project;
Object team = new { name = "My new team", description = "my teams awesome description" };
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);
// serialize the fields array into a json string
var patchValue = new StringContent(JsonConvert.SerializeObject(team), Encoding.UTF8, "application/json"); // mediaType needs to be application/json-patch+json for a patch call
var method = new HttpMethod("PATCH");
var request = new HttpRequestMessage(method, _configuration.UriString + "/_apis/projects/" + project + "/teams/My%20new%20team?api-version=2.2") { Content = patchValue };
var response = client.SendAsync(request).Result;
if (response.IsSuccessStatusCode)
{
WebApiTeam teamResponse = response.Content.ReadAsAsync<WebApiTeam>().Result;
return "success";
}
if (response.StatusCode == System.Net.HttpStatusCode.NotFound)
{
return "not found";
}
return "failed";
}
}
public string DeleteTeam()
{
var project = _configuration.Project;
var team = "My new team";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);
var method = new HttpMethod("DELETE");
var request = new HttpRequestMessage(method, _configuration.UriString + "/_apis/projects/" + project + "/teams/" + team + "?api-version=2.2");
var response = client.SendAsync(request).Result;
if (response.IsSuccessStatusCode)
{
return "success";
}
else
{
return "failed";
}
}
}
public string CreateTeamsByAreaPath()
{
return "failed";
}
}
public class WebApiTeams
{
public WebApiTeam[] value { get; set; }
public int count { get; set; }
}
public class WebApiTeam
{
public string id { get; set; }
public string name { get; set; }
public string url { get; set; }
public string description { get; set; }
public string identityUrl { get; set; }
}
public class Members
{
public Member[] value { get; set; }
public int count { get; set; }
}
public class Member
{
public string id { get; set; }
public string displayName { get; set; }
public string uniqueName { get; set; }
public string url { get; set; }
public string imageUrl { get; set; }
}
}

Просмотреть файл

@ -0,0 +1,288 @@
using System;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using Newtonsoft.Json;
using VstsRestApiSamples.ViewModels.ProjectsAndTeams;
namespace VstsRestApiSamples.ProjectsAndTeams
{
public class TeamProjects
{
readonly IConfiguration _configuration;
readonly string _credentials;
public TeamProjects(IConfiguration configuration)
{
_configuration = configuration;
_credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken)));
}
public ListofProjectsResponse.Projects GetTeamProjects()
{
// create a viewmodel that is a class that represents the returned json response
ListofProjectsResponse.Projects viewModel = new ListofProjectsResponse.Projects();
// use the httpclient
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(_configuration.UriString);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);
// connect to the REST endpoint
HttpResponseMessage response = client.GetAsync("_apis/projects?api-version=2.2").Result;
// check to see if we have a succesfull respond
if (response.IsSuccessStatusCode)
{
// set the viewmodel from the content in the response
viewModel = response.Content.ReadAsAsync<ListofProjectsResponse.Projects>().Result;
}
viewModel.HttpStatusCode = response.StatusCode;
return viewModel;
}
}
public ListofProjectsResponse.Projects GetTeamProjectsByState()
{
// create a viewmodel that is a class that represents the returned json response
ListofProjectsResponse.Projects viewModel = new ListofProjectsResponse.Projects();
// use the httpclient
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(_configuration.UriString);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);
// connect to the REST endpoint
HttpResponseMessage response = client.GetAsync("_apis/projects?stateFilter=All&api-version=2.2").Result;
// check to see if we have a succesfull respond
if (response.IsSuccessStatusCode)
{
// set the viewmodel from the content in the response
viewModel = response.Content.ReadAsAsync<ListofProjectsResponse.Projects>().Result;
}
viewModel.HttpStatusCode = response.StatusCode;
return viewModel;
}
}
public GetProjectResponse.Project GetTeamProjectWithCapabilities(string name)
{
// create a viewmodel that is a class that represents the returned json response
GetProjectResponse.Project viewModel = new GetProjectResponse.Project();
// use the httpclient
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(_configuration.UriString);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);
// connect to the REST endpoint
HttpResponseMessage response = client.GetAsync("_apis/projects/" + name + "?includeCapabilities=true&api-version=2.2").Result;
// check to see if we have a succesfull respond
if (response.IsSuccessStatusCode)
{
// set the viewmodel from the content in the response
viewModel = response.Content.ReadAsAsync<GetProjectResponse.Project>().Result;
}
viewModel.HttpStatusCode = response.StatusCode;
return viewModel;
}
}
public GetOperationResponse.Operation CreateTeamProject(string name)
{
GetOperationResponse.Operation operation = new GetOperationResponse.Operation();
Object teamProject = new
{
name = name,
description = "VanDelay Industries travel app",
capabilities = new
{
versioncontrol = new
{
sourceControlType = "Git"
},
processTemplate = new
{
templateTypeId = "6b724908-ef14-45cf-84f8-768b5384da45"
}
}
};
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);
// serialize the fields array into a json string
var patchValue = new StringContent(JsonConvert.SerializeObject(teamProject), Encoding.UTF8, "application/json");
var method = new HttpMethod("POST");
var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/projects?api-version=2.2") { Content = patchValue };
var response = client.SendAsync(request).Result;
if (response.IsSuccessStatusCode)
{
operation = response.Content.ReadAsAsync<GetOperationResponse.Operation>().Result;
}
else
{
dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync<dynamic>();
Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result;
operation.Message = msg.ToString();
}
operation.HttpStatusCode = response.StatusCode;
return operation;
}
}
public GetOperationResponse.Operation GetOperation(string url)
{
// create a viewmodel that is a class that represents the returned json response
GetOperationResponse.Operation viewModel = new GetOperationResponse.Operation();
// use the httpclient
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(_configuration.UriString);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);
// connect to the REST endpoint
HttpResponseMessage response = client.GetAsync(url).Result;
// check to see if we have a succesfull respond
if (response.IsSuccessStatusCode)
{
// set the viewmodel from the content in the response
viewModel = response.Content.ReadAsAsync<GetOperationResponse.Operation>().Result;
}
viewModel.HttpStatusCode = response.StatusCode;
return viewModel;
}
}
public GetOperationResponse.Operation RenameTeamProject(string projectId, string newProjectName)
{
GetOperationResponse.Operation operation = new GetOperationResponse.Operation();
Object teamProject = new
{
name = newProjectName,
};
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);
// serialize the fields array into a json string
var patchValue = new StringContent(JsonConvert.SerializeObject(teamProject), Encoding.UTF8, "application/json");
var method = new HttpMethod("PATCH");
var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/projects/" + projectId + "?api-version=2.2") { Content = patchValue };
var response = client.SendAsync(request).Result;
if (response.IsSuccessStatusCode)
{
operation = response.Content.ReadAsAsync<GetOperationResponse.Operation>().Result;
}
else
{
dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync<dynamic>();
Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result;
operation.Message = msg.ToString();
}
operation.HttpStatusCode = response.StatusCode;
return operation;
}
}
public GetOperationResponse.Operation ChangeTeamProjectDescription(string projectId, string projectDescription)
{
GetOperationResponse.Operation opertion = new GetOperationResponse.Operation();
Object projectData = new
{
description = projectDescription
};
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);
// serialize the fields array into a json string
var patchValue = new StringContent(JsonConvert.SerializeObject(projectData), Encoding.UTF8, "application/json");
var method = new HttpMethod("PATCH");
var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/projects/" + projectId + "?api-version=2.2") { Content = patchValue };
var response = client.SendAsync(request).Result;
if (response.IsSuccessStatusCode)
{
opertion = response.Content.ReadAsAsync<GetOperationResponse.Operation>().Result;
}
else
{
dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync<dynamic>();
Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result;
opertion.Message = msg.ToString();
}
opertion.HttpStatusCode = response.StatusCode;
return opertion;
}
}
public HttpStatusCode DeleteTeamProject(string projectId)
{
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);
var method = new HttpMethod("DELETE");
var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/projects/" + projectId + "?api-version=2.2");
var response = client.SendAsync(request).Result;
return response.StatusCode;
}
}
}
}

Просмотреть файл

@ -0,0 +1,168 @@
using Newtonsoft.Json;
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using VstsRestApiSamples.ViewModels.ProjectsAndTeams;
namespace VstsRestApiSamples.ProjectsAndTeams
{
public class Teams
{
readonly IConfiguration _configuration;
readonly string _credentials;
public Teams(IConfiguration configuration)
{
_configuration = configuration;
_credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken)));
}
public ListofTeamsResponse.Teams GetTeams(string project)
{
ListofTeamsResponse.Teams viewModel = new ListofTeamsResponse.Teams();
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(_configuration.UriString);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);
HttpResponseMessage response = client.GetAsync("_apis/projects/" + project + "/teams?api-version=2.2").Result;
if (response.IsSuccessStatusCode)
{
viewModel = response.Content.ReadAsAsync<ListofTeamsResponse.Teams>().Result;
}
viewModel.HttpStatusCode = response.StatusCode;
return viewModel;
}
}
public GetTeamResponse.Team GetTeam (string project, string team)
{
GetTeamResponse.Team viewModel = new GetTeamResponse.Team();
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(_configuration.UriString);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);
HttpResponseMessage response = client.GetAsync("_apis/projects/" + project + "/teams/" + team + "?api-version=2.2").Result;
if (response.IsSuccessStatusCode)
{
viewModel = response.Content.ReadAsAsync<GetTeamResponse.Team>().Result;
}
viewModel.HttpStatusCode = response.StatusCode;
return viewModel;
}
}
public GetTeamMembersResponse.Members GetTeamMembers(string project, string team)
{
GetTeamMembersResponse.Members viewModel = new GetTeamMembersResponse.Members();
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(_configuration.UriString);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);
HttpResponseMessage response = client.GetAsync("_apis/projects/" + project + "/teams/" + team + "/members?api-version=2.2").Result;
if (response.IsSuccessStatusCode)
{
viewModel = response.Content.ReadAsAsync<GetTeamMembersResponse.Members>().Result;
}
viewModel.HttpStatusCode = response.StatusCode;
return viewModel;
}
}
public GetTeamResponse.Team CreateTeam(string project, string newTeam)
{
GetTeamResponse.Team viewModel = new GetTeamResponse.Team();
TeamPost team = new TeamPost() { name = newTeam };
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);
// serialize the fields array into a json string
var patchValue = new StringContent(JsonConvert.SerializeObject(team), Encoding.UTF8, "application/json"); // mediaType needs to be application/json-patch+json for a patch call
var method = new HttpMethod("POST");
var request = new HttpRequestMessage(method, _configuration.UriString + "/_apis/projects/" + project + "/teams?api-version=2.2") { Content = patchValue };
var response = client.SendAsync(request).Result;
if (response.IsSuccessStatusCode)
{
viewModel = response.Content.ReadAsAsync<GetTeamResponse.Team>().Result;
}
viewModel.HttpStatusCode = response.StatusCode;
return viewModel;
}
}
public GetTeamResponse.Team UpdateTeam(string project, string newTeam)
{
GetTeamResponse.Team viewModel = new GetTeamResponse.Team();
TeamPost team = new TeamPost() { name = newTeam, description = "my teams awesome description" };
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);
// serialize the fields array into a json string
var patchValue = new StringContent(JsonConvert.SerializeObject(team), Encoding.UTF8, "application/json"); // mediaType needs to be application/json-patch+json for a patch call
var method = new HttpMethod("PATCH");
var request = new HttpRequestMessage(method, _configuration.UriString + "/_apis/projects/" + project + "/teams/" + newTeam + "?api-version=2.2") { Content = patchValue };
var response = client.SendAsync(request).Result;
if (response.IsSuccessStatusCode)
{
viewModel = response.Content.ReadAsAsync<GetTeamResponse.Team>().Result;
}
viewModel.HttpStatusCode = response.StatusCode;
return viewModel;
}
}
public string DeleteTeam(string project, string team)
{
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);
var method = new HttpMethod("DELETE");
var request = new HttpRequestMessage(method, _configuration.UriString + "/_apis/projects/" + project + "/teams/" + team + "?api-version=2.2");
var response = client.SendAsync(request).Result;
return response.StatusCode.ToString();
}
}
}
}

Просмотреть файл

@ -5,5 +5,6 @@ namespace VstsRestApiSamples.ViewModels
public class BaseViewModel
{
public HttpStatusCode HttpStatusCode { get; set; }
public string Message { get; set; }
}
}

Просмотреть файл

@ -0,0 +1,34 @@

using System.Collections.Generic;
namespace VstsRestApiSamples.ViewModels.Git
{
public class GetAllRepositoriesResponse
{
public class Repositories : BaseViewModel
{
public List<Value> value { get; set; }
public int count { get; set; }
}
public class Project
{
public string id { get; set; }
public string name { get; set; }
public string description { get; set; }
public string url { get; set; }
public string state { get; set; }
public int revision { get; set; }
}
public class Value
{
public string id { get; set; }
public string name { get; set; }
public string url { get; set; }
public Project project { get; set; }
public string defaultBranch { get; set; }
public string remoteUrl { get; set; }
}
}
}

Просмотреть файл

@ -0,0 +1,45 @@
using System.Collections.Generic;
namespace VstsRestApiSamples.ViewModels.Git
{
public class GetCommitsByRepositoryIdResponse
{
public class Commits : BaseViewModel
{
public int count { get; set; }
public List<Value> value { get; set; }
}
public class Author
{
public string name { get; set; }
public string email { get; set; }
public string date { get; set; }
}
public class Committer
{
public string name { get; set; }
public string email { get; set; }
public string date { get; set; }
}
public class ChangeCounts
{
public int Add { get; set; }
public int Edit { get; set; }
}
public class Value
{
public string commitId { get; set; }
public Author author { get; set; }
public Committer committer { get; set; }
public string comment { get; set; }
public ChangeCounts changeCounts { get; set; }
public string url { get; set; }
public string remoteUrl { get; set; }
}
}
}

Просмотреть файл

@ -0,0 +1,31 @@
using System.Collections.Generic;
namespace VstsRestApiSamples.ViewModels.Git
{
public class GetFolderAndChildrenResponse
{
public class FolderAndChildren : BaseViewModel
{
public int count { get; set; }
public List<Value> value { get; set; }
}
public class ContentMetadata
{
public string fileName { get; set; }
}
public class Value
{
public string objectId { get; set; }
public string gitObjectType { get; set; }
public string commitId { get; set; }
public string path { get; set; }
public bool isFolder { get; set; }
public ContentMetadata contentMetadata { get; set; }
public string url { get; set; }
}
}
}

Просмотреть файл

@ -0,0 +1,80 @@
namespace VstsRestApiSamples.ViewModels.Git
{
public class GetRepositoryByIdResponse
{
public class Repository : BaseViewModel
{
public string id { get; set; }
public string name { get; set; }
public string url { get; set; }
public Project project { get; set; }
public string defaultBranch { get; set; }
public string remoteUrl { get; set; }
public Links _links { get; set; }
}
public class Project
{
public string id { get; set; }
public string name { get; set; }
public string description { get; set; }
public string url { get; set; }
public string state { get; set; }
public int revision { get; set; }
}
public class Self
{
public string href { get; set; }
}
public class Project2
{
public string href { get; set; }
}
public class Web
{
public string href { get; set; }
}
public class Commits
{
public string href { get; set; }
}
public class Refs
{
public string href { get; set; }
}
public class PullRequests
{
public string href { get; set; }
}
public class Items
{
public string href { get; set; }
}
public class Pushes
{
public string href { get; set; }
}
public class Links
{
public Self self { get; set; }
public Project2 project { get; set; }
public Web web { get; set; }
public Commits commits { get; set; }
public Refs refs { get; set; }
public PullRequests pullRequests { get; set; }
public Items items { get; set; }
public Pushes pushes { get; set; }
}
}
}

Просмотреть файл

@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VstsRestApiSamples.ViewModels.ProjectsAndTeams
{
public class GetOperationResponse
{
public class Operation : BaseViewModel
{
public string id { get; set; }
public string status { get; set; }
public string url { get; set; }
public _Links _links { get; set; }
}
public class _Links
{
public Self self { get; set; }
}
public class Self
{
public string href { get; set; }
}
}
}

Просмотреть файл

@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VstsRestApiSamples.ViewModels.ProjectsAndTeams
{
public class GetProjectCollectionResponse
{
public class ProjectCollection : BaseViewModel
{
public string id { get; set; }
public string name { get; set; }
public string url { get; set; }
public string state { get; set; }
public _Links _links { get; set; }
}
public class _Links
{
public Self self { get; set; }
public Web web { get; set; }
}
public class Self
{
public string href { get; set; }
}
public class Web
{
public string href { get; set; }
}
}
}

Просмотреть файл

@ -0,0 +1,69 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VstsRestApiSamples.ViewModels.ProjectsAndTeams
{
public class GetProjectResponse
{
public class Project : BaseViewModel
{
public string id { get; set; }
public string name { get; set; }
public string url { get; set; }
public string description { get; set; }
public string state { get; set; }
public Capabilities capabilities { get; set; }
public _Links _links { get; set; }
public Defaultteam defaultTeam { get; set; }
}
public class Capabilities
{
public Versioncontrol versioncontrol { get; set; }
public Processtemplate processTemplate { get; set; }
}
public class Versioncontrol
{
public string sourceControlType { get; set; }
}
public class Processtemplate
{
public string templateName { get; set; }
}
public class _Links
{
public Self self { get; set; }
public Collection collection { get; set; }
public Web web { get; set; }
}
public class Self
{
public string href { get; set; }
}
public class Collection
{
public string href { get; set; }
}
public class Web
{
public string href { get; set; }
}
public class Defaultteam
{
public string id { get; set; }
public string name { get; set; }
public string url { get; set; }
}
}
}

Просмотреть файл

@ -0,0 +1,22 @@
namespace VstsRestApiSamples.ViewModels.ProjectsAndTeams
{
public class GetTeamMembersResponse
{
public class Members : BaseViewModel
{
public Value[] value { get; set; }
public int count { get; set; }
}
public class Value
{
public string id { get; set; }
public string displayName { get; set; }
public string uniqueName { get; set; }
public string url { get; set; }
public string imageUrl { get; set; }
}
}
}

Просмотреть файл

@ -0,0 +1,15 @@
namespace VstsRestApiSamples.ViewModels.ProjectsAndTeams
{
public class GetTeamResponse
{
public class Team : BaseViewModel
{
public string id { get; set; }
public string name { get; set; }
public string url { get; set; }
public string description { get; set; }
public string identityUrl { get; set; }
}
}
}

Просмотреть файл

@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VstsRestApiSamples.ViewModels.ProjectsAndTeams
namespace VstsRestApiSamples.ViewModels.ProjectsAndTeams
{
public class ListofProjectsResponse
{

Просмотреть файл

@ -0,0 +1,22 @@
namespace VstsRestApiSamples.ViewModels.ProjectsAndTeams
{
public class ListofTeamsResponse
{
public class Teams : BaseViewModel
{
public Value[] value { get; set; }
public int count { get; set; }
}
public class Value
{
public string id { get; set; }
public string name { get; set; }
public string url { get; set; }
public string description { get; set; }
public string identityUrl { get; set; }
}
}
}

Просмотреть файл

@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VstsRestApiSamples.ViewModels.ProjectsAndTeams
{
public class ProjectPost
{
public class Project
{
public string name { get; set; }
public string description { get; set; }
public Capabilities capabilities { get; set; }
}
public class Capabilities
{
public Versioncontrol versioncontrol { get; set; }
public Processtemplate processTemplate { get; set; }
}
public class Versioncontrol
{
public string sourceControlType { get; set; }
}
public class Processtemplate
{
public string templateTypeId { get; set; }
}
}
}

Просмотреть файл

@ -0,0 +1,8 @@
namespace VstsRestApiSamples.ViewModels.ProjectsAndTeams
{
public class TeamPost
{
public string name { get; set; }
public string description { get; set; }
}
}

Просмотреть файл

@ -0,0 +1,87 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VstsRestApiSamples.ViewModels.Work
{
public class GetTeamSettingsResponse
{
public class Settings : BaseViewModel
{
public Backlogiteration backlogIteration { get; set; }
public string bugsBehavior { get; set; }
public string[] workingDays { get; set; }
public Backlogvisibilities backlogVisibilities { get; set; }
public Defaultiteration defaultIteration { get; set; }
public string defaultIterationMacro { get; set; }
public string url { get; set; }
public _Links _links { get; set; }
}
public class Backlogiteration
{
public string id { get; set; }
public string name { get; set; }
public string path { get; set; }
public string url { get; set; }
}
public class Backlogvisibilities
{
public bool MicrosoftEpicCategory { get; set; }
public bool MicrosoftFeatureCategory { get; set; }
public bool MicrosoftRequirementCategory { get; set; }
}
public class Defaultiteration
{
public string id { get; set; }
public string name { get; set; }
public string path { get; set; }
public string url { get; set; }
}
public class _Links
{
public Self self { get; set; }
public Project project { get; set; }
public Team team { get; set; }
public Teamiterations teamIterations { get; set; }
public Teamfieldvalues teamFieldValues { get; set; }
public Classificationnode[] classificationNode { get; set; }
}
public class Self
{
public string href { get; set; }
}
public class Project
{
public string href { get; set; }
}
public class Team
{
public string href { get; set; }
}
public class Teamiterations
{
public string href { get; set; }
}
public class Teamfieldvalues
{
public string href { get; set; }
}
public class Classificationnode
{
public string href { get; set; }
}
}
}

Просмотреть файл

@ -1,7 +1,4 @@
using Newtonsoft.Json;
using System;
namespace VstsRestApiSamples.ViewModels.WorkItemTracking
namespace VstsRestApiSamples.ViewModels.WorkItemTracking
{
public class AttachmentReference : BaseViewModel
{

Просмотреть файл

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VstsRestApiSamples.ViewModels.WorkItemTracking
{
public class CreateUpdateNodeViewModel
{
public class Node : BaseViewModel
{
public int id { get; set; }
public string name { get; set; }
public Attributes attributes { get; set; }
}
public class Attributes
{
public DateTime startDate { get; set; }
public DateTime finishDate { get; set; }
}
}
}

Просмотреть файл

@ -0,0 +1,63 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VstsRestApiSamples.ViewModels.WorkItemTracking
{
public class GetDefaultValuesResponse
{
public class Defaults : BaseViewModel
{
public Fields fields { get; set; }
public _Links _links { get; set; }
public string url { get; set; }
}
public class Fields
{
[JsonProperty(PropertyName = "System.WorkItemType")]
public string SystemWorkItemType { get; set; }
[JsonProperty(PropertyName = "System.AreaPath")]
public string SystemAreaPath { get; set; }
[JsonProperty(PropertyName = "System.TeamProject")]
public string SystemTeamProject { get; set; }
[JsonProperty(PropertyName = "System.IterationPath")]
public string SystemIterationPath { get; set; }
[JsonProperty(PropertyName = "System.State")]
public string SystemState { get; set; }
[JsonProperty(PropertyName = "System.Reason")]
public string SystemReason { get; set; }
[JsonProperty(PropertyName = "System.ChangedBy")]
public string SystemChangedBy { get; set; }
[JsonProperty(PropertyName = "System.CreatedBy")]
public string SystemCreatedBy { get; set; }
}
public class _Links
{
public Workitemtype workItemType { get; set; }
public Fields1 fields { get; set; }
}
public class Workitemtype
{
public string href { get; set; }
}
public class Fields1
{
public string href { get; set; }
}
}
}

Просмотреть файл

@ -0,0 +1,115 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VstsRestApiSamples.ViewModels.WorkItemTracking
{
public class GetItemFromRecycleBinResponse
{
public class WorkItem: BaseViewModel
{
public string id { get; set; }
public string type { get; set; }
public string Name { get; set; }
public string Project { get; set; }
public DateTime DeletedDate { get; set; }
public string DeletedBy { get; set; }
public string url { get; set; }
public Resource resource { get; set; }
}
public class Resource
{
public int id { get; set; }
public int rev { get; set; }
public Fields fields { get; set; }
public _Links _links { get; set; }
public string url { get; set; }
}
public class Fields
{
[JsonProperty(PropertyName = "System.AreaPath")]
public string SystemAreaPath { get; set; }
[JsonProperty(PropertyName = "System.TeamProject")]
public string SystemTeamProject { get; set; }
[JsonProperty(PropertyName = "System.IterationPath")]
public string SystemIterationPath { get; set; }
[JsonProperty(PropertyName = "System.WorkItemType")]
public string SystemWorkItemType { get; set; }
[JsonProperty(PropertyName = "System.Reason")]
public string SystemState { get; set; }
[JsonProperty(PropertyName = "")]
public string SystemReason { get; set; }
[JsonProperty(PropertyName = "System.CreatedDate")]
public DateTime SystemCreatedDate { get; set; }
[JsonProperty(PropertyName = "System.CreatedBy")]
public string SystemCreatedBy { get; set; }
[JsonProperty(PropertyName = "System.ChangedDate")]
public DateTime SystemChangedDate { get; set; }
[JsonProperty(PropertyName = "System.ChangedBy")]
public string SystemChangedBy { get; set; }
[JsonProperty(PropertyName = "System.Title")]
public string SystemTitle { get; set; }
}
public class _Links
{
public Self self { get; set; }
public Workitemupdates workItemUpdates { get; set; }
public Workitemrevisions workItemRevisions { get; set; }
public Workitemhistory workItemHistory { get; set; }
public Html html { get; set; }
public Workitemtype workItemType { get; set; }
public Fields1 fields { get; set; }
}
public class Self
{
public string href { get; set; }
}
public class Workitemupdates
{
public string href { get; set; }
}
public class Workitemrevisions
{
public string href { get; set; }
}
public class Workitemhistory
{
public string href { get; set; }
}
public class Html
{
public string href { get; set; }
}
public class Workitemtype
{
public string href { get; set; }
}
public class Fields1
{
public string href { get; set; }
}
}
}

Просмотреть файл

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VstsRestApiSamples.ViewModels.WorkItemTracking
{
public class GetItemsFromRecycleBinResponse
{
public class WorkItems : BaseViewModel
{
public Value[] value { get; set; }
}
public class Value
{
public string id { get; set; }
public string type { get; set; }
public string Name { get; set; }
public string Project { get; set; }
public DateTime DeletedDate { get; set; }
public string DeletedBy { get; set; }
public string url { get; set; }
}
}
}

Просмотреть файл

@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VstsRestApiSamples.ViewModels.WorkItemTracking
{
public class GetNodeResponse
{
public class Node : BaseViewModel
{
public int id { get; set; }
public string name { get; set; }
public string structureType { get; set; }
public bool hasChildren { get; set; }
public Attributes attributes { get; set; }
public _Links _links { get; set; }
public string url { get; set; }
}
public class Attributes
{
public DateTime startDate { get; set; }
public DateTime finishDate { get; set; }
}
public class _Links
{
public Self self { get; set; }
public Parent parent { get; set; }
}
public class Self
{
public string href { get; set; }
}
public class Parent
{
public string href { get; set; }
}
}
}

Просмотреть файл

@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VstsRestApiSamples.ViewModels.WorkItemTracking
{
public class GetNodesResponse
{
public class Nodes : BaseViewModel
{
public int id { get; set; }
public string name { get; set; }
public string structureType { get; set; }
public bool hasChildren { get; set; }
public Child[] children { get; set; }
public _Links _links { get; set; }
public string url { get; set; }
}
public class _Links
{
public Self self { get; set; }
}
public class Self
{
public string href { get; set; }
}
public class Child
{
public int id { get; set; }
public string name { get; set; }
public string structureType { get; set; }
public bool hasChildren { get; set; }
public string url { get; set; }
public Child1[] children { get; set; }
}
public class Child1
{
public int id { get; set; }
public string name { get; set; }
public string structureType { get; set; }
public bool hasChildren { get; set; }
public string url { get; set; }
public Attributes attributes { get; set; }
}
public class Attributes
{
public DateTime startDate { get; set; }
public DateTime finishDate { get; set; }
}
}
}

Просмотреть файл

@ -1,6 +1,6 @@
namespace VstsRestApiSamples.ViewModels.WorkItemTracking
{
public class ListofQueriesByFolderPath
public class GetQueriesByFolderPath
{
public class Queries : BaseViewModel
{

Просмотреть файл

@ -1,6 +1,6 @@
namespace VstsRestApiSamples.ViewModels.WorkItemTracking
{
public class GetQueryResponse
public class GetQueriesByIdResponse
{
public class Queries : BaseViewModel
{

Просмотреть файл

@ -1,6 +1,6 @@
namespace VstsRestApiSamples.ViewModels.WorkItemTracking.Queries
{
public class ListofQueriesResponse
public class GetQueriesResponse
{
public class Queries : BaseViewModel
{

Просмотреть файл

@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VstsRestApiSamples.ViewModels.WorkItemTracking
{
public class GetRestoreMultipleWorkItemsResponse
{
public class Items : BaseViewModel
{
public int count { get; set; }
public Value[] value { get; set; }
}
public class Value
{
public int code { get; set; }
public Headers headers { get; set; }
public string body { get; set; }
}
public class Headers
{
public string ContentType { get; set; }
}
}
}

Просмотреть файл

@ -0,0 +1,103 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VstsRestApiSamples.ViewModels.WorkItemTracking
{
public class GetRestoredWorkItemResponse
{
public class WorkItem: BaseViewModel
{
public int id { get; set; }
public int code { get; set; }
public string type { get; set; }
public string name { get; set; }
public string project { get; set; }
public string deletedDate { get; set; }
public string deletedBy { get; set; }
public string url { get; set; }
public Resource resource { get; set; }
}
public class Resource
{
public int id { get; set; }
public int rev { get; set; }
public Fields fields { get; set; }
public _Links _links { get; set; }
public string url { get; set; }
}
public class Fields
{
public string SystemAreaPath { get; set; }
public string SystemTeamProject { get; set; }
public string SystemIterationPath { get; set; }
public string SystemWorkItemType { get; set; }
public string SystemState { get; set; }
public string SystemReason { get; set; }
public DateTime SystemCreatedDate { get; set; }
public string SystemCreatedBy { get; set; }
public DateTime SystemChangedDate { get; set; }
public string SystemChangedBy { get; set; }
public string SystemTitle { get; set; }
public string SystemBoardColumn { get; set; }
public bool SystemBoardColumnDone { get; set; }
public DateTime MicrosoftVSTSCommonStateChangeDate { get; set; }
public int MicrosoftVSTSCommonPriority { get; set; }
public string MicrosoftVSTSCommonSeverity { get; set; }
public string WEF_6CB513B6E70E43499D9FC94E5BBFB784_KanbanColumn { get; set; }
public bool WEF_6CB513B6E70E43499D9FC94E5BBFB784_KanbanColumnDone { get; set; }
public string MicrosoftVSTSCommonValueArea { get; set; }
}
public class _Links
{
public Self self { get; set; }
public Workitemupdates workItemUpdates { get; set; }
public Workitemrevisions workItemRevisions { get; set; }
public Workitemhistory workItemHistory { get; set; }
public Html html { get; set; }
public Workitemtype workItemType { get; set; }
public Fields1 fields { get; set; }
}
public class Self
{
public string href { get; set; }
}
public class Workitemupdates
{
public string href { get; set; }
}
public class Workitemrevisions
{
public string href { get; set; }
}
public class Workitemhistory
{
public string href { get; set; }
}
public class Html
{
public string href { get; set; }
}
public class Workitemtype
{
public string href { get; set; }
}
public class Fields1
{
public string href { get; set; }
}
}
}

Просмотреть файл

@ -1,6 +1,6 @@
namespace VstsRestApiSamples.ViewModels.WorkItemTracking
{
public class ListofWorkItemFieldsResponse
public class GetWorkItemFieldsResponse
{
public class Fields : BaseViewModel
{
@ -14,11 +14,11 @@
public string referenceName { get; set; }
public string type { get; set; }
public bool readOnly { get; set; }
public Supportedoperation[] supportedOperations { get; set; }
public SupportedOperation[] supportedOperations { get; set; }
public string url { get; set; }
}
public class Supportedoperation
public class SupportedOperation
{
public string referenceName { get; set; }
public string name { get; set; }

Просмотреть файл

@ -1,30 +1,73 @@
using System;
using Newtonsoft.Json;
using System;
namespace VstsRestApiSamples.ViewModels.WorkItemTracking
{
public class GetWorkItemsResponse
{
public class Results : BaseViewModel
public class WorkItems : BaseViewModel
{
public string queryType { get; set; }
public string queryResultType { get; set; }
public DateTime asOf { get; set; }
public Column[] columns { get; set; }
public Workitem[] workItems { get; set; }
public int count { get; set; }
public Value[] value { get; set; }
}
public class Column
{
public string referenceName { get; set; }
public string name { get; set; }
public string url { get; set; }
}
public class Workitem
public class Value
{
public int id { get; set; }
public int rev { get; set; }
public Fields fields { get; set; }
public string url { get; set; }
}
public class Fields
{
[JsonProperty(PropertyName = "System.AreaPath")]
public string SystemAreaPath { get; set; }
[JsonProperty(PropertyName = "System.TeamProject")]
public string SystemTeamProject { get; set; }
[JsonProperty(PropertyName = "System.IterationPath")]
public string SystemIterationPath { get; set; }
[JsonProperty(PropertyName = "System.WorkItemType")]
public string SystemWorkItemType { get; set; }
[JsonProperty(PropertyName = "System.State")]
public string SystemState { get; set; }
[JsonProperty(PropertyName = "System.Reason")]
public string SystemReason { get; set; }
[JsonProperty(PropertyName = "System.CreatedDate")]
public DateTime SystemCreatedDate { get; set; }
[JsonProperty(PropertyName = "System.CreatedBy")]
public string SystemCreatedBy { get; set; }
[JsonProperty(PropertyName = "System.ChangedDate")]
public DateTime SystemChangedDate { get; set; }
[JsonProperty(PropertyName = "System.ChangedBy")]
public string SystemChangedBy { get; set; }
[JsonProperty(PropertyName="System.Title")]
public string SystemTitle { get; set; }
[JsonProperty(PropertyName = "Microsoft.VSTS.Scheduling.Effort")]
public int MicrosoftVSTSSchedulingEffort { get; set; }
[JsonProperty(PropertyName = "System.Description")]
public string SystemDescription { get; set; }
[JsonProperty(PropertyName = "System.AssignedTo")]
public string SystemAssignedTo { get; set; }
[JsonProperty(PropertyName = "Microsoft.VSTS.Scheduling.RemainingWork")]
public int MicrosoftVSTSSchedulingRemainingWork { get; set; }
[JsonProperty(PropertyName = "System.Tags")]
public string SystemTags { get; set; }
}
}
}

Просмотреть файл

@ -0,0 +1,30 @@
using System;
namespace VstsRestApiSamples.ViewModels.WorkItemTracking
{
public class GetWorkItemsWIQLResponse
{
public class Results : BaseViewModel
{
public string queryType { get; set; }
public string queryResultType { get; set; }
public DateTime asOf { get; set; }
public Column[] columns { get; set; }
public Workitem[] workItems { get; set; }
}
public class Column
{
public string referenceName { get; set; }
public string name { get; set; }
public string url { get; set; }
}
public class Workitem
{
public int id { get; set; }
public string url { get; set; }
}
}
}

Просмотреть файл

@ -0,0 +1,181 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VstsRestApiSamples.ViewModels.WorkItemTracking
{
public class GetWorkItemsWithLinksAndAttachmentsResponse
{
public class WorkItems : BaseViewModel
{
public int count { get; set; }
public Value[] value { get; set; }
}
public class Value
{
public int id { get; set; }
public int rev { get; set; }
public Fields fields { get; set; }
public Relation[] relations { get; set; }
public _Links _links { get; set; }
public string url { get; set; }
}
public class Fields
{
[JsonProperty(PropertyName = "System.Id")]
public int SystemId { get; set; }
[JsonProperty(PropertyName = "System.AreaId")]
public int SystemAreaId { get; set; }
[JsonProperty(PropertyName = "System.AreaPath")]
public string SystemAreaPath { get; set; }
[JsonProperty(PropertyName = "System.NodeName")]
public string SystemNodeName { get; set; }
[JsonProperty(PropertyName = "System.TeamProject")]
public string SystemTeamProject { get; set; }
[JsonProperty(PropertyName = "System.AreaLevel1")]
public string SystemAreaLevel1 { get; set; }
[JsonProperty(PropertyName = "System.Rev")]
public int SystemRev { get; set; }
[JsonProperty(PropertyName = "System.AuthorizedDate")]
public DateTime SystemAuthorizedDate { get; set; }
[JsonProperty(PropertyName = "System.RevisedDate")]
public DateTime SystemRevisedDate { get; set; }
[JsonProperty(PropertyName = "System.IterationId")]
public int SystemIterationId { get; set; }
[JsonProperty(PropertyName = "System.IterationPat")]
public string SystemIterationPath { get; set; }
[JsonProperty(PropertyName = "System.IterationLevel1")]
public string SystemIterationLevel1 { get; set; }
[JsonProperty(PropertyName = "System.WorkItemType")]
public string SystemWorkItemType { get; set; }
[JsonProperty(PropertyName = "System.State")]
public string SystemState { get; set; }
[JsonProperty(PropertyName = "System.Reason")]
public string SystemReason { get; set; }
[JsonProperty(PropertyName = "System.CreatedDate")]
public DateTime SystemCreatedDate { get; set; }
[JsonProperty(PropertyName = "System.CreatedBy")]
public string SystemCreatedBy { get; set; }
[JsonProperty(PropertyName = "System.ChangedDate")]
public DateTime SystemChangedDate { get; set; }
[JsonProperty(PropertyName = "")]
public string SystemChangedBy { get; set; }
[JsonProperty(PropertyName = "System.AuthorizedAs")]
public string SystemAuthorizedAs { get; set; }
[JsonProperty(PropertyName = "System.PersonId")]
public int SystemPersonId { get; set; }
[JsonProperty(PropertyName = "System.Watermark")]
public int SystemWatermark { get; set; }
[JsonProperty(PropertyName = "System.Title")]
public string SystemTitle { get; set; }
[JsonProperty(PropertyName = "Microsoft.VSTS.Scheduling.Effort")]
public int MicrosoftVSTSSchedulingEffort { get; set; }
[JsonProperty(PropertyName = "System.Description")]
public string SystemDescription { get; set; }
[JsonProperty(PropertyName = "System.AssignedTo")]
public string SystemAssignedTo { get; set; }
[JsonProperty(PropertyName = "Microsoft.VSTS.Scheduling.RemainingWork")]
public int MicrosoftVSTSSchedulingRemainingWork { get; set; }
[JsonProperty(PropertyName = "System.Tags")]
public string SystemTags { get; set; }
}
public class _Links
{
public Self self { get; set; }
public Workitemupdates workItemUpdates { get; set; }
public Workitemrevisions workItemRevisions { get; set; }
public Workitemhistory workItemHistory { get; set; }
public Html html { get; set; }
public Workitemtype workItemType { get; set; }
public Fields1 fields { get; set; }
}
public class Self
{
public string href { get; set; }
}
public class Workitemupdates
{
public string href { get; set; }
}
public class Workitemrevisions
{
public string href { get; set; }
}
public class Workitemhistory
{
public string href { get; set; }
}
public class Html
{
public string href { get; set; }
}
public class Workitemtype
{
public string href { get; set; }
}
public class Fields1
{
public string href { get; set; }
}
public class Relation
{
public string rel { get; set; }
public string url { get; set; }
public Attributes attributes { get; set; }
}
public class Attributes
{
public bool isLocked { get; set; }
public string comment { get; set; }
public DateTime authorizedDate { get; set; }
public int id { get; set; }
public DateTime resourceCreatedDate { get; set; }
public DateTime resourceModifiedDate { get; set; }
public DateTime revisedDate { get; set; }
public string name { get; set; }
}
}
}

Просмотреть файл

@ -1,73 +0,0 @@
using Newtonsoft.Json;
using System;
namespace VstsRestApiSamples.ViewModels.WorkItemTracking
{
public class ListofWorkItemsResponse
{
public class WorkItems : BaseViewModel
{
public int count { get; set; }
public Value[] value { get; set; }
}
public class Value
{
public int id { get; set; }
public int rev { get; set; }
public Fields fields { get; set; }
public string url { get; set; }
}
public class Fields
{
[JsonProperty(PropertyName = "System.AreaPath")]
public string SystemAreaPath { get; set; }
[JsonProperty(PropertyName = "System.TeamProject")]
public string SystemTeamProject { get; set; }
[JsonProperty(PropertyName = "System.IterationPath")]
public string SystemIterationPath { get; set; }
[JsonProperty(PropertyName = "System.WorkItemType")]
public string SystemWorkItemType { get; set; }
[JsonProperty(PropertyName = "System.State")]
public string SystemState { get; set; }
[JsonProperty(PropertyName = "System.Reason")]
public string SystemReason { get; set; }
[JsonProperty(PropertyName = "System.CreatedDate")]
public DateTime SystemCreatedDate { get; set; }
[JsonProperty(PropertyName = "System.CreatedBy")]
public string SystemCreatedBy { get; set; }
[JsonProperty(PropertyName = "System.ChangedDate")]
public DateTime SystemChangedDate { get; set; }
[JsonProperty(PropertyName = "System.ChangedBy")]
public string SystemChangedBy { get; set; }
[JsonProperty(PropertyName="System.Title")]
public string SystemTitle { get; set; }
[JsonProperty(PropertyName = "Microsoft.VSTS.Scheduling.Effort")]
public int MicrosoftVSTSSchedulingEffort { get; set; }
[JsonProperty(PropertyName = "System.Description")]
public string SystemDescription { get; set; }
[JsonProperty(PropertyName = "System.AssignedTo")]
public string SystemAssignedTo { get; set; }
[JsonProperty(PropertyName = "Microsoft.VSTS.Scheduling.RemainingWork")]
public int MicrosoftVSTSSchedulingRemainingWork { get; set; }
[JsonProperty(PropertyName = "System.Tags")]
public string SystemTags { get; set; }
}
}
}

Просмотреть файл

@ -1,7 +1,5 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System.Collections.Generic;
using System;
namespace VstsRestApiSamples.ViewModels.WorkItemTracking
{

Просмотреть файл

@ -19,6 +19,7 @@
public class Attributes
{
public string comment { get; set; }
public string name { get; set; }
}
}
}

Просмотреть файл

@ -39,7 +39,7 @@
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<HintPath>..\packages\Newtonsoft.Json.9.0.2-beta1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
@ -59,20 +59,50 @@
<Compile Include="Build2\Build.cs" />
<Compile Include="Configuration.cs" />
<Compile Include="GettingStarted\Authentication.cs" />
<Compile Include="Git\Repositories.cs" />
<Compile Include="IConfiguration.cs" />
<Compile Include="ProjectsAndTeams\Processes.cs" />
<Compile Include="ProjectsAndTeams\ProjectCollections.cs" />
<Compile Include="ProjectsAndTeams\TeamProjects.cs" />
<Compile Include="ProjectsAndTeams\Samples.cs" />
<Compile Include="ProjectsAndTeams\Teams.cs" />
<Compile Include="ViewModels\WorkItemTracking\GetRestoredWorkItemResponse.cs" />
<Compile Include="ViewModels\Git\GetAllRepositoriesResponse.cs" />
<Compile Include="ViewModels\Git\GetCommitsByRepositoryIdResponse.cs" />
<Compile Include="ViewModels\Git\GetFolderAndChildrenResponse.cs" />
<Compile Include="ViewModels\Git\GetRepositoryByIdResponse.cs" />
<Compile Include="ViewModels\ProjectsAndTeams\GetOperationResponse.cs" />
<Compile Include="ViewModels\ProjectsAndTeams\GetProjectResponse.cs" />
<Compile Include="ViewModels\ProjectsAndTeams\GetTeamMembersResponse.cs" />
<Compile Include="ViewModels\ProjectsAndTeams\GetTeamResponse.cs" />
<Compile Include="ViewModels\ProjectsAndTeams\GetProjectCollectionResponse.cs" />
<Compile Include="ViewModels\ProjectsAndTeams\ListofProjectsResponse.cs" />
<Compile Include="ViewModels\ProjectsAndTeams\ListofTeamsResponse.cs" />
<Compile Include="ViewModels\ProjectsAndTeams\ProjectPost.cs" />
<Compile Include="ViewModels\ProjectsAndTeams\TeamPost.cs" />
<Compile Include="ViewModels\WorkItemTracking\AttachmentReference.cs" />
<Compile Include="ViewModels\WorkItemTracking\CreateUpdateNodeViewModel.cs" />
<Compile Include="ViewModels\WorkItemTracking\GetDefaultValuesResponse.cs" />
<Compile Include="ViewModels\WorkItemTracking\GetItemFromRecycleBinResponse.cs" />
<Compile Include="ViewModels\WorkItemTracking\GetItemsFromRecycleBinResponse.cs" />
<Compile Include="ViewModels\WorkItemTracking\GetNodeResponse.cs" />
<Compile Include="ViewModels\WorkItemTracking\GetNodesResponse.cs" />
<Compile Include="ViewModels\WorkItemTracking\GetRestoreMultipleWorkItemsResponse.cs" />
<Compile Include="ViewModels\WorkItemTracking\GetWorkItemsWithLinksAndAttachmentsResponse.cs" />
<Compile Include="ViewModels\WorkItemTracking\WorkItemBatchPost.cs" />
<Compile Include="ViewModels\WorkItemTracking\WorkItemBatchPostResponse.cs" />
<Compile Include="ViewModels\Work\GetTeamSettingsResponse.cs" />
<Compile Include="WorkItemTracking\Attachments.cs" />
<Compile Include="WorkItemTracking\Batch.cs" />
<Compile Include="WorkItemTracking\ClassificationNodes.cs" />
<Compile Include="WorkItemTracking\Fields.cs" />
<Compile Include="WorkItemTracking\RecycleBin.cs" />
<Compile Include="WorkItemTracking\Samples.cs" />
<Compile Include="WorkItemTracking\WIQL.cs" />
<Compile Include="WorkItemTracking\Reporting.cs" />
<Compile Include="WorkItemTracking\WorkItems.cs" />
<Compile Include="Work\ProcessConfiguration\Fields.cs" />
<Compile Include="Work\ProcessConfiguration\Lists.cs" />
<Compile Include="Work\Fields.cs" />
<Compile Include="Work\Lists.cs" />
<Compile Include="WorkItemTracking\Queries.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ViewModels\BaseViewModel.cs" />
@ -81,13 +111,13 @@
<Compile Include="ViewModels\ProjectsAndTeams\ListofProcessesResponse.cs" />
<Compile Include="ViewModels\WorkItemTracking\BatchOfWorkItemLinksResponse.cs" />
<Compile Include="ViewModels\WorkItemTracking\BatchOfWorkItemRevisionsResponse.cs" />
<Compile Include="ViewModels\WorkItemTracking\GetWorkItemsResponse.cs" />
<Compile Include="ViewModels\WorkItemTracking\GetWorkItemsWIQLResponse.cs" />
<Compile Include="ViewModels\WorkItemTracking\GetWorkItemExpandAllResponse.cs" />
<Compile Include="ViewModels\WorkItemTracking\ListofQueriesByFolderPath.cs" />
<Compile Include="ViewModels\WorkItemTracking\ListofQueriesByIdResponse.cs" />
<Compile Include="ViewModels\WorkItemTracking\ListofQueriesResponse.cs" />
<Compile Include="ViewModels\WorkItemTracking\ListofWorkItemFieldsResponse.cs" />
<Compile Include="ViewModels\WorkItemTracking\ListofWorkItemsResponse.cs" />
<Compile Include="ViewModels\WorkItemTracking\GetQueriesByFolderPath.cs" />
<Compile Include="ViewModels\WorkItemTracking\GetQueriesByIdResponse.cs" />
<Compile Include="ViewModels\WorkItemTracking\GetQueriesResponse.cs" />
<Compile Include="ViewModels\WorkItemTracking\GetWorkItemFieldsResponse.cs" />
<Compile Include="ViewModels\WorkItemTracking\GetWorkItemsResponse.cs" />
<Compile Include="ViewModels\WorkItemTracking\WorkItemPatch.cs" />
<Compile Include="ViewModels\WorkItemTracking\WorkItemPatchResponse.cs" />
<Compile Include="ViewModels\Work\DownloadAttachmentResponse.cs" />
@ -97,6 +127,7 @@
<Compile Include="ViewModels\Work\PickListResponse.cs" />
<Compile Include="ViewModels\Work\PickListPost.cs" />
<Compile Include="ViewModels\Work\PickListPostResponse.cs" />
<Compile Include="Work\TeamSettings.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />

Просмотреть файл

@ -3,7 +3,7 @@ using System.Net.Http;
using System.Net.Http.Headers;
using VstsRestApiSamples.ViewModels.Work;
namespace VstsRestApiSamples.Work.ProcessConfiguration
namespace VstsRestApiSamples.Work
{
public class Fields
{

Просмотреть файл

@ -3,7 +3,7 @@ using System.Net.Http;
using System.Net.Http.Headers;
using VstsRestApiSamples.ViewModels.Work;
namespace VstsRestApiSamples.Work.ProcessConfiguration
namespace VstsRestApiSamples.Work
{
public class Lists
{

Просмотреть файл

@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using VstsRestApiSamples.ViewModels.Work;
namespace VstsRestApiSamples.Work
{
public class TeamSettings
{
readonly IConfiguration _configuration;
readonly string _credentials;
public TeamSettings(IConfiguration configuration)
{
_configuration = configuration;
_credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken)));
}
public GetTeamSettingsResponse.Settings GetTeamsSettings(string project, string team)
{
GetTeamSettingsResponse.Settings viewModel = new GetTeamSettingsResponse.Settings();
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(_configuration.UriString);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);
HttpResponseMessage response = client.GetAsync(project + "/" + team + "/_apis/work/teamsettings?api-version=3.0-preview").Result;
if (response.IsSuccessStatusCode)
{
viewModel = response.Content.ReadAsAsync<GetTeamSettingsResponse.Settings>().Result;
}
viewModel.HttpStatusCode = response.StatusCode;
return viewModel;
}
}
}
}

Просмотреть файл

@ -2,6 +2,7 @@
using System.IO;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using VstsRestApiSamples.ViewModels.Work;
namespace VstsRestApiSamples.WorkItemTracking
@ -17,12 +18,6 @@ namespace VstsRestApiSamples.WorkItemTracking
_credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken)));
}
// / <summary>
// / download an attachment from the work item
// / </summary>
// / <param name="url">url supplied from get work item</param>
// / <param name="saveToFile">location you want to save the attachment to</param>
// / <returns>DownloadAttachmentResponse</returns>
public DownloadAttachmentResponse DownloadAttachment(string url, string saveToFile)
{
DownloadAttachmentResponse viewModel = new DownloadAttachmentResponse();
@ -69,18 +64,48 @@ namespace VstsRestApiSamples.WorkItemTracking
}
}
// / <summary>
// / upload binary file into attachement store
// / </summary>
// / <param name="filePath">local file path for file</param>
// / <returns>UploadAttachmentResponse.Attachment</returns>
public ViewModels.WorkItemTracking.AttachmentReference UploadAttachment(string filePath)
public ViewModels.WorkItemTracking.AttachmentReference UploadAttachmentTextFile(string filePath)
{
string text = File.ReadAllText(@filePath);
String[] breakApart = filePath.Split('\\');
int length = breakApart.Length;
string fileName = breakApart[length - 1];
ViewModels.WorkItemTracking.AttachmentReference viewModel = new ViewModels.WorkItemTracking.AttachmentReference();
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);
// serialize the fields array into a json string
var patchValue = new StringContent(text, Encoding.UTF8, "application/json"); // mediaType needs to be application/json-patch+json for a patch call
var method = new HttpMethod("POST");
var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/attachments?fileName=" + fileName + "&api-version=2.2") { Content = patchValue };
var response = client.SendAsync(request).Result;
if (response.IsSuccessStatusCode)
{
viewModel = response.Content.ReadAsAsync<ViewModels.WorkItemTracking.AttachmentReference>().Result;
}
viewModel.HttpStatusCode = response.StatusCode;
return viewModel;
}
}
public ViewModels.WorkItemTracking.AttachmentReference UploadAttachmentBinaryFile(string filePath)
{
Byte[] bytes = File.ReadAllBytes(@filePath);
String[] breakApart = filePath.Split('\\');
int length = breakApart.Length;
string fileName = breakApart[length - 1];
ViewModels.WorkItemTracking.AttachmentReference viewModel = new ViewModels.WorkItemTracking.AttachmentReference();
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(_configuration.UriString);
@ -94,17 +119,17 @@ namespace VstsRestApiSamples.WorkItemTracking
if (response.IsSuccessStatusCode)
{
var result = response.Content.ReadAsAsync<ViewModels.WorkItemTracking.AttachmentReference>().Result;
return result;
viewModel = response.Content.ReadAsAsync<ViewModels.WorkItemTracking.AttachmentReference>().Result;
}
else
{
dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync<dynamic>();
Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result;
var error = msg.ToString();
return null;
viewModel.Message = msg.ToString();
}
viewModel.HttpStatusCode = response.StatusCode;
return viewModel;
}
}

Просмотреть файл

@ -1,7 +1,6 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
@ -20,11 +19,6 @@ namespace VstsRestApiSamples.WorkItemTracking
_credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken)));
}
// <summary>
// Create a bug
// </summary>
// <param name="projectName"></param>
// <returns>WorkItemPatchResponse.WorkItem</returns>
public WorkItemBatchPostResponse CreateAndLinkMultipleWorkItems(string projectName)
{
WorkItemBatchPost.BatchRequest[] batchRequests = new WorkItemBatchPost.BatchRequest[2];
@ -35,19 +29,17 @@ namespace VstsRestApiSamples.WorkItemTracking
Object[] parentPatchDocumentBody = new Object[2];
parentPatchDocumentBody[0] = new { op = "add", path = "/fields/System.Title", value = "Customer can sign in using their Microsoft Account" };
parentPatchDocumentBody[1] = new { op = "add", path = "/id", value = "-1" };
batchRequests[0] = new WorkItemBatchPost.BatchRequest
{
method = "PATCH",
uri = '/' + projectName + "/_apis/wit/workitems/$User Story?api-version=2.2",
headers = headers,
body = parentPatchDocumentBody
};
batchRequests[0] = new WorkItemBatchPost.BatchRequest {
method = "PATCH",
uri = '/' + projectName + "/_apis/wit/workitems/$User Story?api-version=2.2",
headers = headers,
body = parentPatchDocumentBody
};
Object[] childPatchDocumentBody = new Object[3];
childPatchDocumentBody[0] = new { op = "add", path = "/fields/System.Title", value = "JavaScript implementation for Microsoft Account" };
childPatchDocumentBody[1] = new { op = "add", path = "/id", value = "-2" };
childPatchDocumentBody[2] = new
{
childPatchDocumentBody[2] = new {
op = "add",
path = "/relations/-",
value = new
@ -56,13 +48,13 @@ namespace VstsRestApiSamples.WorkItemTracking
url = _configuration.UriString + "_apis/wit/workitems/-1"
}
};
batchRequests[1] = new WorkItemBatchPost.BatchRequest
{
method = "PATCH",
uri = '/' + projectName + "/_apis/wit/workitems/$Task?api-version=2.2",
headers = headers,
body = childPatchDocumentBody
};
batchRequests[1] = new WorkItemBatchPost.BatchRequest {
method = "PATCH",
uri = '/' + projectName + "/_apis/wit/workitems/$Task?api-version=2.2",
headers = headers,
body = childPatchDocumentBody
};
using (var client = new HttpClient())
{
@ -70,10 +62,7 @@ namespace VstsRestApiSamples.WorkItemTracking
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);
// serialize the fields array into a json string
var batchRequest = new StringContent(JsonConvert.SerializeObject(batchRequests), Encoding.UTF8, "application/json");
// set the httpmethod to Patch
var method = new HttpMethod("POST");
// send the request

Просмотреть файл

@ -0,0 +1,438 @@
using Newtonsoft.Json;
using System;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using VstsRestApiSamples.ViewModels;
using VstsRestApiSamples.ViewModels.WorkItemTracking;
namespace VstsRestApiSamples.WorkItemTracking
{
/// <summary>
/// otherwise known as area paths
/// </summary>
public class ClassificationNodes
{
readonly IConfiguration _configuration;
readonly string _credentials;
public ClassificationNodes(IConfiguration configuration)
{
_configuration = configuration;
_credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken)));
}
public GetNodesResponse.Nodes GetAreas(string project)
{
GetNodesResponse.Nodes viewModel = new GetNodesResponse.Nodes();
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(_configuration.UriString);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);
HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/classificationNodes/areas?$depth=2&api-version=2.2").Result;
if (response.IsSuccessStatusCode)
{
viewModel = response.Content.ReadAsAsync<GetNodesResponse.Nodes>().Result;
}
viewModel.HttpStatusCode = response.StatusCode;
return viewModel;
}
}
public GetNodesResponse.Nodes GetIterations(string project)
{
GetNodesResponse.Nodes viewModel = new GetNodesResponse.Nodes();
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(_configuration.UriString);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);
HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/classificationNodes/iterations?$depth=2&api-version=2.2").Result;
if (response.IsSuccessStatusCode)
{
viewModel = response.Content.ReadAsAsync<GetNodesResponse.Nodes>().Result;
}
viewModel.HttpStatusCode = response.StatusCode;
return viewModel;
}
}
public GetNodesResponse.Nodes GetArea(string project, string path)
{
GetNodesResponse.Nodes viewModel = new GetNodesResponse.Nodes();
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(_configuration.UriString);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);
HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/classificationNodes/areas/" + path + "?api-version=2.2").Result;
if (response.IsSuccessStatusCode)
{
viewModel = response.Content.ReadAsAsync<GetNodesResponse.Nodes>().Result;
}
viewModel.HttpStatusCode = response.StatusCode;
return viewModel;
}
}
public GetNodesResponse.Nodes GetIteration(string project, string path)
{
GetNodesResponse.Nodes viewModel = new GetNodesResponse.Nodes();
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(_configuration.UriString);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);
HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/classificationNodes/iterations/" + path + "?api-version=2.2").Result;
if (response.IsSuccessStatusCode)
{
viewModel = response.Content.ReadAsAsync<GetNodesResponse.Nodes>().Result;
}
viewModel.HttpStatusCode = response.StatusCode;
return viewModel;
}
}
public GetNodeResponse.Node CreateArea(string project, string path)
{
CreateUpdateNodeViewModel.Node node = new CreateUpdateNodeViewModel.Node()
{
name = path
};
GetNodeResponse.Node viewModel = new GetNodeResponse.Node();
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);
// serialize the fields array into a json string
var postValue = new StringContent(JsonConvert.SerializeObject(node), Encoding.UTF8, "application/json");
var method = new HttpMethod("POST");
// send the request
var request = new HttpRequestMessage(method, _configuration.UriString + project + "/_apis/wit/classificationNodes/areas?api-version=2.2") { Content = postValue };
var response = client.SendAsync(request).Result;
if (response.IsSuccessStatusCode)
{
viewModel = response.Content.ReadAsAsync<GetNodeResponse.Node>().Result;
viewModel.Message = "success";
}
viewModel.HttpStatusCode = response.StatusCode;
return viewModel;
}
}
public GetNodeResponse.Node CreateIteration(string project, string path)
{
CreateUpdateNodeViewModel.Node node = new CreateUpdateNodeViewModel.Node()
{
name = path
//attributes = new CreateUpdateNodeViewModel.Attributes()
//{
// startDate = startDate,
// finishDate = finishDate
//}
};
GetNodeResponse.Node viewModel = new GetNodeResponse.Node();
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);
// serialize the fields array into a json string
var postValue = new StringContent(JsonConvert.SerializeObject(node), Encoding.UTF8, "application/json");
var method = new HttpMethod("POST");
// send the request
var request = new HttpRequestMessage(method, _configuration.UriString + project + "/_apis/wit/classificationNodes/iterations?api-version=2.2") { Content = postValue };
var response = client.SendAsync(request).Result;
if (response.IsSuccessStatusCode)
{
viewModel = response.Content.ReadAsAsync<GetNodeResponse.Node>().Result;
viewModel.Message = "success";
}
else
{
dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync<dynamic>();
Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result;
viewModel.Message = msg.ToString();
}
viewModel.HttpStatusCode = response.StatusCode;
return viewModel;
}
}
public GetNodeResponse.Node UpdateIterationDates(string project, string path, DateTime startDate, DateTime finishDate)
{
CreateUpdateNodeViewModel.Node node = new CreateUpdateNodeViewModel.Node()
{
//name = path,
attributes = new CreateUpdateNodeViewModel.Attributes()
{
startDate = startDate,
finishDate = finishDate
}
};
GetNodeResponse.Node viewModel = new GetNodeResponse.Node();
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);
// serialize the fields array into a json string
var patchValue = new StringContent(JsonConvert.SerializeObject(node), Encoding.UTF8, "application/json");
var method = new HttpMethod("PATCH");
// send the request
var request = new HttpRequestMessage(method, _configuration.UriString + project + "/_apis/wit/classificationNodes/iterations/" + path + "?api-version=2.2") { Content = patchValue };
var response = client.SendAsync(request).Result;
if (response.IsSuccessStatusCode)
{
viewModel = response.Content.ReadAsAsync<GetNodeResponse.Node>().Result;
viewModel.Message = "success";
}
else
{
dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync<dynamic>();
Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result;
viewModel.Message = msg.ToString();
}
viewModel.HttpStatusCode = response.StatusCode;
return viewModel;
}
}
public GetNodeResponse.Node RenameIteration(string project, string path, string newName)
{
CreateUpdateNodeViewModel.Node node = new CreateUpdateNodeViewModel.Node()
{
name = newName
};
GetNodeResponse.Node viewModel = new GetNodeResponse.Node();
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);
// serialize the fields array into a json string
var patchValue = new StringContent(JsonConvert.SerializeObject(node), Encoding.UTF8, "application/json");
var method = new HttpMethod("PATCH");
// send the request
var request = new HttpRequestMessage(method, _configuration.UriString + project + "/_apis/wit/classificationNodes/iterations/" + path + "?api-version=2.2") { Content = patchValue };
var response = client.SendAsync(request).Result;
if (response.IsSuccessStatusCode)
{
viewModel = response.Content.ReadAsAsync<GetNodeResponse.Node>().Result;
viewModel.Message = "success";
}
else
{
dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync<dynamic>();
Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result;
viewModel.Message = msg.ToString();
}
viewModel.HttpStatusCode = response.StatusCode;
return viewModel;
}
}
public GetNodeResponse.Node RenameArea(string project, string path, string newName)
{
CreateUpdateNodeViewModel.Node node = new CreateUpdateNodeViewModel.Node()
{
name = newName
};
GetNodeResponse.Node viewModel = new GetNodeResponse.Node();
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);
// serialize the fields array into a json string
var patchValue = new StringContent(JsonConvert.SerializeObject(node), Encoding.UTF8, "application/json");
var method = new HttpMethod("PATCH");
// send the request
var request = new HttpRequestMessage(method, _configuration.UriString + project + "/_apis/wit/classificationNodes/areas/" + path + "?api-version=2.2") { Content = patchValue };
var response = client.SendAsync(request).Result;
if (response.IsSuccessStatusCode)
{
viewModel = response.Content.ReadAsAsync<GetNodeResponse.Node>().Result;
viewModel.Message = "success";
}
viewModel.HttpStatusCode = response.StatusCode;
return viewModel;
}
}
public GetNodeResponse.Node MoveIteration(string project, string targetIteration, int id)
{
CreateUpdateNodeViewModel.Node node = new CreateUpdateNodeViewModel.Node()
{
id = id
};
GetNodeResponse.Node viewModel = new GetNodeResponse.Node();
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);
// serialize the fields array into a json string
var patchValue = new StringContent(JsonConvert.SerializeObject(node), Encoding.UTF8, "application/json");
var method = new HttpMethod("POST");
// send the request
var request = new HttpRequestMessage(method, _configuration.UriString + project + "/_apis/wit/classificationNodes/iterations/" + targetIteration + "?api-version=2.2") { Content = patchValue };
var response = client.SendAsync(request).Result;
if (response.IsSuccessStatusCode)
{
viewModel = response.Content.ReadAsAsync<GetNodeResponse.Node>().Result;
viewModel.Message = "success";
}
else
{
dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync<dynamic>();
Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result;
viewModel.Message = msg.ToString();
}
viewModel.HttpStatusCode = response.StatusCode;
return viewModel;
}
}
public GetNodeResponse.Node MoveArea(string project, string targetArea, int id)
{
CreateUpdateNodeViewModel.Node node = new CreateUpdateNodeViewModel.Node()
{
id = id
};
GetNodeResponse.Node viewModel = new GetNodeResponse.Node();
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);
// serialize the fields array into a json string
var patchValue = new StringContent(JsonConvert.SerializeObject(node), Encoding.UTF8, "application/json");
var method = new HttpMethod("POST");
// send the request
var request = new HttpRequestMessage(method, _configuration.UriString + project + "/_apis/wit/classificationNodes/areas/" + targetArea + "?api-version=2.2") { Content = patchValue };
var response = client.SendAsync(request).Result;
if (response.IsSuccessStatusCode)
{
viewModel = response.Content.ReadAsAsync<GetNodeResponse.Node>().Result;
viewModel.Message = "success";
}
viewModel.HttpStatusCode = response.StatusCode;
return viewModel;
}
}
public HttpStatusCode DeleteArea(string project, string areaPath, string reclassifyId)
{
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);
var method = new HttpMethod("DELETE");
// send the request
var request = new HttpRequestMessage(method, _configuration.UriString + project + "/_apis/wit/classificationNodes/areas/" + areaPath + "?$reclassifyId=" + reclassifyId + "&api-version=2.2");
var response = client.SendAsync(request).Result;
return response.StatusCode;
}
}
public HttpStatusCode DeleteIteration(string project, string iterationPath, string reclassifyId)
{
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);
var method = new HttpMethod("DELETE");
// send the request
var request = new HttpRequestMessage(method, _configuration.UriString + project + "/_apis/wit/classificationNodes/iterations/" + iterationPath + "?$reclassifyId=" + reclassifyId + "&api-version=2.2");
var response = client.SendAsync(request).Result;
return response.StatusCode;
}
}
}
}

Просмотреть файл

@ -20,9 +20,9 @@ namespace VstsRestApiSamples.WorkItemTracking
// / get list of all the fields in the account
// / </summary>
// / <returns>ListofWorkItemFieldsResponse.Fields</returns>
public ListofWorkItemFieldsResponse.Fields GetListOfWorkItemFields()
public GetWorkItemFieldsResponse.Fields GetListOfWorkItemFields()
{
ListofWorkItemFieldsResponse.Fields viewModel = new ListofWorkItemFieldsResponse.Fields();
GetWorkItemFieldsResponse.Fields viewModel = new GetWorkItemFieldsResponse.Fields();
using (var client = new HttpClient())
{
@ -35,7 +35,7 @@ namespace VstsRestApiSamples.WorkItemTracking
if (response.IsSuccessStatusCode)
{
viewModel = response.Content.ReadAsAsync<ListofWorkItemFieldsResponse.Fields>().Result;
viewModel = response.Content.ReadAsAsync<GetWorkItemFieldsResponse.Fields>().Result;
}
viewModel.HttpStatusCode = response.StatusCode;

Просмотреть файл

@ -17,14 +17,9 @@ namespace VstsRestApiSamples.WorkItemTracking
_credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken)));
}
// / <summary>
// / get list of queries by project
// / </summary>
// / <param name="project">project name or id</param>
// / <returns>ListofQueriesResponse.Queries</returns>
public ListofQueriesResponse.Queries GetListOfQueries(string project)
public GetQueriesResponse.Queries GetListOfQueries(string project)
{
ListofQueriesResponse.Queries viewModel = new ListofQueriesResponse.Queries();
GetQueriesResponse.Queries viewModel = new GetQueriesResponse.Queries();
using (var client = new HttpClient())
{
@ -38,7 +33,7 @@ namespace VstsRestApiSamples.WorkItemTracking
if (response.IsSuccessStatusCode)
{
viewModel = response.Content.ReadAsAsync<ListofQueriesResponse.Queries>().Result;
viewModel = response.Content.ReadAsAsync<GetQueriesResponse.Queries>().Result;
}
viewModel.HttpStatusCode = response.StatusCode;
@ -47,15 +42,9 @@ namespace VstsRestApiSamples.WorkItemTracking
}
}
// / <summary>
// / get list of queries by a specific folder path
// / </summary>
// / <param name="project">project name or id</param>
// / <param name="folderPath">folder path that must be url encoded</param>
// / <returns>ListofQueriesByFolderPath.Queries</returns>
public ListofQueriesByFolderPath.Queries GetListOfQueriesByFolderPath(string project, string folderPath)
public GetQueriesByFolderPath.Queries GetListOfQueriesByFolderPath(string project, string folderPath)
{
ListofQueriesByFolderPath.Queries viewModel = new ListofQueriesByFolderPath.Queries();
GetQueriesByFolderPath.Queries viewModel = new GetQueriesByFolderPath.Queries();
using (var client = new HttpClient())
{
@ -68,7 +57,7 @@ namespace VstsRestApiSamples.WorkItemTracking
if (response.IsSuccessStatusCode)
{
viewModel = response.Content.ReadAsAsync<ListofQueriesByFolderPath.Queries>().Result;
viewModel = response.Content.ReadAsAsync<GetQueriesByFolderPath.Queries>().Result;
}
viewModel.HttpStatusCode = response.StatusCode;
@ -77,15 +66,9 @@ namespace VstsRestApiSamples.WorkItemTracking
}
}
// / <summary>
// / get queries for a specific query path
// / </summary>
// / <param name="project">project name or id</param>
// / <param name="path">full query path</param>
// / <returns>ListofQueriesByFolderPath.Queries</returns>
public GetQueryResponse.Queries GetQueryByPath(string project, string path)
public GetQueriesByIdResponse.Queries GetQueryByPath(string project, string path)
{
GetQueryResponse.Queries viewModel = new GetQueryResponse.Queries();
GetQueriesByIdResponse.Queries viewModel = new GetQueriesByIdResponse.Queries();
using (var client = new HttpClient())
{
@ -98,7 +81,7 @@ namespace VstsRestApiSamples.WorkItemTracking
if (response.IsSuccessStatusCode)
{
viewModel = response.Content.ReadAsAsync<GetQueryResponse.Queries>().Result;
viewModel = response.Content.ReadAsAsync<GetQueriesByIdResponse.Queries>().Result;
}
viewModel.HttpStatusCode = response.StatusCode;
@ -107,15 +90,9 @@ namespace VstsRestApiSamples.WorkItemTracking
}
}
// / <summary>
// / get query or folder by id
// / </summary>
// / <param name="project">project name or id</param>
// / <param name="id">query id</param>
// / <returns>GetQueryByIdResponse.Queries</returns>
public GetQueryResponse.Queries GetQueryById(string project, string id)
public GetQueriesByIdResponse.Queries GetQueryById(string project, string id)
{
GetQueryResponse.Queries viewModel = new GetQueryResponse.Queries();
GetQueriesByIdResponse.Queries viewModel = new GetQueriesByIdResponse.Queries();
using (var client = new HttpClient())
{
@ -128,7 +105,7 @@ namespace VstsRestApiSamples.WorkItemTracking
if (response.IsSuccessStatusCode)
{
viewModel = response.Content.ReadAsAsync<GetQueryResponse.Queries>().Result;
viewModel = response.Content.ReadAsAsync<GetQueriesByIdResponse.Queries>().Result;
}
viewModel.HttpStatusCode = response.StatusCode;

Просмотреть файл

@ -0,0 +1,232 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using VstsRestApiSamples.ViewModels;
using VstsRestApiSamples.ViewModels.WorkItemTracking;
namespace VstsRestApiSamples.WorkItemTracking
{
public class RecycleBin
{
readonly IConfiguration _configuration;
readonly string _credentials;
public RecycleBin(IConfiguration configuration)
{
_configuration = configuration;
_credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken)));
}
public GetItemsFromRecycleBinResponse.WorkItems GetDeletedItems(string project)
{
GetItemsFromRecycleBinResponse.WorkItems viewModel = new GetItemsFromRecycleBinResponse.WorkItems();
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(_configuration.UriString);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);
HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/recyclebin?api-version=3.0-preview").Result;
if (response.IsSuccessStatusCode)
{
viewModel = response.Content.ReadAsAsync<GetItemsFromRecycleBinResponse.WorkItems>().Result;
}
viewModel.HttpStatusCode = response.StatusCode;
return viewModel;
}
}
public GetItemFromRecycleBinResponse.WorkItem GetDeletedItem(string project, string id)
{
GetItemFromRecycleBinResponse.WorkItem viewModel = new GetItemFromRecycleBinResponse.WorkItem();
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(_configuration.UriString);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);
HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/recyclebin/" + id + "?api-version=3.0-preview").Result;
if (response.IsSuccessStatusCode)
{
viewModel = response.Content.ReadAsAsync<GetItemFromRecycleBinResponse.WorkItem>().Result;
}
viewModel.HttpStatusCode = response.StatusCode;
return viewModel;
}
}
public GetRestoredWorkItemResponse.WorkItem RestoreItem(string id)
{
GetRestoredWorkItemResponse.WorkItem viewModel = new GetRestoredWorkItemResponse.WorkItem();
var patchDocument = new {
IsDeleted = false
};
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);
var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json");
var method = new HttpMethod("PATCH");
var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/recyclebin/" + id + "?api-version=3.0-preview") { Content = patchValue };
var response = client.SendAsync(request).Result;
if (response.IsSuccessStatusCode)
{
viewModel = response.Content.ReadAsAsync<GetRestoredWorkItemResponse.WorkItem>().Result;
}
else
{
dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync<dynamic>();
Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result;
viewModel.Message = msg.ToString();
}
viewModel.HttpStatusCode = response.StatusCode;
return viewModel;
}
}
public GetRestoreMultipleWorkItemsResponse.Items RestoreMultipleItems(string[] ids)
{
GetRestoreMultipleWorkItemsResponse.Items viewModel = new GetRestoreMultipleWorkItemsResponse.Items();
WorkItemBatchPost.BatchRequest[] postDocument = new WorkItemBatchPost.BatchRequest[3];
Dictionary<string, string> headers = new Dictionary<string, string>() {
{ "Content-Type", "application/json-patch+json" }
};
Object[] postBody = new Object[1];
postBody[0] = new { op = "replace", path = "/IsDeleted", value = "false" };
var i = 0;
foreach(var id in ids)
{
postDocument[i] = new WorkItemBatchPost.BatchRequest
{
method = "PATCH",
uri = "/_apis/wit/recyclebin/" + id + "?api-version=3.0-preview",
headers = headers,
body = postBody
};
i = i + 1;
};
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);
var postValue = new StringContent(JsonConvert.SerializeObject(postDocument), Encoding.UTF8, "application/json");
var method = new HttpMethod("POST");
var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/$batch?api-version=3.0-preview") { Content = postValue };
var response = client.SendAsync(request).Result;
if (response.IsSuccessStatusCode)
{
viewModel = response.Content.ReadAsAsync<GetRestoreMultipleWorkItemsResponse.Items>().Result;
}
viewModel.HttpStatusCode = response.StatusCode;
return viewModel;
}
}
public HttpStatusCode PermenentlyDeleteItem(string id)
{
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);
var method = new HttpMethod("DELETE");
var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/recyclebin/" + id + "?api-version=3.0-preview");
var response = client.SendAsync(request).Result;
if (! response.IsSuccessStatusCode)
{
dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync<dynamic>();
Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result;
}
return response.StatusCode;
}
}
public GetRestoreMultipleWorkItemsResponse.Items PeremenentlyDeleteMultipleItems(string[] ids)
{
GetRestoreMultipleWorkItemsResponse.Items viewModel = new GetRestoreMultipleWorkItemsResponse.Items();
WorkItemBatchPost.BatchRequest[] postDocument = new WorkItemBatchPost.BatchRequest[3];
Dictionary<string, string> headers = new Dictionary<string, string>() {
{ "Content-Type", "application/json-patch+json" }
};
var i = 0;
foreach (var id in ids)
{
postDocument[i] = new WorkItemBatchPost.BatchRequest
{
method = "DELETE",
uri = "/_apis/wit/recyclebin/" + id + "?api-version=3.0-preview",
headers = headers
};
i = i + 1;
};
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);
var postValue = new StringContent(JsonConvert.SerializeObject(postDocument), Encoding.UTF8, "application/json");
var method = new HttpMethod("POST");
var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/$batch?api-version=3.0-preview") { Content = postValue };
var response = client.SendAsync(request).Result;
if (response.IsSuccessStatusCode)
{
viewModel = response.Content.ReadAsAsync<GetRestoreMultipleWorkItemsResponse.Items>().Result;
}
else
{
dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync<dynamic>();
Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result;
viewModel.Message = msg.ToString();
}
viewModel.HttpStatusCode = response.StatusCode;
return viewModel;
}
}
}
}

Просмотреть файл

@ -0,0 +1,190 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using VstsRestApiSamples.ViewModels.WorkItemTracking;
namespace VstsRestApiSamples.WorkItemTracking
{
public class Reporting
{
readonly IConfiguration _configuration;
readonly string _credentials;
public Reporting(IConfiguration configuration)
{
_configuration = configuration;
_credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken)));
}
public BatchOfWorkItemLinksResponse.WorkItemLinks GetBatchOfWorkItemLinks(string project, DateTime startDateTime)
{
BatchOfWorkItemLinksResponse.WorkItemLinks viewModel = new BatchOfWorkItemLinksResponse.WorkItemLinks();
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(_configuration.UriString);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",_credentials);
HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/reporting/workitemlinks?startDateTime=" + startDateTime.ToShortDateString() + "&api-version=2.0").Result;
if (response.IsSuccessStatusCode)
{
viewModel = response.Content.ReadAsAsync<BatchOfWorkItemLinksResponse.WorkItemLinks>().Result;
}
viewModel.HttpStatusCode = response.StatusCode;
return viewModel;
}
}
public BatchOfWorkItemLinksResponse.WorkItemLinks GetBatchOfWorkItemLinksAll()
{
BatchOfWorkItemLinksResponse.WorkItemLinks viewModel = new BatchOfWorkItemLinksResponse.WorkItemLinks();
BatchOfWorkItemLinksResponse.WorkItemLinks tempViewModel = new BatchOfWorkItemLinksResponse.WorkItemLinks();
List<BatchOfWorkItemLinksResponse.Value> list = new List<BatchOfWorkItemLinksResponse.Value>();
HttpResponseMessage response;
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(_configuration.UriString);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",_credentials);
response = client.GetAsync("_apis/wit/reporting/workitemlinks?api-version=2.0").Result;
if (!response.IsSuccessStatusCode)
{
viewModel.HttpStatusCode = response.StatusCode;
return viewModel;
}
else
{
// read from response
tempViewModel = response.Content.ReadAsAsync<BatchOfWorkItemLinksResponse.WorkItemLinks>().Result;
// and add values to list object
list.AddRange(tempViewModel.values);
// keep looping through the list untill done
// loop thru until isLastBatch = true
while (!tempViewModel.isLastBatch)
{
// using watermarked nextLink value, get next page from list
response = client.GetAsync(tempViewModel.nextLink).Result;
if (!response.IsSuccessStatusCode)
{
viewModel.HttpStatusCode = response.StatusCode;
return viewModel;
}
else
{
// read and add to your list
tempViewModel = response.Content.ReadAsAsync<BatchOfWorkItemLinksResponse.WorkItemLinks>().Result;
list.AddRange(tempViewModel.values);
}
}
// loaded all pages, now set value in viewModel with list object so we can send the entire list back
viewModel.values = list.ToArray<BatchOfWorkItemLinksResponse.Value>();
viewModel.HttpStatusCode = response.StatusCode;
return viewModel;
}
}
}
public BatchOfWorkItemRevisionsResponse.WorkItemRevisions GetBatchOfWorkItemRevisionsByDate(string project, DateTime startDateTime)
{
BatchOfWorkItemRevisionsResponse.WorkItemRevisions viewModel = new BatchOfWorkItemRevisionsResponse.WorkItemRevisions();
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(_configuration.UriString);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",_credentials);
HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/reporting/workItemRevisions?startDateTime=" + startDateTime.ToShortDateString() + "&api-version=2.0").Result;
if (response.IsSuccessStatusCode)
{
viewModel = response.Content.ReadAsAsync<BatchOfWorkItemRevisionsResponse.WorkItemRevisions>().Result;
}
viewModel.HttpStatusCode = response.StatusCode;
return viewModel;
}
}
public BatchOfWorkItemRevisionsResponse.WorkItemRevisions GetBatchOfWorkItemRevisionsAll()
{
BatchOfWorkItemRevisionsResponse.WorkItemRevisions tempViewModel = new BatchOfWorkItemRevisionsResponse.WorkItemRevisions();
BatchOfWorkItemRevisionsResponse.WorkItemRevisions viewModel = new BatchOfWorkItemRevisionsResponse.WorkItemRevisions();
HttpResponseMessage response;
List<BatchOfWorkItemRevisionsResponse.Value> list = new List<BatchOfWorkItemRevisionsResponse.Value>();
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(_configuration.UriString);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",_credentials);
response = client.GetAsync("_apis/wit/reporting/workItemRevisions?api-version=2.0").Result;
if (!response.IsSuccessStatusCode)
{
viewModel.HttpStatusCode = response.StatusCode;
return viewModel;
}
else
{
// read from response
tempViewModel = response.Content.ReadAsAsync<BatchOfWorkItemRevisionsResponse.WorkItemRevisions>().Result;
// add values to the list object
list.AddRange(tempViewModel.values);
// keep looping through the list untill done
// loop thru until isLastBatch = true
while (!tempViewModel.isLastBatch)
{
response = client.GetAsync(tempViewModel.nextLink).Result;
if (!response.IsSuccessStatusCode)
{
viewModel.HttpStatusCode = response.StatusCode;
return viewModel;
}
else
{
// read response
tempViewModel = response.Content.ReadAsAsync<BatchOfWorkItemRevisionsResponse.WorkItemRevisions>().Result;
// add new batch to my list
list.AddRange(tempViewModel.values);
}
}
viewModel.HttpStatusCode = response.StatusCode;
viewModel.values = list.ToArray<BatchOfWorkItemRevisionsResponse.Value>();
return viewModel;
}
}
}
}
}

Просмотреть файл

@ -3,8 +3,7 @@ using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using Newtonsoft.Json;
using VstsRestApiSamples.ViewModels.WorkItemTracking;
using System.Collections.Generic;
namespace VstsRestApiSamples.WorkItemTracking
{
@ -307,6 +306,58 @@ namespace VstsRestApiSamples.WorkItemTracking
}
}
public string AddHyperLinkToBug()
{
string _id = _configuration.WorkItemId;
Object[] patchDocument = new Object[1];
// change some values on a few fields
patchDocument[0] = new
{
op = "add",
path = "/relations/-",
value = new
{
rel = "Hyperlink",
url = "http://www.visualstudio.com/team-services",
attributes = new
{
comment = "Visaul Studio Team Services"
}
}
};
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);
// serialize the fields array into a json string
var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call
// set the httpmethod to Patch
var method = new HttpMethod("PATCH");
// send the request
var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + _id + "?api-version=2.2") { Content = patchValue };
var response = client.SendAsync(request).Result;
if (response.IsSuccessStatusCode)
{
var result = response.Content.ReadAsStringAsync().Result;
return "success";
}
else
{
dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync<dynamic>();
Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result;
return (msg.ToString());
}
}
}
public string AddAttachmentToBug()
{
string _id = _configuration.WorkItemId;
@ -316,8 +367,16 @@ namespace VstsRestApiSamples.WorkItemTracking
String[] breakApart = _filePath.Split('\\');
int length = breakApart.Length;
string fileName = breakApart[length - 1];
Byte[] bytes;
Byte[] bytes = System.IO.File.ReadAllBytes(@_filePath);
try
{
bytes = System.IO.File.ReadAllBytes(@_filePath);
}
catch(System.IO.FileNotFoundException)
{
return @"file not found: " + _filePath;
}
using (var client = new HttpClient())
{
@ -416,9 +475,37 @@ namespace VstsRestApiSamples.WorkItemTracking
if (response.IsSuccessStatusCode)
{
var result = response.Content.ReadAsStringAsync().Result;
return "success";
}
return "success";
return "failure";
}
}
public string GetListOfWorkItemFields(string fieldName)
{
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(_configuration.UriString);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);
HttpResponseMessage response = client.GetAsync("_apis/wit/fields?api-version=2.2").Result;
if (response.IsSuccessStatusCode)
{
WorkItemFields result = response.Content.ReadAsAsync<WorkItemFields>().Result;
List<WorkItemField> list = new List<WorkItemField>(result.value);
var item = list.Find(x => x.name == fieldName);
return item.referenceName;
}
return "failure";
}
}
}
@ -430,6 +517,7 @@ namespace VstsRestApiSamples.WorkItemTracking
public string path { get; set; }
public string url { get; set; }
}
public class WorkItemQueryResult
{
public string queryType { get; set; }
@ -438,20 +526,38 @@ namespace VstsRestApiSamples.WorkItemTracking
public Column[] columns { get; set; }
public Workitem[] workItems { get; set; }
}
public class Workitem
{
public int id { get; set; }
public string url { get; set; }
}
public class Column
{
public string referenceName { get; set; }
public string name { get; set; }
public string url { get; set; }
}
public class AttachmentReference
{
public string id { get; set; }
public string url { get; set; }
}
public class WorkItemFields
{
public int count { get; set; }
public WorkItemField[] value { get; set; }
}
public class WorkItemField
{
public string name { get; set; }
public string referenceName { get; set; }
public string type { get; set; }
public bool readOnly { get; set; }
public string url { get; set; }
}
}

Просмотреть файл

@ -23,9 +23,9 @@ namespace VstsRestApiSamples.WorkItemTracking
// / </summary>
// / <param name="id">query id</param>
// / <returns></returns>
public GetWorkItemsResponse.Results GetListOfWorkItems_ByQueryId(string project, string id)
public GetWorkItemsWIQLResponse.Results GetListOfWorkItems_ByQueryId(string project, string id)
{
GetWorkItemsResponse.Results viewModel = new GetWorkItemsResponse.Results();
GetWorkItemsWIQLResponse.Results viewModel = new GetWorkItemsWIQLResponse.Results();
using (var client = new HttpClient())
{
@ -38,7 +38,7 @@ namespace VstsRestApiSamples.WorkItemTracking
if (response.IsSuccessStatusCode)
{
viewModel = response.Content.ReadAsAsync<GetWorkItemsResponse.Results>().Result;
viewModel = response.Content.ReadAsAsync<GetWorkItemsWIQLResponse.Results>().Result;
}
viewModel.HttpStatusCode = response.StatusCode;
@ -52,9 +52,9 @@ namespace VstsRestApiSamples.WorkItemTracking
// / </summary>
// / <param name="project"></param>
// / <returns></returns>
public GetWorkItemsResponse.Results GetListOfWorkItems_ByWiql(string project)
public GetWorkItemsWIQLResponse.Results GetListOfWorkItems_ByWiql(string project)
{
GetWorkItemsResponse.Results viewModel = new GetWorkItemsResponse.Results();
GetWorkItemsWIQLResponse.Results viewModel = new GetWorkItemsWIQLResponse.Results();
// create wiql object
Object wiql = new {
@ -83,7 +83,7 @@ namespace VstsRestApiSamples.WorkItemTracking
if (response.IsSuccessStatusCode)
{
viewModel = response.Content.ReadAsAsync<GetWorkItemsResponse.Results>().Result;
viewModel = response.Content.ReadAsAsync<GetWorkItemsWIQLResponse.Results>().Result;
}
viewModel.HttpStatusCode = response.StatusCode;

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net452" />
<package id="Microsoft.IdentityModel.Clients.ActiveDirectory" version="3.13.8" targetFramework="net452" />

Просмотреть файл

@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -14,8 +14,11 @@ namespace VstsClientLibrariesSamples.Tests
public string ApplicationId { get; set; }
public string UriString { get { return string.Format("https://{0}.visualstudio.com", AccountName); } }
public Uri CollectionUri { get { return new Uri(UriString); } }
public string CollectionId { get; set; }
public string PersonalAccessToken { get; set; }
public string Project { get; set; }
public string Team { get; set; }
public string MoveToProject { get; set; }
public string Query { get; set; }
public string Identity { get; set; }
public string WorkItemIds { get; set; }

Просмотреть файл

@ -1,4 +1,4 @@
using System;
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using VstsClientLibrariesSamples.GettingStarted;
@ -22,7 +22,7 @@ namespace VstsClientLibrariesSamples.Tests.GettingStarted
}
[TestMethod, TestCategory("Client Libraries - Authentication")]
public void GettingStarted_Authentication_InteractiveADAL_Success()
public void CL_GettingStarted_Authentication_InteractiveADAL_Success()
{
// arrange
Authentication authentication = new Authentication();
@ -35,7 +35,7 @@ namespace VstsClientLibrariesSamples.Tests.GettingStarted
}
[TestMethod, TestCategory("Client Libraries - Authentication")]
public void GettingStarted_Authentication_InteractiveADALExchangeGraphTokenForVSTSToken_Success()
public void CL_GettingStarted_Authentication_InteractiveADALExchangeGraphTokenForVSTSToken_Success()
{
// arrange
Authentication authentication = new Authentication();
@ -48,7 +48,7 @@ namespace VstsClientLibrariesSamples.Tests.GettingStarted
}
[TestMethod, TestCategory("Client Libraries - Authentication")]
public void GettingStarted_Authentication_NonInteractivePersonalAccessToken_Success()
public void CL_GettingStarted_Authentication_NonInteractivePersonalAccessToken_Success()
{
// arrange
Authentication authentication = new Authentication();
@ -59,7 +59,5 @@ namespace VstsClientLibrariesSamples.Tests.GettingStarted
// assert
Assert.IsNotNull(result);
}
}
}

Просмотреть файл

@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
@ -13,8 +13,11 @@ namespace VstsClientLibrariesSamples.Tests
{
configuration.AccountName = ConfigurationSettings.AppSettings["appsetting.accountname"].ToString();
configuration.ApplicationId = ConfigurationSettings.AppSettings["appsetting.applicationId"].ToString();
configuration.CollectionId = ConfigurationSettings.AppSettings["appsetting.collectionid"].ToString();
configuration.PersonalAccessToken = ConfigurationSettings.AppSettings["appsetting.pat"].ToString();
configuration.Project = ConfigurationSettings.AppSettings["appsetting.project"].ToString();
configuration.Team = ConfigurationSettings.AppSettings["appsetting.team"].ToString();
configuration.MoveToProject = ConfigurationSettings.AppSettings["appsetting.movetoproject"].ToString();
configuration.Query = ConfigurationSettings.AppSettings["appsetting.query"].ToString();
configuration.Identity = ConfigurationSettings.AppSettings["appsetting.identity"].ToString();
configuration.WorkItemIds = ConfigurationSettings.AppSettings["appsetting.workitemids"].ToString();

Просмотреть файл

@ -0,0 +1,60 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using VstsClientLibrariesSamples.ProjectsAndTeams;
using Microsoft.TeamFoundation.Core.WebApi;
using System.Collections.Generic;
namespace VstsClientLibrariesSamples.Tests.ProjectsAndTeams
{
[TestClass]
public class ProjectCollectionsTest
{
private IConfiguration _configuration = new Configuration();
[TestInitialize]
public void TestInitialize()
{
InitHelper.GetConfiguration(_configuration);
}
[TestCleanup]
public void TestCleanup()
{
_configuration = null;
}
[TestMethod, TestCategory("Client Libraries")]
public void CL_ProjectsAndTeams_ProjectCollections_GetProjectCollections_Success()
{
// arrange
ProjectCollections projectCollections = new ProjectCollections(_configuration);
// act
IEnumerable<TeamProjectCollectionReference> results = projectCollections.GetProjectCollections();
// assert
Assert.IsNotNull(results);
}
[TestMethod, TestCategory("Client Libraries")]
public void CL_ProjectsAndTeams_ProjectCollections_GetProjectCollection_Success()
{
// arrange
ProjectCollections projectCollections = new ProjectCollections(_configuration);
// act
try
{
TeamProjectCollectionReference result = projectCollections.GetProjectCollection(_configuration.CollectionId);
// assert
Assert.AreEqual(result.Id, new System.Guid(_configuration.CollectionId));
}
catch (System.AggregateException)
{
Assert.Inconclusive("project collection'" + _configuration.Project + "' not found");
}
}
}
}

Просмотреть файл

@ -1,46 +0,0 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using VstsClientLibrariesSamples.ProjectsAndTeams;
using Microsoft.TeamFoundation.Core.WebApi;
namespace VstsClientLibrariesSamples.Tests.ProjectsAndTeams
{
[TestClass]
public class ProjectsTest
{
private IConfiguration _configuration = new Configuration();
[TestInitialize]
public void TestInitialize()
{
InitHelper.GetConfiguration(_configuration);
}
[TestCleanup]
public void TestCleanup()
{
_configuration = null;
}
[TestMethod, TestCategory("Client Libraries")]
public void WorkItemTracking_ProjectsAndTeams_GetProjectByName_Success()
{
// arrange
Projects projects = new Projects(_configuration);
// act
try
{
TeamProjectReference result = projects.GetProjectByName(_configuration.Project);
// assert
Assert.AreEqual(_configuration.Project, result.Name);
}
catch (System.AggregateException)
{
Assert.Inconclusive("project '" + _configuration.Project + "' not found");
}
}
}
}

Просмотреть файл

@ -0,0 +1,146 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using VstsClientLibrariesSamples.ProjectsAndTeams;
namespace VstsClientLibrariesSamples.Tests.ProjectsAndTeams
{
[TestClass]
public class SamplesTest
{
private IConfiguration _configuration = new Configuration();
[TestInitialize]
public void TestInitialize()
{
InitHelper.GetConfiguration(_configuration);
}
[TestCleanup]
public void TestCleanup()
{
_configuration = null;
}
[TestMethod, TestCategory("Client Libraries")]
public void CL_Samples_ProjectsAndTeams_GetTeams_Success()
{
// arrange
Samples request = new Samples(_configuration);
// act
try
{
var result = request.GetTeams();
// assert
Assert.IsNotNull(result);
}
catch (System.AggregateException)
{
Assert.Inconclusive("project '" + _configuration.Project + "' not found");
}
}
[TestMethod, TestCategory("Client Libraries")]
public void CL_Samples_ProjectsAndTeams_Samples_GetTeam_Success()
{
// arrange
Samples request = new Samples(_configuration);
// act
try
{
var result = request.GetTeam();
// assert
Assert.AreEqual("My new team", result.Name);
}
catch (System.AggregateException)
{
Assert.Inconclusive("team '" + _configuration.Team + "' not found");
}
}
[TestMethod, TestCategory("Client Libraries")]
public void CL_Samples_ProjectsAndTeams_GetTeamMembers_Success()
{
// arrange
Samples request = new Samples(_configuration);
// act
try
{
var result = request.GetTeamMembers();
// assert
Assert.IsNotNull(result);
}
catch (System.AggregateException)
{
Assert.Inconclusive("team '" + _configuration.Team + "' not found");
}
}
[TestMethod, TestCategory("Client Libraries")]
public void CL_Samples_ProjectsAndTeams_CreateTeam_Success()
{
// arrange
Samples request = new Samples(_configuration);
// act
try
{
var result = request.CreateTeam();
// assert
Assert.AreEqual("My new team", result.Name);
}
catch (System.AggregateException)
{
Assert.Inconclusive("'My new team' already exists");
}
}
[TestMethod, TestCategory("Client Libraries")]
public void ProjectsAndTeams_Samples_UpdateTeam_Success()
{
// arrange
Samples request = new Samples(_configuration);
// act
try
{
var result = request.UpdateTeam();
// assert
Assert.AreEqual("My new team", result.Name);
}
catch (System.AggregateException)
{
Assert.Inconclusive("'My new team' does not exist");
}
}
[TestMethod, TestCategory("Client Libraries")]
public void CL_Samples_ProjectsAndTeams_DeleteTeam_Success()
{
// arrange
Samples request = new Samples(_configuration);
// act
try
{
request.DeleteTeam();
var result = request.GetTeam();
// assert
Assert.AreEqual("My new team", result.Name);
}
catch (System.AggregateException)
{
Assert.Inconclusive("'My new team' does not exist");
}
}
}
}

Просмотреть файл

@ -0,0 +1,171 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using VstsClientLibrariesSamples.ProjectsAndTeams;
using Microsoft.TeamFoundation.Core.WebApi;
using System.Collections.Generic;
using Microsoft.VisualStudio.Services.Operations;
namespace VstsClientLibrariesSamples.Tests.ProjectsAndTeams
{
[TestClass]
public class TeamProjectsTest
{
private IConfiguration _configuration = new Configuration();
[TestInitialize]
public void TestInitialize()
{
InitHelper.GetConfiguration(_configuration);
}
[TestCleanup]
public void TestCleanup()
{
_configuration = null;
}
[TestMethod, TestCategory("Client Libraries")]
public void CL_ProjectsAndTeams_Projects_GetTeamProjects_Success()
{
// arrange
TeamProjects projects = new TeamProjects(_configuration);
// act
IEnumerable<TeamProjectReference> results = projects.GetTeamProjects();
// assert
Assert.IsNotNull(results);
}
[TestMethod, TestCategory("Client Libraries")]
public void CL_ProjectsAndTeams_Projects_GetTeamProjectsByState_Success()
{
// arrange
TeamProjects projects = new TeamProjects(_configuration);
// act
IEnumerable<TeamProjectReference> results = projects.GetTeamProjectsByState();
// assert
Assert.IsNotNull(results);
}
[TestMethod, TestCategory("Client Libraries")]
public void CL_ProjectsAndTeams_Projects_GetTeamProject_Success()
{
// arrange
TeamProjects projects = new TeamProjects(_configuration);
// act
try
{
TeamProjectReference result = projects.GetTeamProjectWithCapabilities(_configuration.Project);
// assert
Assert.AreEqual(_configuration.Project, result.Name);
}
catch (System.AggregateException)
{
Assert.Inconclusive("project '" + _configuration.Project + "' not found");
}
}
[TestMethod, TestCategory("Client Libraries")]
public void CL_ProjectsAndTeams_Projects_CreateTeamProject_Success()
{
// arrange
TeamProjects projects = new TeamProjects(_configuration);
string name = System.Guid.NewGuid().ToString().ToLower().Substring(0, 30);
// act
OperationReference result = projects.CreateTeamProject(name);
// assert
Assert.AreNotEqual(result.Status, OperationStatus.Failed);
}
[TestMethod, TestCategory("Client Libraries")]
public void CL_ProjectsAndTeams_Projects_RenameTeamProject_Success()
{
// arrange
TeamProjects projects = new TeamProjects(_configuration);
string name = System.Guid.NewGuid().ToString().ToLower().Substring(0, 30);
// act
//create the project
OperationReference createResult = projects.CreateTeamProject(name);
//TODO: Instead of sleep, monitor the status ("online")
System.Threading.Thread.Sleep(5000);
//get the project so we can get the id
TeamProjectReference getResult = projects.GetTeamProjectWithCapabilities(name);
//rename the project
OperationReference renameResult = projects.RenameTeamProject(getResult.Id, "Vandelay Scrum Project");
//TODO: keep checking the operation untill it failed or is done
// assert
Assert.AreNotEqual(createResult.Status, OperationStatus.Failed);
Assert.AreNotEqual(renameResult.Status, OperationStatus.Failed);
}
[TestMethod, TestCategory("Client Libraries")]
public void CL_ProjectsAndTeams_Projects_ChangeTeamProjectDescription_Success()
{
// arrange
TeamProjects projects = new TeamProjects(_configuration);
string name = System.Guid.NewGuid().ToString().ToLower().Substring(0, 30);
// act
//create project
OperationReference createResult = projects.CreateTeamProject(name);
//TODO: Instead of sleep, monitor the status ("online")
System.Threading.Thread.Sleep(5000);
//get the project we just created so we can get the id
TeamProjectReference getResult = projects.GetTeamProjectWithCapabilities(name);
//change project desription
OperationReference updateResult = projects.ChangeTeamProjectDescription(getResult.Id, "This is my new project description");
//TODO: keep checking the operation untill it failed or is done
// assert
Assert.AreNotEqual(createResult.Status, OperationStatus.Failed);
Assert.AreNotEqual(updateResult.Status, OperationStatus.Failed);
}
[TestMethod, TestCategory("Client Libraries")]
public void CL_ProjectsAndTeams_Projects_DeleteTeamProject_Success()
{
// arrange
TeamProjects projects = new TeamProjects(_configuration);
string name = System.Guid.NewGuid().ToString().ToLower().Substring(0, 30);
// act
//create a new project
OperationReference createResult = projects.CreateTeamProject(name);
//TODO: Instead of sleep, monitor the status ("online")
System.Threading.Thread.Sleep(5000);
//get the project we just created so we can get the id
TeamProjectReference getResult = projects.GetTeamProjectWithCapabilities(name);
//delete the project
OperationReference deleteResult = projects.DeleteTeamProject(getResult.Id);
//TODO: keep checking the operation untill it failed or is done
// assert
Assert.AreNotEqual(createResult.Status, OperationStatus.Failed);
Assert.AreNotEqual(deleteResult.Status, OperationStatus.Failed);
}
}
}

Просмотреть файл

@ -0,0 +1,152 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using VstsClientLibrariesSamples;
using VstsClientLibrariesSamples.ProjectsAndTeams;
using Microsoft.TeamFoundation.Core.WebApi;
namespace VstsClientLibrariesTeams.Tests.ProjectsAndTeams
{
[TestClass]
public class TeamsTest
{
private IConfiguration _configuration = new Configuration();
[TestInitialize]
public void TestInitialize()
{
VstsClientLibrariesSamples.Tests.InitHelper.GetConfiguration(_configuration);
}
[TestCleanup]
public void TestCleanup()
{
_configuration = null;
}
[TestMethod, TestCategory("Client Libraries")]
public void CL_ProjectsAndTeams_Teams_GetTeams_Success()
{
// arrange
Teams request = new Teams(_configuration);
// act
try
{
var result = request.GetTeams(_configuration.Project);
// assert
Assert.IsNotNull(result);
}
catch (System.AggregateException)
{
Assert.Inconclusive("project '" + _configuration.Project + "' not found");
}
}
[TestMethod, TestCategory("Client Libraries")]
public void CL_ProjectsAndTeams_Teams_GetTeam_Success()
{
// arrange
Teams request = new Teams(_configuration);
// act
try
{
var result = request.GetTeam(_configuration.Project, _configuration.Team);
// assert
Assert.AreEqual(_configuration.Team, result.Name);
}
catch (System.AggregateException)
{
Assert.Inconclusive("team '" + _configuration.Team + "' not found");
}
}
[TestMethod, TestCategory("Client Libraries")]
public void CL_ProjectsAndTeams_Teams_GetTeamMembers_Success()
{
// arrange
Teams request = new Teams(_configuration);
// act
try
{
var result = request.GetTeamMembers(_configuration.Project, _configuration.Team);
// assert
Assert.IsNotNull(result);
}
catch (System.AggregateException)
{
Assert.Inconclusive("team '" + _configuration.Team + "' not found");
}
}
[TestMethod, TestCategory("Client Libraries")]
public void CL_ProjectsAndTeams_Teams_CreateTeam_Success()
{
// arrange
Teams request = new Teams(_configuration);
WebApiTeam teamData = new WebApiTeam() { Name = "My new team" };
// act
try
{
var result = request.CreateTeam(_configuration.Project, teamData);
// assert
Assert.AreEqual("My new team", result.Name);
}
catch (System.AggregateException)
{
Assert.Inconclusive("'My new team' already exists");
}
}
[TestMethod, TestCategory("Client Libraries")]
public void CL_ProjectsAndTeams_Teams_UpdateTeam_Success()
{
// arrange
Teams request = new Teams(_configuration);
WebApiTeam teamData = new WebApiTeam() { Name = "My new team", Description = "my awesome team description" };
// act
try
{
var result = request.UpdateTeam(_configuration.Project, "My new team", teamData);
// assert
Assert.AreEqual("My new team", result.Name);
}
catch (System.AggregateException)
{
Assert.Inconclusive("'My new team' does not exist");
}
}
[TestMethod, TestCategory("Client Libraries")]
public void CL_ProjectsAndTeams_Teams_DeleteTeam_Success()
{
// arrange
Teams request = new Teams(_configuration);
// act
try
{
request.DeleteTeam(_configuration.Project, "My new team");
var result = request.GetTeam(_configuration.Project, "My new team");
// assert
Assert.AreEqual("My new team", result.Name);
}
catch (System.AggregateException)
{
Assert.Inconclusive("'My new team' does not exist");
}
}
}
}

Просмотреть файл

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@ -88,11 +88,10 @@
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.Services.WebApi, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.VisualStudio.Services.Client.15.109.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<HintPath>..\packages\Newtonsoft.Json.9.0.2-beta1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
@ -124,10 +123,17 @@
<Compile Include="Configuration.cs" />
<Compile Include="GettingStarted\AuthenticationTest.cs" />
<Compile Include="InitHelper.cs" />
<Compile Include="ProjectsAndTeams\ProjectsTest.cs" />
<Compile Include="ProjectsAndTeams\ProjectCollectionsTest.cs" />
<Compile Include="ProjectsAndTeams\TeamProjectsTest.cs" />
<Compile Include="ProjectsAndTeams\TeamsTest.cs" />
<Compile Include="ProjectsAndTeams\SamplesTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="WorkItemTracking\SampleTest.cs" />
<Compile Include="WorkItemTracking\QueriesTest.cs" />
<Compile Include="WorkItemTracking\FieldsTest.cs" />
<Compile Include="WorkItemTracking\ClassifcationNodesTest.cs" />
<Compile Include="WorkItemTracking\AttachmentsTest.cs" />
<Compile Include="WorkItemTracking\RecyleBinTest.cs" />
<Compile Include="WorkItemTracking\WorkItemsTest.cs" />
</ItemGroup>
<ItemGroup>

Просмотреть файл

@ -0,0 +1,111 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using VstsClientLibrariesSamples.WorkItemTracking;
using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models;
namespace VstsClientLibrariesSamples.Tests.WorkItemTracking
{
[TestClass]
public class AttachmentsTest
{
private IConfiguration _configuration = new Configuration();
[TestInitialize]
public void TestInitialize()
{
InitHelper.GetConfiguration(_configuration);
}
[TestCleanup]
public void TestCleanup()
{
_configuration = null;
}
[TestMethod, TestCategory("Client Libraries")]
public void CL_WorkItemTracking_Attachements_UploadAttachmentTextFile_Success()
{
// arrange
Attachments request = new Attachments(_configuration);
string filePath = @"D:\temp\test.txt";
if (!System.IO.File.Exists(filePath))
{
Assert.Inconclusive("file not found");
}
// act
AttachmentReference attachmentReference = request.UploadAttachmentTextFile(filePath);
// assert
Assert.IsNotNull(attachmentReference);
request = null;
}
[TestMethod, TestCategory("Client Libraries")]
public void CL_WorkItemTracking_Attachements_UploadAttachmentBinaryFile_Success()
{
// arrange
Attachments request = new Attachments(_configuration);
string filePath = @"D:\temp\test.jpg";
if (!System.IO.File.Exists(filePath))
{
Assert.Inconclusive("file not found");
}
// act
AttachmentReference attachmentReference = request.UploadAttachmentBinaryFile(filePath);
// assert
Assert.IsNotNull(attachmentReference);
request = null;
}
[TestMethod, TestCategory("Client Libraries")]
public void CL_WorkItemTracking_Attachements_DownloadAttachmentTextFile_Success()
{
// arrange
Attachments request = new Attachments(_configuration);
string filePath = @"D:\temp\test.txt";
if (! System.IO.File.Exists(filePath))
{
Assert.Inconclusive("file not found");
}
// act
AttachmentReference attachmentReference = request.UploadAttachmentTextFile(filePath);
request.DownloadAttachment(attachmentReference.Id, @"D:\temp\attachment.txt");
// assert
Assert.IsTrue(System.IO.File.Exists(@"D:\temp\attachment.txt"));
request = null;
}
[TestMethod, TestCategory("Client Libraries")]
public void CL_WorkItemTracking_Attachements_DownloadAttachmentBinaryFile_Success()
{
// arrange
Attachments request = new Attachments(_configuration);
string filePath = @"D:\temp\test.jpg";
if (!System.IO.File.Exists(filePath))
{
Assert.Inconclusive("file not found");
}
// act
AttachmentReference attachmentReference = request.UploadAttachmentBinaryFile(filePath);
request.DownloadAttachment(attachmentReference.Id, @"D:\temp\attachment.jpg");
// assert
Assert.IsTrue(System.IO.File.Exists(@"D:\temp\attachment.txt"));
request = null;
}
}
}

Просмотреть файл

@ -0,0 +1,241 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models;
using VstsClientLibrariesSamples.WorkItemTracking;
namespace VstsClientLibrariesSamples.Tests.WorkItemTracking
{
[TestClass]
public class ClassificationNodesTest
{
private IConfiguration _configuration = new Configuration();
[TestInitialize]
public void TestInitialize()
{
InitHelper.GetConfiguration(_configuration);
}
[TestCleanup]
public void TestCleanup()
{
_configuration = null;
}
[TestMethod, TestCategory("Client Libraries")]
public void CL_WorkItemTracking_ClassificationNodes_GetAreas_Success()
{
// arrange
ClassificationNodes nodes = new ClassificationNodes(_configuration);
// act
var result = nodes.GetAreas(_configuration.Project, 100);
Assert.AreEqual("success", result);
}
[TestMethod, TestCategory("Client Libraries")]
public void CL_WorkItemTracking_ClassificationNodes_GetIterations_Success()
{
// arrange
ClassificationNodes nodes = new ClassificationNodes(_configuration);
// act
var result = nodes.GetIterations(_configuration.Project, 100);
//assert
Assert.IsNotNull(result);
}
[TestMethod, TestCategory("Client Libraries")]
public void CL_WorkItemTracking_ClassificationNodes_GetArea_Success()
{
// arrange
string name = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15);
ClassificationNodes nodes = new ClassificationNodes(_configuration);
// act
var createResult = nodes.CreateArea(_configuration.Project, name);
var getResult = nodes.GetArea(_configuration.Project, name);
//assert
Assert.IsNotNull(createResult);
Assert.IsNotNull(getResult);
}
[TestMethod, TestCategory("Client Libraries")]
public void WorkItemTracking_ClassificationNodes_GetIteration_Success()
{
// arrange
string name = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15);
ClassificationNodes nodes = new ClassificationNodes(_configuration);
// act
var createResult = nodes.CreateIteration(_configuration.Project, name);
var getResult = nodes.GetIteration(_configuration.Project, name);
//assert
Assert.IsNotNull(createResult);
Assert.IsNotNull(getResult);
}
[TestMethod, TestCategory("Client Libraries")]
public void CL_WorkItemTracking_ClassificationNodes_CreateArea_Success()
{
// arrange
string name = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15);
ClassificationNodes nodes = new ClassificationNodes(_configuration);
// act
var result = nodes.CreateArea(_configuration.Project, name);
// assert
Assert.IsNotNull(result);
}
[TestMethod, TestCategory("Client Libraries")]
public void WorkItemTracking_ClassificationNodes_CreateIteration_Success()
{
// arrange
ClassificationNodes nodes = new ClassificationNodes(_configuration);
string name = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15);
// act
var result = nodes.CreateIteration(_configuration.Project, name);
// assert
Assert.IsNotNull(result);
}
[TestMethod, TestCategory("Client Libraries")]
public void CL_WorkItemTracking_ClassificationNodes_RenameIteration_Success()
{
// arrange
string path = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15);
ClassificationNodes nodes = new ClassificationNodes(_configuration);
// act
var createResult = nodes.CreateIteration(_configuration.Project, path);
var renameResult = nodes.RenameIteration(_configuration.Project, path, path + "-rename");
//assert
Assert.IsNotNull(createResult);
Assert.IsNotNull(renameResult);
}
[TestMethod, TestCategory("Client Libraries")]
public void CL_WorkItemTracking_ClassificationNodes_RenameArea_Success()
{
// arrange
string path = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15);
ClassificationNodes nodes = new ClassificationNodes(_configuration);
// act
var createResult = nodes.CreateArea(_configuration.Project, path);
var renameResult = nodes.RenameArea(_configuration.Project, path, path + "-rename");
//assert
Assert.IsNotNull(createResult);
Assert.IsNotNull(renameResult);
}
[TestMethod, TestCategory("Client Libraries")]
public void WorkItemTracking_ClassificationNodes_UpdateIterationDates_Success()
{
// arrange
DateTime startDate = new DateTime(2016,12,28);
DateTime finishDate = new DateTime(2017,1,7);
string path = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15);
ClassificationNodes nodes = new ClassificationNodes(_configuration);
// act
var createResult = nodes.CreateIteration(_configuration.Project, path);
var updateResult = nodes.UpdateIterationDates(_configuration.Project, path, startDate, finishDate);
//assert
Assert.IsNotNull(createResult);
Assert.IsNotNull(updateResult);
}
[TestMethod, TestCategory("Client Libraries")]
[Ignore]
public void CL_WorkItemTracking_ClassificationNodes_MoveIteration_Success()
{
// arrange
string pathParent = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-Parent";
string pathChild = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-Child";
ClassificationNodes nodes = new ClassificationNodes(_configuration);
// act
var createParentResult = nodes.CreateIteration(_configuration.Project, pathParent);
var createChildResult = nodes.CreateIteration(_configuration.Project, pathChild);
var moveResult = nodes.MoveIteration(_configuration.Project, pathParent, createChildResult.Id);
//assert
Assert.IsNotNull(createParentResult);
Assert.IsNotNull(createChildResult);
Assert.IsNotNull(moveResult);
}
[TestMethod, TestCategory("Client Libraries")]
[Ignore]
public void CL_WorkItemTracking_ClassificationNodes_MoveArea_Success()
{
// arrange
string pathParent = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-Parent";
string pathChild = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-Child";
ClassificationNodes nodes = new ClassificationNodes(_configuration);
// act
var createParentResult = nodes.CreateArea(_configuration.Project, pathParent);
var createChildResult = nodes.CreateArea(_configuration.Project, pathChild);
var moveResult = nodes.MoveArea(_configuration.Project, pathParent, createChildResult.Id);
//assert
Assert.IsNotNull(createParentResult);
Assert.IsNotNull(createChildResult);
Assert.IsNotNull(moveResult);
}
[TestMethod, TestCategory("Client Libraries")]
public void CL_WorkItemTracking_ClassificationNodes_DeleteIteration_Success()
{
// arrange
string pathDelete = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-delete";
string pathMaster = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-master";
ClassificationNodes nodes = new ClassificationNodes(_configuration);
// act
var createDelete = nodes.CreateIteration(_configuration.Project, pathDelete);
var createMaster = nodes.CreateIteration(_configuration.Project, pathMaster);
nodes.DeleteIteration(_configuration.Project, pathDelete, createMaster.Id);
//assert
Assert.IsNotNull(createDelete);
Assert.IsNotNull(createMaster);
}
[TestMethod, TestCategory("Client Libraries")]
public void CL_WorkItemTracking_ClassificationNodes_DeleteArea_Success()
{
// arrange
string pathDelete = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-delete";
string pathMaster = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-master";
ClassificationNodes nodes = new ClassificationNodes(_configuration);
// act
var createDelete = nodes.CreateArea(_configuration.Project, pathDelete);
var createMaster = nodes.CreateArea(_configuration.Project, pathMaster);
nodes.DeleteArea(_configuration.Project, pathDelete, createMaster.Id);
//assert
Assert.IsNotNull(createDelete);
Assert.IsNotNull(createMaster);
}
}
}

Просмотреть файл

@ -0,0 +1,41 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using VstsClientLibrariesSamples.WorkItemTracking;
namespace VstsClientLibrariesSamples.Tests.WorkItemTracking
{
[TestClass]
public class FieldsTest
{
private IConfiguration _configuration = new Configuration();
[TestInitialize]
public void TestInitialize()
{
InitHelper.GetConfiguration(_configuration);
}
[TestCleanup]
public void TestCleanup()
{
_configuration = null;
}
[TestMethod]
public void CL_Fields_GetListOfWorkItemFields()
{
// arrange
Fields fields = new Fields(_configuration);
// act
var result = fields.GetListOfWorkItemFields("Title");
//assert
Assert.AreEqual("System.Title", result);
}
public void CL_Fields_GetField()
{
}
}
}

Просмотреть файл

@ -25,7 +25,7 @@ namespace VstsClientLibrariesSamples.Tests.WorkItemTracking
}
[TestMethod, TestCategory("Client Libraries")]
public void WorkItemTracking_Queries_GetQueryByName_Success()
public void CL_WorkItemTracking_Queries_GetQueryByName_Success()
{
// arrange
Queries queries = new Queries(_configuration);
@ -39,7 +39,7 @@ namespace VstsClientLibrariesSamples.Tests.WorkItemTracking
}
[TestMethod, TestCategory("Client Libraries")]
public void WorkItemTracking_Queries_ExecuteQuery_Success()
public void CL_WorkItemTracking_Queries_ExecuteQuery_Success()
{
// arrange
Queries queries = new Queries(_configuration);
@ -62,7 +62,7 @@ namespace VstsClientLibrariesSamples.Tests.WorkItemTracking
}
[TestMethod, TestCategory("Client Libraries")]
public void WorkItemTracking_Queries_ExecuteByWiql_Success()
public void CL_WorkItemTracking_Queries_ExecuteByWiql_Success()
{
// arrange
Queries queries = new Queries(_configuration);

Просмотреть файл

@ -0,0 +1,105 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using VstsClientLibrariesSamples.WorkItemTracking;
using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models;
namespace VstsClientLibrariesSamples.Tests.WorkItemTracking
{
[TestClass]
public class RecyleBinTest
{
private IConfiguration _configuration = new Configuration();
[TestInitialize]
public void TestInitialize()
{
InitHelper.GetConfiguration(_configuration);
}
[TestCleanup]
public void TestCleanup()
{
_configuration = null;
}
[TestMethod, TestCategory("Client Libraries")]
public void CL_WorkItemTracking_RecycleBin_GetDeletedItems_Success()
{
// arrange
RecycleBin recycleBin = new RecycleBin(_configuration);
WorkItems workItems = new WorkItems(_configuration);
WorkItem item = null;
int[] ids = new int[2];
// act
////create workitems, delete them, get from bin
item = workItems.CreateWorkItem(_configuration.Project);
workItems.DeleteWorkItem(Convert.ToInt32(item.Id));
ids[0] = Convert.ToInt32(item.Id);
item = workItems.CreateWorkItem(_configuration.Project);
workItems.DeleteWorkItem(Convert.ToInt32(item.Id));
ids[1] = Convert.ToInt32(item.Id);
var list = recycleBin.GetDeletedItems(_configuration.Project, ids);
//assert
Assert.IsNotNull(list);
Assert.AreEqual(2, list.Count);
}
[TestMethod, TestCategory("Client Libraries")]
public void CL_WorkItemTracking_RecycleBin_GetDeletedItem_Success()
{
// arrange
RecycleBin recycleBin = new RecycleBin(_configuration);
WorkItems workItems = new WorkItems(_configuration);
// act
////create workitem, delete them, get from bin by id
var item = workItems.CreateWorkItem(_configuration.Project);
workItems.DeleteWorkItem(Convert.ToInt32(item.Id));
var result = recycleBin.GetDeletedItem(Convert.ToInt32(item.Id));
//assert
Assert.IsNotNull(result);
Assert.AreEqual(result.Id, item.Id);
}
[TestMethod, TestCategory("Client Libraries")]
public void CL_WorkItemTracking_RecycleBin_RestoreItem_Success()
{
// arrange
RecycleBin recycleBin = new RecycleBin(_configuration);
WorkItems workItems = new WorkItems(_configuration);
// act
////create workitem, delete it, restore it, get it
var item = workItems.CreateWorkItem(_configuration.Project);
workItems.DeleteWorkItem(Convert.ToInt32(item.Id));
var restoreResult = recycleBin.RestoreItem(Convert.ToInt32(item.Id));
var getResult = workItems.GetWorkItem(Convert.ToInt32(item.Id));
//assert
Assert.IsNotNull(getResult);
Assert.AreEqual(getResult.Id, item.Id);
}
[TestMethod, TestCategory("Client Libraries")]
public void CL_WorkItemTracking_RecycleBin_PermenentlyDeleteItem_Success()
{
// arrange
RecycleBin recycleBin = new RecycleBin(_configuration);
WorkItems workItems = new WorkItems(_configuration);
// act
////create workitem, delete it, perm deleted it, try and get it
var item = workItems.CreateWorkItem(_configuration.Project);
workItems.DeleteWorkItem(Convert.ToInt32(item.Id));
recycleBin.PermenentlyDeleteItem(Convert.ToInt32(item.Id));
}
}
}

Просмотреть файл

@ -22,7 +22,7 @@ namespace VstsClientLibrariesSamples.Tests.QueryAndUpdateWorkItems
}
[TestMethod, TestCategory("Client Libraries")]
public void WorkItemTracking_Sample_QueryAndUpdateWorkItems_Success()
public void CL_Sample_WorkItemTracking_QueryAndUpdateWorkItems_Success()
{
// arrange
Sample sample = new Sample(_configuration);
@ -41,7 +41,7 @@ namespace VstsClientLibrariesSamples.Tests.QueryAndUpdateWorkItems
}
[TestMethod, TestCategory("Client Libraries")]
public void WorkItemTracking_Sample_CreateBug_Success()
public void CL_Sample_WorkItemTracking_CreateBug_Success()
{
// arrange
Sample sample = new Sample(_configuration);
@ -53,7 +53,7 @@ namespace VstsClientLibrariesSamples.Tests.QueryAndUpdateWorkItems
}
[TestMethod, TestCategory("Client Libraries")]
public void WorkItemTracking_Sample_CreateBugByPassingRules_Success()
public void CL_Sample_WorkItemTracking_CreateBugByPassingRules_Success()
{
// arrange
Sample sample = new Sample(_configuration);
@ -65,7 +65,7 @@ namespace VstsClientLibrariesSamples.Tests.QueryAndUpdateWorkItems
}
[TestMethod, TestCategory("Client Libraries")]
public void WorkItemTracking_Sample_UpdateBug_Success()
public void CL_Sample_WorkItemTracking_UpdateBug_Success()
{
// arrange
Sample sample = new Sample(_configuration);
@ -77,7 +77,7 @@ namespace VstsClientLibrariesSamples.Tests.QueryAndUpdateWorkItems
}
[TestMethod, TestCategory("Client Libraries")]
public void WorkItemTracking_Samples_AddLinkToBug_Success()
public void CL_Sample_WorkItemTracking_AddLinkToBug_Success()
{
// arrange
Sample sample = new Sample(_configuration);
@ -98,7 +98,27 @@ namespace VstsClientLibrariesSamples.Tests.QueryAndUpdateWorkItems
}
[TestMethod, TestCategory("Client Libraries")]
public void WorkItemTracking_Samples_AddAttachmentToBug_Success()
public void CL_Sample_WorkItemTracking_AddHyperLinkToBug_Success()
{
// arrange
Sample sample = new Sample(_configuration);
// act
var result = sample.AddHyperLinkToBug();
// assert
if (result.ToLower().Contains("relation already exists"))
{
Assert.Inconclusive("Link already exists on bug");
}
else
{
Assert.AreEqual("success", result);
}
}
[TestMethod, TestCategory("Client Libraries")]
public void CL_Sample_WorkItemTracking_AddAttachmentToBug_Success()
{
// arrange
Sample sample = new Sample(_configuration);
@ -110,9 +130,8 @@ namespace VstsClientLibrariesSamples.Tests.QueryAndUpdateWorkItems
Assert.AreEqual("success", result);
}
[TestMethod, TestCategory("Client Libraries")]
public void WorkItemTracking_Sample_AddCommentsToBug_Success()
public void CL_Sample_WorkItemTracking_AddCommentsToBug_Success()
{
// arrange
Sample sample = new Sample(_configuration);
@ -124,7 +143,7 @@ namespace VstsClientLibrariesSamples.Tests.QueryAndUpdateWorkItems
}
[TestMethod, TestCategory("Client Libraries")]
public void WorkItemTracking_Sample_QueryWorkItems_Query_Success()
public void CL_Sample_WorkItemTracking_QueryWorkItems_Query_Success()
{
// arrange
Sample sample = new Sample(_configuration);
@ -136,7 +155,7 @@ namespace VstsClientLibrariesSamples.Tests.QueryAndUpdateWorkItems
}
[TestMethod, TestCategory("Client Libraries")]
public void WorkItemTracking_Sample_QueryWorkItems_Query_QueryNotFound()
public void CL_Sample_WorkItemTracking_QueryWorkItems_Query_QueryNotFound()
{
// arrange
Sample sample = new Sample(_configuration);
@ -149,7 +168,7 @@ namespace VstsClientLibrariesSamples.Tests.QueryAndUpdateWorkItems
}
[TestMethod, TestCategory("Client Libraries")]
public void WorkItemTracking_Sample_QueryWorkItems_Wiql_Success()
public void CL_Sample_WorkItemTracking_QueryWorkItems_Wiql_Success()
{
// arrange
Sample sample = new Sample(_configuration);
@ -166,5 +185,18 @@ namespace VstsClientLibrariesSamples.Tests.QueryAndUpdateWorkItems
Assert.AreEqual("success", result);
}
}
[TestMethod, TestCategory("Client Libraries")]
public void CL_Sample_WorkItemTracking_GetListOfWorkItemFields_Success()
{
// arrange
Sample sample = new Sample(_configuration);
// act
var result = sample.GetListOfWorkItemFields("Title");
//assert
Assert.AreEqual("System.Title", result);
}
}
}

Просмотреть файл

@ -4,6 +4,7 @@ using System.Collections.Generic;
using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models;
using VstsClientLibrariesSamples.WorkItemTracking;
using System.IO;
namespace VstsClientLibrariesSamples.Tests.WorkItemTracking
{
@ -25,55 +26,88 @@ namespace VstsClientLibrariesSamples.Tests.WorkItemTracking
}
[TestMethod, TestCategory("Client Libraries")]
public void WorkItemTracking_WorkItems_UpdateWorkItemsByQueryResults_Success()
public void CL_WorkItemTracking_WorkItems_GetWorkItemsByIDs_Success()
{
// arrange
IList<WorkItemReference> workItemsList = new List<WorkItemReference>();
string[] workItemsArr = _configuration.WorkItemIds.Split(','); // get the list of ids from our app.config
WorkItems workItems = new WorkItems(_configuration);
var split = _configuration.WorkItemIds.Split(',');
var ids = new List<int>();
// build a list of work item references for ids we know exist
foreach (string item in workItemsArr)
foreach(string item in split)
{
workItemsList.Add(new WorkItemReference() { Id = Convert.ToInt32(item) });
ids.Add(Convert.ToInt32(item));
}
WorkItemQueryResult workItemQueryResult = new WorkItemQueryResult();
workItemQueryResult.WorkItems = workItemsList;
// act
WorkItems workItems = new WorkItems(_configuration);
var result = workItems.UpdateWorkItemsByQueryResults(workItemQueryResult, _configuration.Identity);
var result = workItems.GetWorkItemsByIDs(ids);
// assert
Assert.AreEqual("success", result);
//assert
Assert.IsNotNull(result);
}
[TestMethod, TestCategory("Client Libraries")]
public void WorkItemTracking_WorkItems_CreatWorkItem_Success()
public void CL_WorkItemTracking_WorkItems_GetWorkItemsWithSpecificFields_Success()
{
// arrange
WorkItems workItems = new WorkItems(_configuration);
var split = _configuration.WorkItemIds.Split(',');
var ids = new List<int>();
foreach (string item in split)
{
ids.Add(Convert.ToInt32(item));
}
// act
var result = workItems.CreateWorkItem(_configuration.Project);
var result = workItems.GetWorkItemsWithSpecificFields(ids);
Assert.AreEqual("success", result);
//assert
Assert.IsNotNull(result);
}
[TestMethod, TestCategory("Client Libraries")]
public void WorkItemTracking_WorkItems_UpdateWorkItem_Success()
public void CL_WorkItemTracking_WorkItems_GetWorkItemsAsOfDate_Success()
{
// arrange
WorkItems workItems = new WorkItems(_configuration);
var asOfDate = new DateTime().AddDays(-30);
var split = _configuration.WorkItemIds.Split(',');
var ids = new List<int>();
foreach (string item in split)
{
ids.Add(Convert.ToInt32(item));
}
// act
var result = workItems.UpdateWorkItem(_configuration.WorkItemId);
var result = workItems.GetWorkItemsAsOfDate(ids, asOfDate);
Assert.AreEqual("success", result);
//assert
Assert.IsNotNull(result);
}
[TestMethod, TestCategory("Client Libraries")]
public void WorkItemTracking_WorkItems_GetWorkItem_Success()
public void CL_WorkItemTracking_WorkItems_GetWorkItemsWithLinksAndAttachments_Success()
{
// arrange
WorkItems workItems = new WorkItems(_configuration);
var split = _configuration.WorkItemIds.Split(',');
var ids = new List<int>();
foreach (string item in split)
{
ids.Add(Convert.ToInt32(item));
}
// act
var result = workItems.GetWorkItemsWithLinksAndAttachments(ids);
//assert
Assert.IsNotNull(result);
}
[TestMethod, TestCategory("Client Libraries")]
public void CL_WorkItemTracking_WorkItems_GetWorkItem_Success()
{
// arrange
WorkItems workItems = new WorkItems(_configuration);
@ -81,21 +115,296 @@ namespace VstsClientLibrariesSamples.Tests.WorkItemTracking
// act
var result = workItems.GetWorkItem(_configuration.WorkItemId);
Assert.AreEqual("success", result);
Assert.IsNotNull(result);
}
[TestMethod, TestCategory("Client Libraries")]
public void WorkItemTracking_WorkItems_AddLink_Success()
public void CL_WorkItemTracking_WorkItems_GetWorkItemWithLinksAndAttachments_Success()
{
// arrange
WorkItems workItems = new WorkItems(_configuration);
string[] arr = _configuration.WorkItemIds.Split(',');
// act
var result = workItems.GetWorkItemWithLinksAndAttachments(_configuration.WorkItemId);
Assert.IsNotNull(result);
}
[TestMethod, TestCategory("Client Libraries")]
public void CL_WorkItemTracking_WorkItems_GetWorkItemFullyExpanded_Success()
{
// arrange
WorkItems workItems = new WorkItems(_configuration);
// act
var result = workItems.AddLink(Convert.ToInt32(arr[0]), Convert.ToInt32(arr[1]));
var result = workItems.GetWorkItemFullyExpanded(_configuration.WorkItemId);
Assert.AreEqual("success", result);
Assert.IsNotNull(result);
}
[TestMethod, TestCategory("Client Libraries")]
public void CL_WorkItemTracking_WorkItems_CreateWorkItem_Success()
{
// arrange
WorkItems workItems = new WorkItems(_configuration);
// act
var result = workItems.CreateWorkItem(_configuration.Project);
//assert
Assert.IsNotNull(result);
}
[TestMethod, TestCategory("Client Libraries")]
public void CL_WorkItemTracking_WorkItems_CreateWorkItemWithWorkItemLink_Success()
{
// arrange
WorkItems workItems = new WorkItems(_configuration);
// act
var createResult = workItems.CreateWorkItem(_configuration.Project);
var updateResult = workItems.CreateWorkItemWithWorkItemLink(_configuration.Project, createResult.Url);
//assert
Assert.IsNotNull(createResult);
Assert.IsNotNull(updateResult);
}
[TestMethod, TestCategory("Client Libraries")]
public void CL_WorkItemTracking_WorkItems_CreateWorkItemByPassingRules_Success()
{
// arrange
WorkItems workItems = new WorkItems(_configuration);
// act
var result = workItems.CreateWorkItemByPassingRules(_configuration.Project);
//assert
Assert.IsNotNull(result);
}
[TestMethod, TestCategory("Client Libraries")]
public void CL_WorkItemTracking_WorkItems_UpdateWorkItemUpdateField_Success()
{
// arrange
WorkItems workItems = new WorkItems(_configuration);
// act
var createResult = workItems.CreateWorkItem(_configuration.Project);
var id = createResult.Id ?? default(int);
var updateResult = workItems.UpdateWorkItemUpdateField(id);
//assert
Assert.IsNotNull(createResult);
Assert.IsNotNull(updateResult);
}
[TestMethod, TestCategory("Client Libraries")]
public void CL_WorkItemTracking_WorkItems_UpdateWorkItemMoveWorkItem_Success()
{
// arrange
WorkItems workItems = new WorkItems(_configuration);
string project = _configuration.MoveToProject;
string areaPath = _configuration.MoveToProject; // use project name for root area path
string iterationPath = _configuration.MoveToProject; // use project name for root iteration path
// act
var createResult = workItems.CreateWorkItem(_configuration.Project);
var id = createResult.Id ?? default(int);
var moveResult = workItems.UpdateWorkItemMoveWorkItem(id, project, areaPath, iterationPath);
//assert
Assert.IsNotNull(createResult);
Assert.IsNotNull(moveResult);
}
[TestMethod, TestCategory("Client Libraries")]
public void CL_WorkItemTracking_WorkItems_UpdateWorkItemChangeWorkItemType_Success()
{
// arrange
WorkItems workItems = new WorkItems(_configuration);
// act
var createResult = workItems.CreateWorkItem(_configuration.Project);
var id = createResult.Id ?? default(int);
var changeResult = workItems.UpdateWorkItemChangeWorkItemType(id);
//assert
Assert.IsNotNull(createResult);
Assert.IsNotNull(changeResult);
}
[TestMethod, TestCategory("Client Libraries")]
public void CL_WorkItemTracking_WorkItems_UpdateWorkItemAddTag_Success()
{
// arrange
WorkItems workItems = new WorkItems(_configuration);
// act
var createResult = workItems.CreateWorkItem(_configuration.Project);
var id = createResult.Id ?? default(int);
var updateResult = workItems.UpdateWorkItemAddTag(id);
//assert
Assert.IsNotNull(createResult);
Assert.IsNotNull(updateResult);
}
[TestMethod, TestCategory("Client Libraries")]
public void CL_WorkItemTracking_WorkItems_UpdateWorkItemUpdateLink_Success()
{
// arrange
WorkItems workItems = new WorkItems(_configuration);
// act
var createOneResult = workItems.CreateWorkItem(_configuration.Project);
var createTwoResult = workItems.CreateWorkItem(_configuration.Project);
var id = createOneResult.Id ?? default(int);
var linkToId = createTwoResult.Id ?? default(int);
var updateLinkResult = workItems.UpdateWorkItemAddLink(id, linkToId);
var updateResult = workItems.UpdateWorkItemUpdateLink(id);
//assert
Assert.IsNotNull(createOneResult);
Assert.IsNotNull(createTwoResult);
Assert.IsNotNull(updateResult);
}
[TestMethod, TestCategory("Client Libraries")]
public void CL_WorkItemTracking_WorkItems_UpdateWorkItemRemoveLink_Success()
{
// arrange
WorkItems workItems = new WorkItems(_configuration);
// act
var createOneResult = workItems.CreateWorkItem(_configuration.Project); //create wi 1
var createTwoResult = workItems.CreateWorkItem(_configuration.Project); //creaet wi 2
var id = createOneResult.Id ?? default(int);
var linkToId = createTwoResult.Id ?? default(int);
var updateResult = workItems.UpdateWorkItemAddLink(id, linkToId); //link on wi #1 to wi #2
var removeResult = workItems.UpdateWorkItemRemoveLink(id); //remove link from wi #1
//assert
Assert.IsNotNull(createOneResult);
Assert.IsNotNull(createTwoResult);
Assert.IsNotNull(updateResult);
Assert.IsNotNull(removeResult);
}
[TestMethod, TestCategory("Client Libraries")]
public void CL_WorkItemTracking_WorkItems_UpdateWorkItemAddAttachment_Success()
{
string filePath = @"D:\Temp\Test.txt";
if (! File.Exists(filePath))
{
Assert.Inconclusive("File path '" + filePath + "' not found");
}
// arrange
WorkItems workItems = new WorkItems(_configuration);
// act
var createOneResult = workItems.CreateWorkItem(_configuration.Project);
var id = createOneResult.Id ?? default(int);
var updateResult = workItems.UpdateWorkItemAddAttachment(id, @"D:\Temp\Test.txt");
//assert
Assert.IsNotNull(createOneResult);
Assert.IsNotNull(updateResult);
}
[TestMethod, TestCategory("Client Libraries")]
public void CL_WorkItemTracking_WorkItems_UpdateWorkItemRemoveAttachment_Success()
{
string filePath = @"D:\Temp\Test.txt";
if (!File.Exists(filePath))
{
Assert.Inconclusive("File path '" + filePath + "' not found");
}
// arrange
WorkItems workItems = new WorkItems(_configuration);
// act
var createOneResult = workItems.CreateWorkItem(_configuration.Project);
var id = createOneResult.Id ?? default(int);
var addAttachmentResult = workItems.UpdateWorkItemAddAttachment(id, @"D:\Temp\Test.txt");
var removeAttachmentResult = workItems.UpdateWorkItemRemoveAttachment(id, "0");
//assert
Assert.IsNotNull(createOneResult);
Assert.IsNotNull(addAttachmentResult);
Assert.IsNotNull(removeAttachmentResult);
}
[TestMethod, TestCategory("Client Libraries")]
public void CL_WorkItemTracking_WorkItems_UpdateWorkItemAddHyperLink_Success()
{
// arrange
WorkItems workItems = new WorkItems(_configuration);
// act
var createResult = workItems.CreateWorkItem(_configuration.Project);
var id = createResult.Id ?? default(int);
var updateResult = workItems.UpdateWorkItemAddHyperLink(id);
//assert
Assert.IsNotNull(createResult);
Assert.IsNotNull(updateResult);
}
[TestMethod, TestCategory("Client Libraries")]
public void CL_WorkItemTracking_WorkItems_UpdateWorkItemAddCommitLink_Success()
{
// arrange
WorkItems workItems = new WorkItems(_configuration);
// act
var createResult = workItems.CreateWorkItem(_configuration.Project);
var id = createResult.Id ?? default(int);
var updateResult = workItems.UpdateWorkItemAddCommitLink(id);
//assert
Assert.IsNotNull(createResult);
Assert.IsNotNull(updateResult);
}
[TestMethod, TestCategory("Client Libraries")]
public void CL_WorkItemTracking_WorkItems_UpdateWorkItemUsingByPassRules_Success()
{
// arrange
WorkItems workItems = new WorkItems(_configuration);
// act
var createResult = workItems.CreateWorkItem(_configuration.Project);
var id = createResult.Id ?? default(int);
var updateResult = workItems.UpdateWorkItemUsingByPassRules(id);
//assert
Assert.IsNotNull(createResult);
Assert.IsNotNull(updateResult);
}
[TestMethod, TestCategory("Client Libraries")]
public void CL_WorkItemTracking_WorkItems_DeleteWorkItem_Success()
{
// arrange
WorkItems workItems = new WorkItems(_configuration);
// act
var createResult = workItems.CreateWorkItem(_configuration.Project);
var id = createResult.Id ?? default(int);
var deleteResult = workItems.DeleteWorkItem(id);
//assert
Assert.IsNotNull(createResult);
Assert.IsNotNull(deleteResult);
}
}

Просмотреть файл

@ -14,8 +14,11 @@
</runtime>
<appSettings>
<add key="appsetting.uri" value="" />
<add key="appsetting.collectionid" value="" />
<add key="appsetting.pat" value="" />
<add key="appsetting.project" value="" />
<add key="appsetting.team" value="" />
<add key="appsetting.movetoproject" value="" />
<add key="appsetting.query" value="Shared Queries/Current Iteration/Open User Stories" />
<add key="appsetting.identity" value="" />
<add key="appsetting.workitemids" value="" />

Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше