Skip to content

Instantly share code, notes, and snippets.

@KenBonny
Last active January 6, 2018 16:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KenBonny/be5add0a438ede0eb1386e93657c79ff to your computer and use it in GitHub Desktop.
Save KenBonny/be5add0a438ede0eb1386e93657c79ff to your computer and use it in GitHub Desktop.
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