- First we need to convert the .xsd into C# classes with the Visual Studio program xsd.exe
- Open the 'Developer Command Prompt for VS2015'
- Execute the command:
- xsd.exe xsdfilename.xsd /outputdir:"{path}" /classes
- If you want to place the generated class in a namespace use /namespace:
- xsd.exe xsdfilename.xsd /classes /namespace:namespacename
- If you have multiple related .xsd-s (with identical children) then it's best to convert them all in one single xsd.exe call to prevent having a lot of duplicate declarations in Visual Studio which will have to be removed or commented out manually:
- xsd.exe xsdfile1.xsd xsdfile2.xsd xsdfile3.xsd /outputdir:"{path}" /classes
- Next is to import the class(es) into VS
- Then it's possible to 'deserialize' existing XML strings into the imported classes via the following code:
- XmlSerializer serializer = new XmlSerializer(typeof(XMLType));
- MemoryStream stream = new MemoryStream();
- StreamWriter writer = new StreamWriter(stream);
- writer.Write(XML_String);
- writer.Flush();
- stream.Position = 0;
- this.AX_Instance = (XMLType)serializer.Deserialize(stream);
- The next step is to serialize an XML object into a string via the following code:
- serializer.Serialize(stream, AX_Instance);
- byte[] newXmlArray = stream.ToArray();
- string newXml = System.Text.Encoding.Default.GetString(newXmlArray);
A Monkey's Ramblings on Software Development
dinsdag 14 maart 2017
C# > Serializing and Deserializing XMLs
Testers generally need to generate lots of testdata. Often this testdata comes in the form of files. So one of the first areas where automation can really help out in the testing effort is in file generation. We're going to look into XML file reading and generation on the basis of the .xsd of the .xml.
vrijdag 3 maart 2017
C# > Why Properties Matter
interesting blog post
http://csharpindepth.com/Articles/Chapter8/PropertiesMatter.aspx
http://csharpindepth.com/Articles/Chapter8/PropertiesMatter.aspx
vrijdag 11 november 2016
Jira > Confluence API > Getting page content
To find a page in confluence via title name and space key:
host/rest/api/content?title=Title%20Page&spaceKey=MYSPACE
This will typically get you the ID of the page.
With the ID it's much easier to find the page. The API call to get the page and all data of it goes like:
host/rest/api/content/{id}?expand=space,body.view,version,container
host/rest/api/content?title=Title%20Page&spaceKey=MYSPACE
This will typically get you the ID of the page.
With the ID it's much easier to find the page. The API call to get the page and all data of it goes like:
host/rest/api/content/{id}?expand=space,body.view,version,container
C# > Modifying xml files
I have been neglecting my blog for way too long again. The short term and adhoc is once again getting in the way of the long term learning. Often test data comes in the way of XML files, and often that data needs to be modified to suit your needs or stay up to date. Recently I have been given the task of enriching existing test XMLs with an extra node. To do this manually would be possible but error-prone and mind-numbingly boring. Let's investigate how we can enrich the test XMLs with this new node automatically.
Scenario 1: we have an .xsd of the test XML which we have converted into C# classes giving us the ability to deserialize the XMLs into C# objects and modify them accordingly.
And... It was actually so easy and trivial to enrich the document via this method it ended the blog post right there.
Scenario 1: we have an .xsd of the test XML which we have converted into C# classes giving us the ability to deserialize the XMLs into C# objects and modify them accordingly.
And... It was actually so easy and trivial to enrich the document via this method it ended the blog post right there.
vrijdag 7 oktober 2016
C# > October > DUH! Moments
Time for a new month of facepalms!
- GUID stands for...
- Globally Unique Identifier
- In Visual Studio:
- The key combo for 'Quick Actions' is: CTRL + .
C# > September > DUH! Moments
- When working with I/O, Streams, Writers, etc. ALWAYS use 'using{}'
- In regex the '?' makes the preceding item optional:
- Or: '?' in regex means '0 or 1'
- An? (matches both A and An)
- 23(rd)? (matches both 23 and 23rd)
- In SpecFlow: when using regex step definition bindings you can create step definition methods with multiple parameters easily by having multiple (.*)s in the regex.
- C#/.NET syntax for pattern matching:
- string pattern = "[regex pattern]"
- string input = "[input]"
- Match match = Regex.Match(input, pattern);
- AssertTrue(match.Success) etc.
- Useful methods of DateTime objects:
- myDateTime.AddDays(int days)
- myDateTime.AddMonths(int months)
- etc.
- In Visual Studio: when debugging the immediate window is an amazing section where you can type statements which will be immediately executed and the value shown.
- A class containing [Fact]-s for xunit.net should be public
- ?? operator
- if/else operator with nullable argument
- LINQ:
- var query = from element in collection select element.attribute
- var query = collection.Select(element => element.attribute)
- In regex:
- '+' means '1 or more'
- '$' means 'end of string or end of line'
- '\d' means 'digit'
- Working with the JIRA REST API and the JIRA Zephyr API (ZAPI) I've been making my very first steps in web-based APIs. So there are a LOT of "DUH!" moments. The most newbie one so far:
- We have GET requests, and POST requests.
- GET requests:
- Have no body
- Arguments to the request are passed via the URL.
- Example: /api/latest/resource?argumentName=argumentValue
- POST requests:
- (Can) have a body
- Arguments to the requests are typically passed via a body (such as JSON)
- If you don't follow these rules you get fancy error messages such as:
- "Cannot send a content-body with this verb-type".
- The different calls and what they mean:
- GET: read
- POST: create
- PUT: update
- DELETE: delete
- (apparently there is PATCH as well - no idea what it is)
woensdag 21 september 2016
MTM > Microsoft Test Manager > First Steps
I will have to setup a test automation framework at my new job and considering the fact that my new company essentially uses the entire Microsoft stack I'm going to see if Microsoft Test Manager (MTM) will suit our purposes.
Long live the Pluralsight courses:
- Structure:
- Test Plan
- Test Suite
- Test Cases
- Test Plan Configuration
- What are you testing?
- How are you testing it?
- Test Plans are now TFS Work Items
- Inside the Test Plan:
- Plan
- Test
- Track
- Organize
- Plan section:
- Contents
- Results
- Properties
- Test Plan Properties (& Run Settings):
- Settings
- Environments
- Assigned Builds
- Test Configurations
- Run Settings:
- Test settings:
- General
- Roles
- Data and Diagnostics (there is a LOT here)
- Summary
- Test environment
- This leads to the 'lab section' of the MTM which is out of scope for the course. TODO: Lab section MTM.
- Builds:
- Information about against which build the tests are ran.
- Configurations:
- Operating System
- Browser etc.
- If multiple configurations are applied to the Test Plan then a single Test Case will be 'created twice' - one for each of the configurations.
- Customizations
- Test Plans are now considered TFS work items, this has all sorts of handy consequences. Such as:
- Work Item
- Fields & States
- History
- TODO: Lean about Work Items.
- For example: make changes to the Work Items states with the help of Windows Powertools.
- Track section:
- Here we can query for Work Items (and therefore also Test Cases etc.)
- MTM Web Interface: with the correct licenses there is a really handy Web Interface in the case you require MTM on machines that don't have MTM installed.
- Plan: Create Test Suites and Test Cases
- Test Suites
- Types:
- Static
- Requirements-based
- Query-based
- Out-of-the-box states:
- In Planning
- In Progress
- Completed
- Aside:
- Test Cases are now available as TFS work items
- You can add Test Suites to the Test Plan
- Be they Static, Requirements-based, Query-based, etc.
- You can then add Requirements to the Test Suite
- Doing so will open a window in which to query for TFS requirements
- Test Cases
- Are TFS Work Items with all the accompanying benefits
- Consist of Steps
- Can be assigned to Testers
- Can have their own sets of configurations
- Test Points
- Test Cases x nr. of configurations
- Test results are tied to a Test Point
- LEARNING MOMENT
- In MTM:
- ADD stands for adding something existing
- NEW stands for creating something... new(!)
- END LEARNING MOMENT
- Creating Test Cases:
- Steps
- Summary
- Tested Backlog Items
- Links
- Attachments
- Associated Automation
Aannnnnnnd... it's gone.
If the goal is to fail hard and fail fast we're not doing too badly, because after investing roughly a day into MTM it has become clear that this is currently not an efficient tool for my new company. So we're dropping the course and this line of MTM investigation. Next step: Zephyr for Jira!
Abonneren op:
Reacties (Atom)