Azure DevOps Server 2019 Programmatially copy test case error Exception: 'TF237124: Work Item is not ready to save'." - azure-devops-rest-api

I'm able to copy most test cases with this code (trying to copy shared steps to be part of the test case itself) but this one will not copy but I can not see any error message as to why - could anyone suggest anything else to try. See output from Immediate windows. Thanks John.
?targetTestCase.Error
null
?targetTestCase.InvalidProperties
Count = 0
?targetTestCase.IsDirty
true
?targetTestCase.State
"Ready"
?targetTestCase.Reason
"New"
foreach (ITestAction step in testSteps)
{
if (step is ITestStep)
{
ITestStep sourceStep = (ITestStep)step;
ITestStep targetStep = targetTestCase.CreateTestStep();
targetStep.Title = sourceStep.Title;
targetStep.Description = sourceStep.Description;
targetStep.ExpectedResult = sourceStep.ExpectedResult;
//Copy Attachments
if (sourceStep.Attachments.Count > 0)
{
string attachmentRootFolder = _tfsServiceUtilities.GetAttachmentsFolderPath();
string testCaseFolder = _tfsServiceUtilities.CreateDirectory(attachmentRootFolder, "TestCase_" + targetTestCase.Id);
//Unique folder path for test step
string TestStepAttachementFolder = _tfsServiceUtilities.CreateDirectory(testCaseFolder, "TestStep_" + sourceStep.Id);
using (var client = new WebClient())
{
client.UseDefaultCredentials = true;
foreach (ITestAttachment attachment in sourceStep.Attachments)
{
string attachmentPath = TestStepAttachementFolder + "\\" + attachment.Name;
client.DownloadFile(attachment.Uri, attachmentPath);
ITestAttachment newAttachment = targetTestCase.CreateAttachment(attachmentPath);
newAttachment.Comment = attachment.Comment;
targetStep.Attachments.Add(newAttachment);
}
}
}
targetTestCase.Actions.Add(targetStep);
targetTestCase.Save();
}

Since this code works for most test cases, this issue may come from the particular test case. In order to narrow down the issue, please try the following items:
Run the code on another client machine to see whether it works.
Try to modify this particular test case using the account API uses, to see whether it can be saved successfully.
Try validate the WorkItem prior to save. The validate() method will return an arraylist of invalid fields.

Related

Missing Test Points using .Net sdk GetPointsByQueryAsync

I am using the method "GetPointsByQueryAsync" when I use it for a small number of test cases (as input) it is working fine but when I use it for a large number of test cases (as input), it messes up like some test points will miss, when I try to get miss points separately, it works fine. I have posted this issue on the Visual studio community, they refuse to fix it and said it is not our policy to look into this issue. I have a test case count of 3000 and a test point count of 15000.
https://developercommunity.visualstudio.com/t/Missing-Test-Points-using-Net-sdk/10215409
using Microsoft.TeamFoundation.TestManagement.WebApi;
public List<TestPoint> GetTestPoints(Uri uri, string oAuthAccessToken, List<int> testcaseIds)
{
TestPointsQuery outputQuery= null;
try
{
VssOAuthAccessTokenCredential mCredential = new VssOAuthAccessTokenCredential(oAuthAccessToken);
VssConnection connection =
new VssConnection(uri, mCredential);
TestManagementHttpClient testManagementHttpClient = connection.GetClient<TestManagementHttpClient>();
TestPointsQuery query = new TestPointsQuery();
PointsFilter filter = new PointsFilter();
filter.TestcaseIds = testcaseIds;
query.PointsFilter = filter;
outputQuery = testManagementHttpClient.GetPointsByQueryAsync(query, WIProject.Id).Result;
}
catch (Exception e)
{
Console.WriteLine(e);
}
return outputQuery.Points;
}

why asp.net mvc does not include the image uploaded folder in the project?

what I have found that the images uploaded by my application are not included in the project and that I have to include them manually image by image so what is the correct way of asp.net mvc project to let the images uploaded to be included in the project.
The following code is the one that upload the images to the folder and creates a unique name for each image. but still those images are not included in the project explorer.
public ActionResult Create(Job job, HttpPostedFileBase JobImage)
{
var value = "999999999";
var result4 = from app in db.Job where app.UniqueJobImageName.Contains(value) select app;
if(result4.FirstOrDefault() != null)
{
value = generateRandom();
}
if (ModelState.IsValid && CheckFileType(JobImage.FileName))
{
string ext = Path.GetExtension(JobImage.FileName);
var fileName = Path.GetFileName(JobImage.FileName);
job.JobImage = JobImage.FileName;
job.UniqueJobImageName = value + ext;
var path = Path.Combine(Server.MapPath("~/Images"), value + ext);
JobImage.SaveAs(path);
job.UserId = User.Identity.GetUserId();
job.jobUrl = "";
job.Month = DateTime.Now.ToString("MMMM");
job.DateAndTime = DateTime.Now;
AllJobModel all = new AllJobModel
{
JobTitle = job.JobTitle,
JobDescription = job.JobDescription,
JobImage = job.JobImage,
UniqueJobImageName = job.UniqueJobImageName,
locationName = job.locationName,
minimumSalary = job.minimumSalary.ToString(),
maximumSalary = job.maximumSalary.ToString(),
jobUrl = job.jobUrl,
PostedDate = DateTime.Now.ToString("dd/MM/yyyy"),
UserId= User.Identity.GetUserId(),
};
db.AllJobModel.Add(all);
db.SaveChanges();
db.Job.Add(job);
db.SaveChanges();
return RedirectToAction("Index","Home");
}else if (!CheckFileType(JobImage.FileName))
{
}
return View(job);
}
enter image description here
This doesn't make any sense. The uploaded images are content created by the user. They are not a deployable component of the site (or, they shouldn't be anyway). They are user-generated content, not developer resources.
If you are looking to effectively migrate your data (i.e. copy database entries and other user-generated content such as image files) from one environment to another, then that is a separate task for which you can create a separate process and/or automated script. Don't confuse it with the job of uploading a new version of your application code.
P.S. Even if what you were asking for was a sensible goal, it's impossible anyway - the executable version of your code is not the same as the code you see in Visual Studio in your project. In a modern ASP.NET application the executable code is in a different folder (even when you're running in debug mode in Visual Studio) and it has no concept or knowledge of the original project it was compiled from, or where to find it, or how to interact with it.

When I try to read an X12 204 using EDI Fabric, I get "Invalid Node Name: ST", but the file is well formed. Any idea why?

Here's an example 204 I have made. It validates with a couple different validation tools (EDI Notepad and Altova), but when I try to use EDI fabric to parse it, it gets the ISA and GS data just fine, but then errors out with "Invalid Node Name: ST".
I can't figure out why, any ideas?
ISA*ZZ* *ZZ* *ZZ*XXXX *ZZ*YYYY *170130*1025*U*00401*485789958*0*P*~
GS*SM*YYYY*XXXX*20170130*1027*485790079*X*004010
ST*204*485790093
B2**YYYY**123456789**CC
B2A*00
L11*123456789*CR
S5*1*LD
G62*64*20160131*1*1351
SE*7*485790093
GE*1*485790079
IEA*1*485789958
Here is the code:
internal static void Parse204(FileStream file,
List<MyCompany.TruckRouteInfo> result)
{
var reader = EdiFabric.Framework.Readers.X12Reader.Create(file);
file.Flush();
var qEdiItems = reader.ReadToEnd();
var ediItems = qEdiItems.ToList();
var m204 = ediItems.OfType<M_204>().ToList();
foreach (var item in m204)
{
MyCompany.TruckRouteInfo stop = new MyCompany.TruckRouteInfo ();
foreach (var l11 in item.S_L11)
{
if (l11.D_128_2 == EdiFabric.Rules.X12004010204.X12_ID_128.CR)
{
stop.Reference1 = l11.D_127_1;
}
}
result.Add(stop);
}
}
I've just literally copied your example and pasted it to a file which was processed fine. Works on my machine :)
My best guess would be to open the file and inspect the line terminators for any discrepancies, which might have been sorted when I copied it\pasted it.

Trigger Automated Test from Testrail to Ranorex

Anyone had also worked with TestRail(maybe by a click of a button) trigger automated test run in Ranorex and return the result/s back to testrail.
Would it be possible to share to us the steps you made and maybe a sample code.
Can you highlight how you run multiple test case in Ranorex.
Thanks!
I have used TestRails API binding for .NET (http://docs.gurock.com/testrail-api2/bindings-dotnet) for writing a simple C# file in Ranorex.
The idea is to have a test run with tests in TestRail and Ranorex posting to TestRail about the success of the test execution of these tests.
var testCase = TestCase.Current.Parameters["test_case"];
var runID = TestSuite.Current.Parameters["run_id"];
if (String.IsNullOrEmpty(testCase))
{
Report.Failure("Test case '" + TestCase.Current.Name + "' has no test case id defined !");
return;
}
if (String.IsNullOrEmpty(runID))
{
Report.Failure("Test suite '" + TestSuite.Current.Name + "' has no run id defined !");
return;
}
APIClient client = new APIClient("https://<your_server>");
client.User = "<user>";
client.Password = "<api_key>";
var data = new Dictionary<string, object>
{
{ "status_id", 1 }, // 1 = successful
{ "comment", "test case executed in Ranorex" }
};
JObject r = (JObject) client.SendPost("add_result_for_case/" + runID + "/" + testCase, data);
Ranorex.Report.Info(r.ToString());
This posts the result for one case to Ranorex (therefore the add_result_for_case method. The runID is a parameter I give in command line when I execute the suite and each test case in Ranorex corresponds to one test case in TestRail and must hold the test case id.
Take a look at http://docs.gurock.com/testrail-api2/start about what possibilities the TestRail api offers

MonoTouch SecKeyChain.Add returning SecStatusCode.Param

I'm trying to save a record like so:
var testRecord = new SecRecord(SecKind.GenericPassword)
{
CreationDate = DateTime.UtcNow,
MatchCaseInsensitive = false,
Service = "MyService",
Label = "MyService",
Account = "User",
Generic = NSData.FromString("test", NSStringEncoding.UTF8),
};
SecKeyChain.Add(testRecord);
...but I'm getting SecStatusCode.Param back when I run it in the simulator. According to the documentation, that code means "Invalid or incomplete parameters passed" but I don't see anything missing or unusual that others aren't doing with apparent success.
Even adding CreationDate, Invisible, Description, Comment, Accessible, and ValueData properties to the SecRecord (some as in this example) didn't help -- still getting SecStatusCode.Param.
Are there any non-obvious things that might cause a Param status code to be returned?
I had a lot of trouble trying to use the keychain. I finally got mine working to store user credentials in the app. Here is what I have:
SecRecord existingRec = new SecRecord (SecKind.GenericPassword) {
Service = Keychain.USER_SERVICE,
Label = Keychain.USER_LABEL
};
var record = new SecRecord (SecKind.GenericPassword) {
Service = Keychain.USER_SERVICE,
Label = Keychain.USER_LABEL,
Account = username,
ValueData = NSData.FromString (password),
Accessible = SecAccessible.Always
};
SecStatusCode code = SecKeyChain.Add (record);
if (code == SecStatusCode.DuplicateItem) {
code = SecKeyChain.Remove (existingRec);
if (code == SecStatusCode.Success)
code = SecKeyChain.Add (record);
}
Keychain is a static class with constants so I don't have to retype the strings.
The only thing different between yours and mine is the CreationDate/MatchCaseInsensitive properties and the encoding for NSData. Maybe try it without those and see if it works? If so, add them back separately and see what gives the problem.
This might be because you are running on the simulator - in that case you need to add an Entitlements plist in the project options for your current build config in order to make keychain access work.

Resources