With the TDD series in full swing - any feedback out there? anyone? - some interesting TDD and coding links have been coming up recently
Download all the test and program code generated by the end of this article here.
With a selection of schemas tested and a set of CodeDom tests established for the checks we're most likely to need in part 2, let's turn our attention to the tweaks we want to make to the generated CodeNamespace members. Here's my initial list - we could well add to it later on providing more tests are written to cover the additional code.
- Change the field \ property names from elementField\Element to element\Element
- Change the type of a field \ property
- Change the name of a type
- Change the way dates are serialized.
- Change the way boolean values are serialized.
In this post, we'll build the code that makes the first these changes.
Download code covering all the tests and code so far from this series here.
In the last episode, we started building our alternate to xsd.exe and wrote a set of five tests that made sure the converter worked against the smallest possible schema. We also learnt about building basic schemas programmatically. Next up, we'll look at some more basic pieces of a schema and start working in the CodeNamespace area.
So let's lay out what we want our application to do.
- Convert any number of given, connected schema files to a set of C# classes
- Allow us to tweak aspects of the generated classes to suit our needs elsewhere - for example, change field, property and class names to our own naming conventions or the way something is serialized.
- Save the generated classes into a given file.
- Present some sort of UI that allows us to specify what tweaks should be made.
- Save those settings for reuse later on.
With that in mind, let's bear in mind the mantra of 'code little, think, code a little more' and write some tests. The heart of our app is a two stage process.
- Convert schema to namespace
- Tweak namespace
So let's start on stage one and write some tests.