Generic test with summary result file, "Summary Result File Schema Could Not Be Loaded" - unit-testing

I'm doing some experiments with use of generic test and use of summary result files. The purpose with summary result files is to be able to split one generic test into several smaller inner tests.
I have a small test setup like this:
My generic test looks like this (TestPass.GenericTest):
<?xml version="1.0" encoding="UTF-8"?>
<GenericTest name="TestPass" storage="c:\tfs\mstest\testpass.generictest" id="481fe683-c835-4cf5-aa15-532b4e4e50df" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
<Execution id="087a367f-ac5b-4ab7-bb69-e506b436f51b" />
<Command filename="runtest.bat" arguments="%TestOutputDirectory%" workingDirectory="%TestLocation%" />
<SummaryXmlFile enabled="true" path="LocalTest.trx" />
</GenericTest>
When running this test it simply calls a bat-file which generate the summary result files and the inner result files:
runtest.bat:`
copy sr.xml "%TestOutputDirectory%"\LocalTest.trx
copy r1.txt "%TestOutputDirectory%"\Results1.txt
copy r2.txt "%TestOutputDirectory%"\Results2.txt
sr.xml:
<SummaryResult>
<TestName>ParentTest</TestName>
<TestResult>Passed</TestResult>
<InnerTests>
<InnerTest>
<TestName>InnerTest1</TestName>
<TestResult>Passed</TestResult>
<ErrorMessage>Everything is fine.</ErrorMessage>
<DetailedResultsFile>Results1.txt</DetailedResultsFile>
</InnerTest>
<InnerTest>
<TestName>InnerTest2</TestName>
<TestResult>Failed</TestResult>
<ErrorMessage>Something went wrong.</ErrorMessage>
<DetailedResultsFile>Results2.txt</DetailedResultsFile>
</InnerTest>
</InnerTests>
</SummaryResult>
r1.txt:
This is the the resultfile for innertest1
r2.txt:
This is the the resultfile for innertest2
I run the test like this:
mstest /testcontainer:TestPass.GenericTest
And now to the problem. The test fails with "Summary Result File Schema Could Not Be Loaded"

You must generate a valid XML file.
see:
http://blogs.msdn.com/b/chrsmith/archive/2005/12/07/summary-results-file-in-vsts.aspx this is solution 4u

Related

xmlstarlet extract values from Office 365 XML Files

I am attempting to extract the IPv4 Addresses and URLs for each product in the Office 365 portfolio from http://go.microsoft.com/fwlink/?LinkId=533185. I would like to create an input file for updating Firewall and Proxy server rules.
Snippet from XML File
<?xml version="1.0" encoding="utf-8"?>
<products updated="8/31/2016">
<product name="WAC">
<addresslist type="IPv6">
<address>2a01:111:f406:8800::/64</address>
<address>2a01:111:f406:400::/64</address>
<address>2a01:111:f406:1c01::/64</address>
<address>2a01:111:f406:9400::/64</address>
<address>2a01:111:f406:2402::/64</address>
<address>2a01:111:f406:a804::/64</address>
<address>2a01:111:f406:b401::/64</address>
<address>2620:1ec:c11::204</address>
<address>2a01:111:202c::204</address>
<address>2620:1ec:c11::205</address>
<address>2a01:111:202c::205</address>
</addresslist>
<addresslist type="IPv4">
<address>13.69.187.20/32</address>
<address>13.70.184.242/32</address>
<address>13.71.155.176/32</address>
<address>13.75.153.216/32</address>
<address>13.76.140.48/32</address>
<address>13.78.114.39/32</address>
<address>13.85.84.102/32</address>
<address>13.88.248.161/32</address>
<address>13.88.254.212/32</address>
<address>13.94.209.165/32</address>
<address>23.103.183.15/32</address>
<address>40.68.166.51/32</address>
<address>40.74.130.243/32</address>
<address>40.74.138.42/32</address>
<address>40.76.54.124/32</address>
<address>40.86.230.88/32</address>
<address>40.114.192.209/32</address>
<address>40.117.226.146/32</address>
<address>40.126.236.216/32</address>
<address>40.127.79.139/32</address>
<address>52.169.109.48/32</address>
<address>52.172.13.171/32</address>
<address>52.172.153.104/32</address>
<address>52.175.25.142/32</address>
<address>52.232.128.169/32</address>
<address>104.40.225.204/32</address>
<address>104.41.62.54/32</address>
<address>104.211.103.207/32</address>
<address>104.211.229.230/32</address>
<address>104.214.38.136/32</address>
<address>104.215.194.17/32</address>
<address>134.170.27.86/32</address>
<address>134.170.48.20/32</address>
<address>134.170.48.22/32</address>
<address>134.170.65.86/32</address>
<address>134.170.170.86/32</address>
<address>137.116.172.39/32</address>
<address>137.135.65.72/32</address>
<address>191.235.87.181/32</address>
<address>191.237.40.220/32</address>
</addresslist>
<addresslist type="URL">
<address>*.officeapps.live.com</address>
<address>*.cdn.office.net</address>
</addresslist>
</product>
<product name="Sway">
I have figured out out to list the products which can be used as to cycle through the products to get the end result but I can seem to get past filtering on a particular product and IPv4 address.
./xmlstarlet sel -t -m '/products/product' -v #name -n Downloads/O365IPAddresses.xml
WAC
Sway
Planner
Yammer
OneNote
OfficeiPad
OfficeMobile
ProPlus
RCA
LYO
SPO
Office365Video
identity
EXO
CRLs
o365
EOP
I have tried many variations of the following and no output.
./xmlstarlet sel -t -m '//root/products/product[name="WAC"]/addresslist[type="IPv4"]' Downloads/O365IPAddresses.xml
Ultimately I would like to get to a text file that has something like the following.
WAC,IPv4,13.69.187.20/32
WAC,IPv4,13.70.184.242/32
.....
.....
WAC,URL,*.officeapps.live.com
I can then use this csv file to update the collection of Firewalls and Proxy servers in my company.
Many thanks in advance for the help.

xbuild with [System.Text.RegularExpressions.Regex]::Match(string,string) parameters doesn't work properly (MSBuild is fine)

I have a target that reads a .proj file with ReadLinesFromFile and then try to match a version number (e.g. 1.0.23) from the contained lines like:
<Target Name="GetRevision">
<ReadLinesFromFile File="$(MyDir)GetStuff.Data.proj">
<Output TaskParameter="Lines" ItemName="GetStuffLines" />
</ReadLinesFromFile>
<PropertyGroup>
<In>#(GetStuffLines)</In>
<Out>$([System.Text.RegularExpressions.Regex]::Match($(In), "(\d+)\.(\d+)\.(\d+)"))</Out>
</PropertyGroup>
<Message Text="Revision number [$(Out)]" />
<CreateProperty Value="$(Out)">
<Output TaskParameter="Value" PropertyName="RevisionNumber" />
</CreateProperty>
</Target>
The result is always empty.. Even if I try to do a simple Match($(In), "somestring") its not working correctly in linux/xbuild. This does work on windows/msbuild
Any tricks/ideas? An alternative would be to get the property version out of the first .proj file, instead of reading all lines and matching the number with a regex, but I don't even know if that is possible.
I am running versions:
XBuild Engine Version 12.0
Mono, Version 4.2.1.0
EDIT:
I've been able to trace it further down into the parameters that go into Match(), there is something wrong with the variables evaluation. The function actually works with for example Match("foobar","bar") I will get bar
But weird things happen with other inputs, e.g. Match($(In), "Get") will match Get because it is actually matching against the string "#(GetStuffLines)"
When I do Match($(In), "#..") I will get a match of #(G
But then, when I do Match($(In), "#.*") I actually get the entire content of the input file GetStuff.Data.proj which indicates that the variable was correctly expanded somewhere and the matching matched the entire input string.
I needed to circumvent Match() because it seems to be bugged at this point.
The ugly solution I came up with was to use Exec and grep the pattern like:
<Exec Command="grep -o -P '[0-9]+[.][0-9]+[.][0-9]+' $(MyDir)GetStuff.Data.proj > extractedRevisionNumber.tmp" Condition="$(OSTYPE.Contains('linux'))"/>
<ReadLinesFromFile File="$(ComponentRootDir)extractedRevisionNumber.tmp" Condition="$(OSTYPE.Contains('linux'))">
<Output TaskParameter="Lines" ItemName="GetExtractedRevisionNumber" />
</ReadLinesFromFile>
I couldn't even use the properties ConsoleToMSBuild and ConsoleOutput (https://msdn.microsoft.com/en-us/library/ms124731%28v=VS.110%29.aspx) because xbuild didn't recognize those.. That's why I grep the pattern and save it into a temp file which can be read with ReadLinesFromFile into the ItemName="GetExtractedRevisionNumber" that I use later.

BASH script to rename XML file to an attribute value

I have a lot of .xml files structured the same way:
<parent id="idvalue" attr1="val1" attr2="val2" ...>
<child attr3="val3" attr4="val4" ... />
<child attr3="val5" attr4="val6" ... />
...
</parent>
Each file has exactly one <parent> element with exactly one id attribute.
All of those files (almost 1,700,000 of them) are named as part.xxxxx where xxxxx is a random number.
I want to name each of those files as idvalue.xml, according to the sole id attribute from the file's content.
I believe doing it with a bash script would be the fastest and most automated way. But if there are other suggestions, I would love to hear them.
My main problem is that I am not able (don't know how) to get the idvalue in a specific file, so that I could use it with the mv file.xxxxx idvalue.xml command.
First I would iterate through the xml files using find:
find -maxdepth 1 -name 'part*.xml' -exec ./rename_xml.sh {} \;
The line above will execute rename_xml.sh for every xml file, passing the file name as command argument to the script.
rename_xml.sh should look like this:
#!/bin/bash
// Get the id using XPath. You might probably need
// to install xmllint for that if it is not already present.
// The xpath query will return a string like this (try it!):
//
// id="idvalue"
//
// We are using sed to extract the value from that
id=$(xmllint --xpath '//parent/#id' "$1" | sed -r 's/[^"]+"([^"]+).*/\1/')
mv -v "$1" "$id.xml"
Don't forget to
chmod +x rename_xml.sh
Use a proper XML handling tool to extract the id from the files. For example,
xsh:
for file in part.* ; do
mv "$file" $(xsh -aC 'open { shift }; echo /parent/#id' "$file").xml
done
Like I mentioned in my comment that I am not sure about the performance of XSLT in compared to bash scripts, but I created the XSLT for you to try out.
In the stylesheet below, Dire is the directory that contains the xml files.The select "tokenize(document-uri(.), '/')[last()]"
retrieves the filename and the second line concatenates the directory name with the filename to get the path of the file.The line with xsl:copy..is used to copy the entire xml.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxml="urn:schemas-microsoft-com:xslt" xmlns:random="http://www.microsoft.com/msxsl">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<xsl:for-each select="collection('Dire/?select=*.xml')" >
<xsl:variable name="filename" select="tokenize(document-uri(.), '/')[last()]"/>
<xsl:variable name="filepath" select="concat('Dire/',$filename)"/>
<xsl:variable name="doc" select="document($filepath)"/>
<xsl:variable name="outname" select="$doc/parent/#id"/>
<xsl:result-document href="{$outname}.xml" method="xml">
<xsl:copy-of select="$doc/node()"/>
</xsl:result-document>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
I ran the xslt using saxon8. Unfortunately I could not find any way to rename the xml directly.But the above code should be worth a try.

RegexFilter with RollingFileAppender not working properly

I am trying to use Regexfilter in RollingFileAppender. For 1st matching instance it retreived the logger, but after that I different patttern but nothing is logged in the file. Here is what I am using:
Main Class:
public class MainApp {
public static void main(String[] args) {
final Logger logger = LogManager.getLogger(MainApp.class.getName());
ApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml");
HelloWorld obj = (HelloWorld) context.getBean("helloWorld");
logger.trace("NPF:Trace:Entering Log4j2 Example.");
logger.debug("NTL:debug Entering Log4j2 Example.");
obj.getMessage();
Company comp = new Company();
comp.setCompName("ANC");
comp.setEstablish(1889);
CompanyBusiness compBus = (CompanyBusiness)context.getBean("compBus");
compBus.finaceBusiness(comp.getCompName(), comp.getEstablish());
logger.trace("NTL: Trace: Exiting Log4j2 Example.");
}
}
log4j2.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<Configuration>
<Appenders>
<Console name="STDOUT" target="SYSTEM_OUT">
<PatternLayout pattern="%d{yyyy-MM-dd [%t] HH:mm:ss} %-5p %c{1}:%L - %m%X%n" />
</Console>
<RollingFile name="RollingFile" fileName="C:\logTest\runtime\tla\els3.log" append="true" filePattern="C:\logTest\runtime\tla\els3-%d{yyyy-MM-dd}-%i.log" >
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %m%X%n" />
<RegexFilter regex=".*business*." onMatch="ACCEPT" onMismatch="DENY"/>
<Policies>
<SizeBasedTriggeringPolicy size="20 MB" />
</Policies>
</RollingFile>
</Appenders>
<Loggers>
<Logger name="com.anc" level="trace"/>
<Root level="trace">
<AppenderRef ref="STDOUT" />
<AppenderRef ref="RollingFile"/>
</Root>
</Loggers>
</Configuration>
When I ran for the first time, in my logfile I got logs having only "business" related line. Latter I changed the patter from .business (pattern has astreik before and after business word). to "business", logging did not happen in file nor on the console. Also my application terminated without any kind of logging.
Then I tried to revert back the pattern to '.business.' (pattern has astreik before and after business word), thereafter no logging happened on the log file, but on the console all the log trace is printed. When I comment out the Regexfilter after trying for long time, my logs was printed in the log file.
I am not sure if this is a bug of Regexfilter works only for one time. Also if we do not pass any patter matching characters, the application stops without any log printing either on console or file.
If you want to log all events containing the word "business", then you shall use the regex .*business.* instead of .*business*.. Here is an example:
<RegexFilter regex=".*business.*" onMatch="ACCEPT" onMismatch="DENY"/>
For information, .*business*. means: anything, followed by business, followed by s character 0 or more time, followed by any single character.
More explaining:
. means any single character
* means 0 or more times
so .* means any character, 0 or more times.

msbuild c++ : how do I supply desired version info as command line parameter?

I'm building a C++ application on a CruiseControl.Net buildserver.
The build itself is done by msbuild and through cruisecontrol.net I have the desired version available - but I can't get it to be stamped into the c++ output.
Below is my msbuild project file.
Any comments are appreciated,
Anders, Denmark
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="FullBuild" ToolsVersion="3.5">
<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>
<UsingTask TaskName="NCover.MSBuildTasks.NCover" AssemblyFile="C:\Program Files\NCover\Build Task Plugins\NCover.MSBuildTasks.dll"/>
<UsingTask TaskName="NCover.MSBuildTasks.NCoverReporting" AssemblyFile="C:\Program Files\NCover\Build Task Plugins\NCover.MSBuildTasks.dll"/>
<ItemGroup>
<MyBinaries Include="Build\*.*"/>
</ItemGroup>
<PropertyGroup>
<CCNetLabel Condition="$(CCNetLabel)==''">2.0.0.0</CCNetLabel>
</PropertyGroup>
<ItemGroup>
<Projects Include="$(vsproject)" />
</ItemGroup>
<Target Name="Rebuild">
<MSBuild Projects="#(Projects)" StopOnFirstFailure="true" ContinueOnError="false" Targets="Rebuild" Properties="version=$(CCNetLabel)" />
</Target>
</Project>
In your buildscript, create a file (version.info) which will look like this:
#define BINVERSION 1,2,3,4
#define STRVERSION "1.2.3.4"
You might need to create a small utility to do that.
In your resourcefile, you will have a versioninfo rescource, the start will look like this:
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,2,3,4
PRODUCTVERSION 1,2,3,4
(...)
VALUE "FileVersion", "1.2.3.4"
VALUE "ProductVersion", "1.2.3.4"
Replace that with something like this:
VS_VERSION_INFO VERSIONINFO
FILEVERSION BINVERSION
PRODUCTVERSION BINVERSION
(...)
VALUE "FileVersion", STRVERSION
VALUE "ProductVersion", STRVERSION
Don't forget to add #include "version.info" at the top of the resource file
When you now compile your application, it will have the correct versionnumber. (if you correctly created the version.info).
Also take a look at Automatic Build Versioning in Visual Studio (codeproject)
I ended up just doing a search & replace on the .rc file.
Wimmels suggestion was good, but if I need to write a custom tool I might as well keep the rest simple. I tried out a single freeware search and replace tool, but it messes up the format of the rc file and it's really simple to do the replace yourself. For completeness, I include the code for search-replace below.
Thanks all!
Anders, Denmark
Target in msbuild project file:
<Target Name="UpdateVersion">
<Exec Command="..\CCNetConfig\tools\SearchReplace\SearchReplace.exe project\project.rc $(CCNetLabel)"/>
</Target>
Search & Replace:
class Program
{
static void Main(string[] args)
{
if (args.Length!=2)
{
Console.WriteLine("Must call with two args:");
Console.WriteLine("1 - File");
Console.WriteLine("2 - Version");
Environment.Exit(1);
}
var fileName = args[0];
var version = args[1];
var commaVersion = version.Replace(',', '.');
var allLines = File.ReadAllLines(fileName).ToList();
for (int i = 0; i < allLines.Count(); i++)
{
allLines[i] = allLines[i].Replace("1.0.0.1", version);
allLines[i] = allLines[i].Replace("1,0,0,1", commaVersion);
}
File.WriteAllLines(fileName, allLines);
}
}
From the CruiseControl.Net standpoint everything looks fine. The CCNetLabel property should have the correct value. You could print it out with the Message task just to be sure.
I don't have any experience with C++ projects, but if you're not using Visual Studio 2010, MSBuild is only delegating the build to VCBuild which could be the reason why the version you pass in is not being used (the same should happen if you manually call MSBuild with e.g. /p:version=1.2.3.4).
You might want to take a look at this question. Maybe you could solve your problem as well by overriding the vsprops file.