Just added some additional classes and functions to help make it modular and so others can build ontop of it.
using System; using System.Collections.Generic; using System.Linq; class Kata { public static string Main(string language) { var salutations = new DeveloperGreeting().GreetMyDeveloper(language); Console.Write(salutations); return salutations; } } //Returns the developer greeting message. class DeveloperGreeting { public string GreetMyDeveloper(string language){ return new GreetingRepository().GetDeveloperGreetings(language).message; } } //Get greeting data from either a collection or database store. class GreetingRepository { public List<Greeting> greetings; public GreetingRepository() { greetings = new List<Greeting>(){ new Greeting(){language = "C#", message = "Hello my fellow C# developers, work hard."}, new Greeting() {language = "Java", message = "Hello my fellow Java developers, work hard."} }; } public Greeting GetDeveloperGreetings(string language){ var g = greetings.Where(x => x.language.Equals(language)).ToList(); return new Greeting(){ language = g[0].language, message = g[0].message}; } } //Greeting Model class class Greeting{ public string language {get; set;} public string message {get; set;} }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- class Kata {
public static string Main(string greeting, string language) {Console.Write("{0}, {1}!\n", greeting, language);return greeting + ", " + language + "!";- public static string Main(string language) {
- var salutations = new DeveloperGreeting().GreetMyDeveloper(language);
- Console.Write(salutations);
- return salutations;
- }
}- }
- //Returns the developer greeting message.
- class DeveloperGreeting {
- public string GreetMyDeveloper(string language){
- return new GreetingRepository().GetDeveloperGreetings(language).message;
- }
- }
- //Get greeting data from either a collection or database store.
- class GreetingRepository {
- public List<Greeting> greetings;
- public GreetingRepository() {
- greetings = new List<Greeting>(){
- new Greeting(){language = "C#", message = "Hello my fellow C# developers, work hard."},
- new Greeting() {language = "Java", message = "Hello my fellow Java developers, work hard."}
- };
- }
- public Greeting GetDeveloperGreetings(string language){
- var g = greetings.Where(x => x.language.Equals(language)).ToList();
- return new Greeting(){ language = g[0].language, message = g[0].message};
- }
- }
- //Greeting Model class
- class Greeting{
- public string language {get; set;}
- public string message {get; set;}
- }
using NUnit.Framework; using System; using System.IO; [TestFixture] public class KataTests { [Test] public void Prints_expected_output() { string language = "C#"; var originalConsoleOut = Console.Out; // preserve the original stream var writer = new StringWriter(); Console.SetOut(writer); //ready to listen to console Kata.Main(language); writer.Flush(); // when you're done, make sure everything is written out var myString = writer.GetStringBuilder().ToString(); Console.SetOut(originalConsoleOut); // restore Console output Assert.AreEqual("Hello my fellow C# developers, work hard.", myString); } }
- using NUnit.Framework;
- using System;
- using System.IO;
- [TestFixture]
- public class KataTests
- {
- [Test]
- public void Prints_expected_output()
- {
- string language = "C#";
string greeting = "Hello";- var originalConsoleOut = Console.Out; // preserve the original stream
- var writer = new StringWriter();
- Console.SetOut(writer);
- //ready to listen to console
Kata.Main(greeting, language);- Kata.Main(language);
- writer.Flush(); // when you're done, make sure everything is written out
- var myString = writer.GetStringBuilder().ToString();
- Console.SetOut(originalConsoleOut); // restore Console output
Assert.AreEqual(greeting + ", " + language + "!\n" , myString);- Assert.AreEqual("Hello my fellow C# developers, work hard.", myString);
- }
- }