I'm trying to change tester of the test case in tfs api
in test-case manager i see this testers: https://gyazo.com/03adc434225c4c5541f602bc954feaed
i try to create and add TestPointAssignment with this tester:
IdAndName idAndName = new IdAndName(testSuite.Id, testSuite.Title);
var assignment = testSuite.CreateTestPointAssignment(testCase.Id, idAndName, Tester);
testSuite.AssignTestPoints(new List<ITestPointAssignment>() { assignment });
but nothing changes and remains the same tester.
how can i change tester in test-case with tfs api?
To change a Tester of a Test Case using TFS API, you could try the following code snippet:
string teamProjectName = "TeamProjectName";
TfsTeamProjectCollection tfsCollection = new TfsTeamProjectCollection(new Uri("http://serverName:8080/tfs/MyCollection"));
ITestManagementService testService = tfsCollection.GetService<ITestManagementService>();
ITestManagementTeamProject teamProject = testService.GetTeamProject(teamProjectName);
//get test point of a test case
ITestPlan tplan = teamProject.TestPlans.Find(testplanid);
ITestPoint point = tplan.QueryTestPoints("SELECT * FROM TestPoint WHERE TestCaseID = Testcaseid").FirstOrDefault();
IIdentityManagementService ims = tfsCollection.GetService<IIdentityManagementService>();
TeamFoundationIdentity tester = ims.ReadIdentity(IdentitySearchFactor.DisplayName, "Mike", MembershipQuery.Direct, ReadIdentityOptions.None);
//change tester for testcase
point.AssignedTo = tester;
point.Save();
I believe your issue is with idAndName.
CreateTestPointAssignment expects a list of ITestPointAssignment objects, where each object contains:
The Test Case Id
The Configuration
The TeamFoundationIdentity (user)
I believe it's failing because you're specifying the suite id and name, not a configuration id and name.
As you're probably aware, each tester gets assigned a Test Point, which is the intersection of a test case and a configuration. In MTM, you can see your configurations in Organize -> Test Configuration Manager. You'll see the ID and Name there, though in code, you'll probably want to query that list through the suite's DefaultConfigurations property. (Note that if it's empty, it means it's inheriting configurations from its parent or ancestor, and you may have to get the values from there.)
Related
I am using Ldapconnection.Sendrequest because I am running on Linux, so I can only use classes from the System.DirectoryServices.Protocols namespace.
The code works perfectly well against a live Active Directory, but here is an example anyway.
// retrieves the distinguishedname for all groups, starting from dc=test,dc=local
var request = new SearchRequest("dc=test,dc=local", "(Objectclass=group)", "distinguishedname");
var searchResponse = ldapConnection.SendRequest(request) as SearchResponse;
My question is, how can this be unit tested? I would like to unit test it because a different searchResponse will cause a different path to be taken through code.
I have tried mocking SearchResponse: (How to create an instance of SearchResponse class (which has no public constructors)?)
var ctors = typeof (SearchResponse).GetConstructors(BindingFlags.NonPublic | BindingFlags.Instance);
var neededCtor = ctors.First(
ctor =>
ctor.GetParameters().Count() == 5);
SearchResponse response = neededCtor.Invoke(new object[]
{
"distinguishedName",
null, // System.DirectoryServices.Protocols.DirectoryControl[]
null, // System.DirectoryServices.Protocols.ResultCode
errorMessage,
null // System.Uri[]
}) as SearchResponse;
return response;
But I cannot find a way to mock SearchResponse.Entries, as SearchResultEntryCollection and SearchResultEntry are (seemingly) unmockable. It's as though the dotnet team has gone out of its way to make this area completely unmockable.
I'm new to using LdapConnection (previously I could use the AccountManagement class, as I was running in Windows), so maybe I shouldn't be using LdapConnection in the first place?
Equally, I'd be open to running the AD tests in memory, as I would for database access, but I cannot find a way to do so.
Many thanks for you help,
Dan
I'm working with the TFS API and have run into a problem with ITestSuiteBase and IRequirementTestSuite. I've mananged to easily create a new test case within a IStaticTestSuite:
IStaticTestSuite workingSuite = this.WorkingSuite as IStaticTestSuite;
testCase = CreateTestCase(this.TestProject, tci.Title, tci.Description);
workingSuite.Entries.Add(testCase);
this.Plan.Save();
However, this solution doesn't work for requirements test suites or ITestSuiteBase. The method that I would assume would work is:
ITestcase testCase = null;
testCase = CreateTestCase(this.TestProject, tci.Title, tci.Description);
this.WorkingSuite.AllTestCases.Add(testCase);
this.WorkingSuite.TestCases.Add(testCase);
this.Plan.Save();
But this method doesn't actually add the test case to the suite. It does, however, add the test case to the plan. I can query the created test case but it doesn't show up in the suite as expected - even immediately in the code afterwards. Refreshing the working suite has no benefit.
Additional code included below:
public static ITestCase CreateTestCase(ITestManagementTeamProject project, string title, string desc = "", TeamFoundationIdentity owner = null)
{
// Create a test case.
ITestCase testCase = project.TestCases.Create();
testCase.Owner = owner;
testCase.Title = title;
testCase.Description = desc;
testCase.Save();
return testCase;
}
Has anyone been able to successfully add a test case to a requirements test suite or a ITestSuiteBase?
Giulio's link proved to be the best way to do this
testCase = CreateTestCase(this.TestProject, tci.Title, tci.Description);
if (this.BaseWorkingSuite is IRequirementTestSuite)
TFS_API.AddTestCaseToRequirementSuite(this.BaseWorkingSuite as IRequirementTestSuite, testCase);
else if (this.BaseWorkingSuite is IStaticTestSuite)
(this.BaseWorkingSuite as IStaticTestSuite).Entries.Add(testCase);
this.Plan.Save();
And the important method:
public static void AddTestCaseToRequirementSuite(IRequirementTestSuite reqSuite, ITestCase testCase)
{
WorkItemStore store = reqSuite.Project.WitProject.Store;
WorkItem tfsRequirement = store.GetWorkItem(reqSuite.RequirementId);
tfsRequirement.Links.Add(new RelatedLink(store.WorkItemLinkTypes.LinkTypeEnds["Tested By"], testCase.WorkItem.Id));
tfsRequirement.Save();
reqSuite.Repopulate();
}
This is expected.
Static Test Suites are ... static while Requirement-based Test Suites are dynamic. The relationship between a Test Case and a Requirement is determined by the presence of a proper Tests/Tested By Work Item Link, so you need to add such a link.
For sample code see Not able to add test cases to type of IRequirementTestSuite.
Small note: you cannot duplicate links, so you may have to check for existence if the Test Case is not new.
Here I am using IIdentityManagementService to retrieve a specified user by name. Now I want to retrieve only those team projects which they are a member of and can create tasks/workitems for in TFS. My program allows a user to create a task in TFS and I only want them to be able to see a list of the projects which they have access to for creating tasks/work items.
var tfsTpc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://dotnettfs:8080/tfs/"));
identityService = tfsTpc.GetService<IIdentityManagementService>();
userId = identityService.ReadIdentity(
IdentitySearchFactor.DisplayName,
strOutlookUser,
MembershipQuery.Direct,
ReadIdentityOptions.None
);
userTpc = new TfsTeamProjectCollection(tfsTpc.Uri, userId.Descriptor);
cssService = (ICommonStructureService4)userTpc.GetService(typeof(ICommonStructureService4));
wis = userTpc.GetService<WorkItemStore>();
lstAllProjects.AddRange(cssService.ListAllProjects().ToList());
List<string> lstViewProjectNames = lstAllProjects.Select(a => a.Name).ToList();
Right now, the list shows all projects within that software collection when I want it to show only those projects which the retrieved user has access to.
then they are able to create a task and specify the iteration and area for one of those projects.
var store = wis.Projects[0]; //should be a specified project, not the first element.
WorkItem pbi = new WorkItem(store.WorkItemTypes["Product Backlog Item"]);
pbi.IterationPath = lstIterations.Where(a => a.Name == selectedIteration.ToString())
.Select(a => a.Path).First().ToString();
pbi.AreaPath = lstAreas.Where(a => a.Name == selectedArea.ToString())
.Select(a => a.Path).First().ToString();
I only want them to be able to see a list of the projects which they
have access to for creating tasks/work items.
Work items are tied to areas and areas are tied to team projects.
The basic steps are:
1) Connect to TFS as the user in question
2) Retrieve the team project in question
3) Get the areas for the team project in question
4) Check each one for the ability to create work items (you can probably get away with doing the recursive check on just the root area node)
The usings you will need (might not need all):
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Framework.Client;
using Microsoft.TeamFoundation.Framework.Common;
using Microsoft.TeamFoundation.Server;
using Microsoft.TeamFoundation.VersionControl.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
IIdentityManagementService identityManagementService = tpc.GetService<IIdentityManagementService>();
TfsTeamProjectCollection tpc = GetTfsCollection();
TeamFoundationIdentity identity = identityManagementService.ReadIdentity(IdentitySearchFactor.AccountName, #"Domain\username", MembershipQuery.None, ReadIdentityOptions.None);
TfsTeamProjectCollection impersonatedTPC = new TfsTeamProjectCollection(new Uri(this._tfsUri, this._tfsCollectionName), identity.Descriptor);
WorkItemStore impersonatedWIS = impersonatedTPC.GetService<WorkItemStore>();
ProjectCollection impersonatedProjects = impersonatedWIS.Projects;
foreach (Project p in impersonatedProjects)
{
if (p.Name == "My Team Project")
{
NodeCollection areas = p.AreaRootNodes;
foreach (Node area in areas)
{
if (area.HasWorkItemWriteRightsRecursive)
{
//They do have rights
}
}
}
}
Note that I call GetTfsCollection() which my own user defined function (this is just the class that I constructed with, passing in the root tfs uri and the collection name as string). I also didn't put in any exception handling, just showing the basics:
private TfsTeamProjectCollection GetTfsCollection()
{
return TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(this._tfsUri, this._tfsCollectionName));
}
I am working with an SDK that can query a set of data as well as update data with a restful web service called VersionOne. We use the web service to document QA testing. Each test has attributes such as "Name", "Status", etc. Most of the attributes have been successfully updating except for "Status".
Here is the method I am calling, when I step through the code I can get the old value but cannot change the attribute value as expected. An error stating "Cannot assign new value to a read-only attribute".
public bool TestInProgress()
{
var testId = Oid.FromToken("Test:26017", _context.MetaModel);
var query = new Query(testId);
var assetType = _context.MetaModel.GetAssetType("Test");
var testStatus = assetType.GetAttributeDefinition("Status.Name");
query.Selection.Add(testStatus);
var result = _context.Services.Retrieve(query);
var test = result.Assets[0];
var oldResult = GetValue(test.GetAttribute(testStatus).Value);
test.SetAttributeValue(testStatus, "Failed");
_context.Services.Save(test);
LogResult(test.Oid.Token, oldResult, GetValue(test.GetAttribute(testStatus).Value));
Console.WriteLine(test.Oid.Token, oldResult, GetValue(test.GetAttribute(testStatus).Value));
return true;
}
https://github.com/versionone/VersionOne.SDK.Net.APIClient#attribute-definition
According to the VersionOne SDK documentation it appears as though "read-only" and is an attribute. I've looked though the different attribute from several different tests and testsets and do not see it. I am authenticated properly and have successfully updated other attributes with many different tests. However, when I attempt to programmatically change the "Status" attribute it says it is read-only.
https://github.com/versionone/VersionOne.SDK.Net.APIClient#learn-by-example-apiclient-setup
How do you change the attribute for an asset in VersionOne programmatically that is currently read-only so you can update the attribute using the restful web service?
Because the Attribute is read-only, you will not be able to change its value. Instead, consider creating a 'new' Asset, set its Attributes, and then save it.
Review the example below and attempt to utilize the idea within your project:
var TestId = Oid.FromToken("Test:26017", _context.MetaModel);
var TestAsset = _context.MetaModel.GetAssetType("Test");
var newTestAsset = _context.Services.New(TestAsset, TestId);
var TestStatusAttr = newTestAsset.GetAttributeDefinition("Status.Name");
newTestAsset.SetAttributeValue(TestStatusAttr, "Failed");
_context.Services.Save(newTestAsset);
I have written below code to queue a build via api. team project collection, workitem store and version control server works fine, but i am not getting buildserver object. its always returning null. am i missing any other configuration
using (TfsTeamProjectCollection tpc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://tfsserver:8080/tfs/DefaultCollection")))
{
tpc.EnsureAuthenticated();
// i am getting workitemstore object here
var wiStore = tpc.GetService<WorkItemStore>();
....
....
// i am getting version control server object here as well
var vcs = tpc.GetService<VersionControlServer>();
....
....
// but here i get a null object
var bs = tpc.GetService<IBuildServer>();
//this is what i want to do with buildserver object
var buildDefinition = bs.GetBuildDefinition("aaa", "bbb");
var buildRequest = buildDefinition.CreateBuildRequest();
bs.QueueBuild(buildRequest);
}
any idea?
This can happen if you reference the wrong version of Microsoft.TeamFoundation.Build.Client for the TFS that you're trying to connect to. Check that you're referencing the correct version for TFS2010 (10.0.0.0 I believe).
http://pmichaels.net/2015/03/20/unable-to-get-ibuildserver-always-returning-null/
Try var bs = (IBuildServer)tpc.GetService(typeof(IBuildServer)); Sometimes the GetService<>() didn't work for me, maybe because IBuildServer is an interface, while VersionControlServer for example is a class.