using System; class Kata { public static string Main(string greeting, string language) { Console.WriteLine(Greeting(greeting, language)); return Greeting(greeting, language); } public static string Greeting(string greeting, string language) => $"{greeting} {language}!"; }
- using System;
- class Kata {
- public static string Main(string greeting, string language) {
- Console.WriteLine(Greeting(greeting, language));
- return Greeting(greeting, language);
- }
public static string Greeting(string greeting, string language) => $"{greeting}, {language}!";- public static string Greeting(string greeting, string language) => $"{greeting} {language}!";
- }
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); 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); } }
- 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);
- 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 + "!" , myString);- Assert.AreEqual(greeting + " " + language + "!
- " , myString);
- }
- }