Access TFS field TC Description - c#

I want to get the values of Description of test cases in TFS as shown in the image using C#. let me know if anyone knows how to get this using C#.

You can use below sample to get the value of Description of a specific test case:
With Nuget package Microsoft.TeamFoundationServer.ExtendedClient intalled
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.TestManagement.Client;
using Microsoft.VisualStudio.Services.Client;
using System;
namespace RetrieveTestCaseDescription
{
class Program
{
static void Main(string[] args)
{
var u = new Uri("http://server:8080/tfs/DefaultCollection");
var c = new VssClientCredentials();
int TestCaseId = 57;
TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(u, c);
tpc.EnsureAuthenticated();
ITestManagementService test_service = (ITestManagementService)tpc.GetService(typeof(ITestManagementService));
ITestManagementTeamProject project = test_service.GetTeamProject("ProjectNameHere");
ITestCase testcase = project.TestCases.Find(TestCaseId);
Console.WriteLine(String.Format("{0} - {1}", testcase.Id, testcase.Description));
Console.Read();
}
}
}

Related

Methods return type in C#

i am using a method to retrieve data from an OPC DA server using TitaniumAS packages, the problem i am having is that i have a lot of tags to read/write so i have to use methods.
The WriteX method works fines as it doesnt have to return anything but the read does not, well it does its job, it reads but i cannot use that data outside of the method because it was a void method, when i tried to use it as a String method (that's the type of data i need) it says :
Error CS0161 'ReadX(string, string)': not all code paths return a value
PS : note that i am just a beginner in C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TitaniumAS.Opc.Client.Common;
using TitaniumAS.Opc.Client.Da;
using TitaniumAS.Opc.Client.Da.Browsing;
using System.Threading;
using System.Threading.Channels;
using Async;
namespace OPCDA
{
class Program
{
static void Main(string[] args)
{
TitaniumAS.Opc.Client.Bootstrap.Initialize();
Uri url = UrlBuilder.Build("Kepware.KEPServerEX.V6");
using (var server = new OpcDaServer(url))
{
server.Connect();
OpcDaGroup group = server.AddGroup("MyGroup");
group.IsActive = true;
Ascon ascon1 = new Ascon();
ReadX("Channel1.Ascon1.AsconS", ascon1.ALM);
Console.WriteLine("value = {0}", ascon1.ALM);
void WriteX(String Link, String Ascon)
{
var definition1 = new OpcDaItemDefinition
{
ItemId = Link,
IsActive = true
};
OpcDaItemDefinition[] definitions = { definition1 };
OpcDaItemResult[] results = group.AddItems(definitions);
OpcDaItem tag = group.Items.FirstOrDefault(i => i.ItemId == Link);
OpcDaItem[] items = { tag };
object[] Values = { Ascon };
HRESULT[] Results = group.Write(items, Values);
}
string ReadX(String Link, String read)
{
var definition1 = new OpcDaItemDefinition
{
ItemId = Link,
IsActive = true
};
OpcDaItemDefinition[] definitions = { definition1 };
OpcDaItemResult[] results = group.AddItems(definitions);
OpcDaItemValue[] values = group.Read(group.Items, OpcDaDataSource.Device);
read = Convert.ToString(values[0].Value);
}
}
}
}
}
the first step was to state the return like this :
return Convert.ToString(values[0].Value) instead of read = Convert.ToString(values[0].Value)
then go up and use that value with my variable :
ascon1.ALM=ReadX("Channel1.Ascon1.AsconS");

Find all the child test suites in TFS using C#

I would like get all the child test suites under a parent test suite in TFS using C# code. Let me know if anyone has done this.
I have create the simple app based on Microsoft.TeamFoundationServer.ExtendedClient
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.TestManagement.Client;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
string teamProjectName = "TFSCMMI";
int parentTestSuiteId = 819; // or test plan id
var TFSCurrentProjectCollection = new TfsTeamProjectCollection(new Uri("http://tfs-srv:8080/tfs/defaultcollection"));
var testStore = TFSCurrentProjectCollection.GetService<ITestManagementService>();
var teamProject = testStore.GetTeamProject(teamProjectName);
var testSuite = teamProject.TestSuites.Find(parentTestSuiteId);
if (testSuite.TestSuiteType == TestSuiteType.StaticTestSuite)
{
var staticSuite = testSuite as IStaticTestSuite;
foreach (var childSuite in staticSuite.Entries)
{
Console.WriteLine("Test suite id " + childSuite.Id + " name '" + childSuite.Title + "'");
}
}
}
}
}

Ghostscript.NET.dll print pdf to specified printer

How to print pdf using ghostscript api.
I tried google but still not getting proper solution. Please help me how i do this task.
This should work for you (by using Ghostscript.NET wrapper):
using System;
using System.Collections.Generic;
using Ghostscript.NET.Processor;
namespace Ghostscript.NET.Samples
{
public class SendToPrinterSample : ISample
{
public void Start()
{
// YOU NEED TO HAVE ADMINISTRATOR RIGHTS TO RUN THIS CODE
string printerName = "YourPrinterName";
string inputFile = #"E:\__test_data\test.pdf";
using (GhostscriptProcessor processor = new GhostscriptProcessor())
{
List<string> switches = new List<string>();
switches.Add("-empty");
switches.Add("-dPrinted");
switches.Add("-dBATCH");
switches.Add("-dNOPAUSE");
switches.Add("-dNOSAFER");
switches.Add("-dNumCopies=1");
switches.Add("-sDEVICE=mswinpr2");
switches.Add("-sOutputFile=%printer%" + printerName);
switches.Add("-f");
switches.Add(inputFile);
processor.StartProcessing(switches.ToArray(), null);
}
}
}
}

How to get attributes out of an event of Google-Calendar?

In the Last days I tried to read attributes out of an event of Google-calendar
So currently I have only achived to get the event-ID out of my calendar.
Code:
using System;
using Google.GData.Extensions;
using Google.GData.Calendar;
namespace ConsoleApplication1
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
EventQuery query = new EventQuery();
query.Uri = new Uri("https://www.google.com/calendar/feeds/my#e-mail.com/public/basic");
query.NumberToRetrieve = 10;
query.StartTime = System.DateTime.Now;
query.EndTime = System.DateTime.Today.AddDays(10);
CalendarService service = new CalendarService(appName);
service.setUserCredentials(userName, password);
EventFeed calFeed = service.Query(query);
foreach (EventEntry feedEntry in calFeed.Entries)
{
Console.WriteLine("Event ID: " + feedEntry.EventId);
Console.ReadLine();
}
}
}
}
and I tried feedEntry.Title.Text to get the Title ... but its always "busy"
So my question is:
Ho Can I Get informations out of my Event?
The Answer is:
query.Uri = new Uri("https://www.google.com/calendar/feeds/my#e-mail.com/public/basic");
has to be :
query.Uri = new Uri("https://www.google.com/calendar/feeds/my#e-mail.com/private/full");
You should migrate off this approach altogether. Gdata is a deprecated Calendar API and will be shut down in November: http://googleappsdeveloper.blogspot.co.at/2014/07/upgrade-now-to-calendar-apiv3.html
Use Events.List in the Calendar API v3 https://developers.google.com/google-apps/calendar/

Using C#, how do I set a Rally weblink field?

Here's a screenshot of the field I'm trying to update:
How do I update the URL field?
WebLink type fields consist of two parts: LinkID and DisplayString. In order to set a LinkID (which corresponds to the variable ${id} in your screenshot, a DisplayString needs also to be set to an empty string.
Here is a full code example that uses Rally .NET REST toolkit:
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using Rally.RestApi;
using Rally.RestApi.Response;
namespace aRestApp_CollectionOfTasks
{
class Program
{
static void Main(string[] args)
{
//Initialize the REST API
RallyRestApi restApi;
restApi = new RallyRestApi("user#co.com", "secret", "https://rally1.rallydev.com", "v2.0");
//Set our Workspace and Project scopings
String workspaceRef = "/workspace/1111"; //please replace this OID with an OID of your workspace
String projectRef = "/project/2222"; //please replace this OID with an OID of your project
bool projectScopingUp = false;
bool projectScopingDown = true;
Request storyRequest = new Request("Defect");
storyRequest.Workspace = workspaceRef;
storyRequest.Project = projectRef;
storyRequest.ProjectScopeUp = projectScopingUp;
storyRequest.ProjectScopeDown = projectScopingDown;
storyRequest.Fetch = new List<string>()
{
"Name",
"_ref",
"c_JiraLink"
};
storyRequest.Query = new Query("FormattedID", Query.Operator.Equals, "DE170");
QueryResult queryStoryResults = restApi.Query(storyRequest);
foreach (var s in queryStoryResults.Results)
{
Console.WriteLine(" Name: " + s["Name"] + " JiraLink's DisplayString: " + s["c_JiraLink"]["DisplayString"] + " JiraLink's LinkID: " + s["c_JiraLink"]["LinkID"]);
DynamicJsonObject toUpdate = new DynamicJsonObject();
DynamicJsonObject myLink = new DynamicJsonObject();
myLink["LinkID"] = "NM-3";
myLink["DisplayString"] = "";
toUpdate["c_JiraLink"] = myLink;
OperationResult updateResult = restApi.Update(s["_ref"], toUpdate);
}
}
}
}
Note that this is not different from a more general example of setting LinkID of a WebLink type of filed using a browser's REST client.
Method: POST
URL:
https://rally1.rallydev.com/slm/webservice/v2.0/defect/3807704995?key=abc123...
Request Body:
{
"defect":
{
"c_JiraLink":{
"DisplayString":"",
"LinkID":"NM-2"
}
}
}

Categories

Resources