How I can get list all scenario from specflow dll? - nunit

Or from other place..
What I want: get all scenario names on start test, but without start all tests.
What I tried: by assembly reflection I scanned content, but one contain only feature names and method names. Not scenario names. (from this: Get list of tests in nunit library programmatically without having to run tests)
Also exist ScenarioContext, but it contain only current names. Not all existing in testsuite.
What i am using:
Specflow for describe.
NUnit for run. VS2019.
TestRail for result collect. TestSuite contains testName equal test describe in Specflow.
I hope it possible.
Thanks to all!

Ok, I`m finded it!
List<string> scenLst = new List<string>();
try
{
var assembly = System.Reflection.Assembly.LoadFrom(Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "project.dll"));
var types = assembly.GetTypes();
foreach (Type t in types){
foreach (var method in t.GetMethods()){
foreach (var attributes in tm.GetCustomAttributes())
{
if (attributes is DescriptionAttribute){
var d = propertyList.Properties["Description"][0].ToString();
if(d != null){
scenLst.Add();
}
}
}
}
}
catch (Exception ex){...}
return scenLst;
}
To get tags use CategoryAttribute (from NUnit).

Related

Entity Framework Core throw DbUpdateConcurrencyException

I am working on .net core entity framework. I have two list of class type. One for update and other for new entry, adding new records all worked fine but which is achieved by context.[Model].Add but update which is done by context.[Model].Update throw exception update i know no record been updated as it is running on local.
$exception {Microsoft.EntityFrameworkCore.DbUpdateConcurrencyException: Database operation expected to affect 1 row(s) but actually affected 0 row(s). Data may have been modified or deleted since entities were loaded.
Code
List<AnswerDataModel> surveyResponseListToCreate = new
List<AnswerDataModel>();
List<AnswerDataModel> surveyResponseListToUpdate = new
List<AnswerDataModel>();
if (surveyResponseListToUpdate.Count > 0)
{
foreach (var answerObject in surveyResponseListToUpdate)
{
Context.Answers.Update(answerObject);
if (answerObject.AnswerOptions.Count > 0)
{
foreach (var optItem in answerObject.AnswerOptions)
{
AnswerOptionDataModel answOpt = new AnswerOptionDataModel();
answOpt = optItem;
Context.AnswerOptions.Update(answOpt);
}
}
}
}
var recordsAffected = Context.SaveChanges();
if (!UsingExternalTransaction)
{
FinalizeTransaction(recordsAffected);
}
I can't resist a quote:
"I do not think [your code] means what you think it means."
Assuming that surveyResponseListToUpdate was a list of entities previously loaded and modified:
if (answerObject.AnswerOptions.Count > 0) // Unnecessary...
{
foreach (var optItem in answerObject.AnswerOptions)
{
AnswerOptionDataModel answOpt = new AnswerOptionDataModel(); // does nothing.
answOpt = optItem; // references existing answer option..
Context.AnswerOptions.Update(answOpt);
}
}
The whole block boils down to:
foreach (var optItem in answerObject.AnswerOptions)
Context.AnswerOptions.Update(optItem);
The error you are likely running into is because Update will recurse through navigation properties automatically, so when the parent (Answer) is updated, it's AnswerOptions will be updated as well. So when you go through the extra steps to try and save answer options, they've already been updated when the answer was saved. Provided the Answer was loaded by the same context that you are saving it to, you should be in the clear with:
foreach (var answerObject in surveyResponseListToUpdate)
Context.Answers.Update(answerObject);
var recordsAffected = Context.SaveChanges();
This should update the answer and it's associated answer objects. Even if options were added or removed, the change tracking should do it's job and ensure all of the associated data records are updated.
The extra if checks and such aren't necessary and just add to nesting depth making code harder to read.
However, I suspect that your real code is doing something different to the example given that my tests where I tried to reproduce your error, the code worked fine even updating the child references after updating the parent. If the above still raises issues, please update your example with the code you are running.

Is there a REST endpoint to get a list of a project's task assignments in Project Server?

I've tried sending a request to
"/_api/ProjectServer/Projects('projectid')/Assignments", but all it does is return duplicates of the last assignment which is weird because the number of objects it returns is always equal to the number of assignments there are in the project.
Basically if I assign a resource to each of a hundred different tasks, the call returns 100 duplicates of the last task's assignment in the list.
I suspect it might be a bug, I'd appreciate it if someone could confirm or deny my assumption and/or let me know if there's any other way to retrieve the list of assignments in a project.
I didn't exactly know how to work with rest but I would like to provide you with litle lines of code using CSOM that, if I understood properly the question, it might help you:
private static void ListPublishedProjects()
{
// Get the list of projects on the server.
projContext.Load(projContext.Projects);
projContext.ExecuteQuery();
var proj = projContext.Projects.First(p => p.Name == "<project name>");
projContext.ExecuteQuery();
//You must ckeck out the project and load it's tasks
var draftProj = proj.CheckOut();
projContext.Load(draftProj.Tasks);
projContext.ExecuteQuery();
//Loop between all tasks
foreach (DraftTask task in draftProj.Tasks)
{
// Load all assignments in that task
projContext.Load(task.Assignments);
projContext.ExecuteQuery();
//Loop between al assignments
foreach (var assignment in task.Assignments)
{
projContext.Load(assignment.Owner, temp => temp.LoginName, temp => temp.Email);
projContext.Load(assignment.Resource);
projContext.ExecuteQuery();
Console.WriteLine("\n\t RESOURCE NAME:" + assignment.Resource.Name + " => " + assignment.ActualWork);
}
}
//Remember to publish and checkin the project when you finish your TODOs
draftProj.Publish(true);
draftProj.CheckIn(true);
QueueJob qJob = projContext.Projects.Update();
JobState jobState = projContext.WaitForQueue(qJob, 200);
}
}
Hope it helps,

Sequence of Project Deployment in Mule

Does anybody know in what sequence, the mule project are loaded when the Mule starts-up?
It doesn't seem to be in alphabetical order or last updated time.
If you look at the class MuleDeploymentService, you can see the following:
String appString = (String) options.get("app");
if (appString == null)
{
String[] explodedApps = appsDir.list(DirectoryFileFilter.DIRECTORY);
String[] packagedApps = appsDir.list(ZIP_APPS_FILTER);
deployPackedApps(packagedApps);
deployExplodedApps(explodedApps);
}
else
{
String[] apps = appString.split(":");
Description for method File.list states that "there is no guarantee that the name strings in the resulting array will appear in any specific order". So, I guess the answer is in no particular order, or in the order they are listed in using the -app option.

Get package childs from a package

In Eclipse, how can I get the package's children?
Consider this example:
+ org.stack
org.stack.test
- StackTest.java
- Stack.java
When we do IPackageFragment.getChildren() in org.stack, the Eclipse JDT only returns the compilation unit (Java Files)! But I want all children of a package: all ICompilationUnits and all Packages.
In this example when I apply IPackageFragment.getChildren() in org.stack, I want the org.stack.test and the ICompilationUnit Stack.java...
How can I do this?
IPackageFragment is not the correct starting point. You have to ask a higher level for the packages:
IPackageFragment: A single package. It contains ICompilationUnits or IClassFiles, depending on whether the IPackageFragmentRoot is of type source or of type binary. Note that IPackageFragment are not organized as parent-children. E.g. net.sf.a is not the parent of net.sf.a.b. They are two independent children of the same IPackageFragmentRoot.
Have a look at this article about the AST
Here's some code that should be close to what you needed. (Since we're a bit past 2011, I doubt it will help you much, but maybe it will help somebody else.) Doubtless it can stand some improvement.
Since it doesn't seem possible to directly recurse downward from the IPackageFragment (as mentioned by Kai), the basic idea is to get the higher level IPackageFragmentRoot and filter it's children based on the original fragment's path.
PackageFragment originFragment; // = org.stack's fragment
try {
String fragmentPath = originFragment.getPath().toString();
IJavaElement parent = originFragment.getParent();
ArrayList<IJavaElement> allChildren =
new ArrayList<IJavaElement>();
if (parent instanceof IPackageFragmentRoot) {
IPackageFragmentRoot root = (IPackageFragmentRoot)parent;
IJavaElement[] rootChildren = root.getChildren();
// originsFragments includes the origin and all package
// fragments beneath it
List<IJavaElement> originsFragments =
Arrays.asList(rootChildren).stream()
.filter(c -> c.getPath().toString().startsWith(fragmentPath))
.collect(Collectors.toList());
allChildren.addAll(originsFragments);
// Gather the children of the package fragments
for (IJavaElement o : originsFragments) {
if (o instanceof IPackageFragment ) {
IPackageFragment oFragment = (IPackageFragment)o;
IJavaElement[] fChildren = oFragment.getChildren();
allChildren.addAll(Arrays.asList(fChildren));
}
}
}
} catch (JavaModelException e) {
e.printStackTrace();
}
An alternative inelegant solution would be to start with the original fragment's path and then use Java's file and directory facilities to descend through the directory hierarchy. Then, you can use IJavaProject's findPackageFragment(IPath path) to connect to the proper IPackageFragments.
you need to do it in a recursive way.
here's some pseudo code
findAllClasses(package, classesCollection) {
for(Class c: package.getClasses)
classesCollection.add(c.getResourcePath)
if(package.hasChildPackages)
for(Package p: packages)
findAllClasses(p, classesCollection)
}

What is the better way to do the below program(c#3.0)

Consider the below program
private static bool CheckFactorPresent(List<FactorReturn> factorReturnCol)
{
bool IsPresent = true;
StringBuilder sb = new StringBuilder();
//Get the exposure names from Exposure list.
//Since this will remain same , so it has been done outside the loop
List<string> lstExposureName = (from item in Exposures
select item.ExposureName).ToList<string>();
foreach (FactorReturn fr in factorReturnCol)
{
//Build the factor names from the ReturnCollection dictionary
List<string> lstFactorNames = fr.ReturnCollection.Keys.ToList<string>();
//Check if all the Factor Names are present in ExposureName list
List<string> result = lstFactorNames.Except(lstExposureName).ToList();
if (result.Count() > 0)
{
result.ForEach(i =>
{
IsPresent = false;
sb.AppendLine("Factor" + i + "is not present for week no: " + fr.WeekNo.ToString());
});
}
}
return IsPresent;
}
Basically I am checking if all the FactorNames[lstFactorNames] are present in
ExposureNames[lstExposureName] list by using lstFactorNames.Except(lstExposureName).
And then by using the Count() function(if count() > 0), I am writing the error
messages to the String Builder(sb)
I am sure that someone can definitely write a better implementation than the one presented.
And I am looking forward for the same to learn something new from that program.
I am using c#3.0 and dotnet framework 3.5
Thanks
Save for some naming convention issues, I'd say that looks fine (for what I can figure out without seeing the rest of the code, or the purpose in the effort. The naming conventions though, need some work. A sporadic mix of ntnHungarian, PascalCase, camelCase, and abbrv is a little disorienting. Try just naming your local variables camelCase exclusively and things will look a lot better. Best of luck to you - things are looking good so far!
- EDIT -
Also, you can clean up the iteration at the end by just running a simple foreach:
...
foreach (var except in result)
{
isPresent = false;
builder.AppendFormat("Factor{0} is not present for week no: {1}\r\n", except, fr.WeekNo);
}
...