Created
September 20, 2012 09:13
-
-
Save janderit/3754837 to your computer and use it in GitHub Desktop.
Kata: Fluent DSL Builder Pattern in c#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Kata: Fluent DSL Builder Pattern in c# | |
Es sollen SQL-artige Connectionstrings | |
des Musters | |
SQL:[UserId/Passwort@]{hostname|IP}#dbname | |
durch eine Fluent Konfigurationssprache erstellt werden. | |
#1 Funktionale Anforderungen | |
Folgender Tests sollen ohne Änderungen erfolgreich sein: | |
// gibt einen string zurück | |
string connstr = Connection.Database("somedb").Host("127.0.0.1"); | |
Assert.AreEqual( "SQL:127.0.0.1#somedb", connstr ); | |
// Host darf als IP oder text angegeben werden. Hier soll keine Validierung erfolgen. | |
string connstr = Connection.Database("somedb").Host("localhost"); | |
Assert.AreEqual( "SQL:localhost#somedb", connstr ); | |
// default Hostname soll "localhost" sein | |
string connstr = Connection.Database("somedb"); | |
Assert.AreEqual( "SQL:localhost#somedb", connstr ); | |
// Angabe von User und Passwort (immer zusammen in dieser Reihenfolge) | |
string connstr = Connection.Database("somedb") | |
.Host("127.0.0.1").UserId("xyz").Password("geheim"); | |
Assert.AreEqual( "SQL:xyz/[email protected]#somedb", connstr ); | |
// Die Angabe des Hosts kann auch nach User und Passwort erfolgen | |
string connstr = Connection.Database("somedb").UserId("xyz").Password("geheim") | |
.Host("127.0.0.1"); | |
Assert.AreEqual( "SQL:xyz/[email protected]#somedb", connstr ); | |
#2 Syntaxcheck durch Compiler | |
Zusätzlich soll der C# Compiler! bereits folgenden code als ungültig markieren: | |
// fehlendes Passwort: | |
string connstr = Connection.Database("somedb").Host("127.0.0.1").UserId("xyz"); | |
// keine DB: | |
string connstr = Connection.Host("127.0.0.1"); | |
#3 Einfache Validierung | |
Angegebene Parameter dürfen werde leere Strings noch <null> sein. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment