Last active
January 6, 2018 16:32
-
-
Save KenBonny/be5add0a438ede0eb1386e93657c79ff to your computer and use it in GitHub Desktop.
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
using Xunit; | |
using Xunit.Abstractions; | |
namespace KenBonny.TestProject.Tests | |
{ | |
public class CtorTests | |
{ | |
private readonly ITestOutputHelper _console; | |
public CtorTests(ITestOutputHelper console) | |
{ | |
_console = console; | |
} | |
[Fact] | |
public void Test() | |
{ | |
var intTest = new Response<int>(1); | |
WriteToConsole(intTest); | |
var intErrorTest = new Response<int>("error"); | |
WriteToConsole(intErrorTest); | |
var strShouldBeValueTest = new Response<string>("good"); | |
WriteToConsole(strShouldBeValueTest); | |
var strIsValueTest = new Response<string>(value: "good"); | |
WriteToConsole(strIsValueTest); | |
var strErrorTest = new Response<string>("error"); | |
WriteToConsole(strErrorTest); | |
} | |
private void WriteToConsole<T>(Response<T> response) | |
{ | |
if (response.IsError) | |
_console.WriteLine($"Error: {response.Error}"); | |
else | |
_console.WriteLine($"Value: {response.Value}"); | |
} | |
} | |
class Response<T> | |
{ | |
public Response(T value) | |
{ | |
Value = value; | |
IsError = false; | |
} | |
public Response(string error) | |
{ | |
Error = error; | |
IsError = true; | |
} | |
public T Value { get; } | |
public string Error { get; } | |
public bool IsError { get; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment