Skip to content

Instantly share code, notes, and snippets.

@gravypower
Last active December 26, 2015 10:58
Show Gist options
  • Save gravypower/7140018 to your computer and use it in GitHub Desktop.
Save gravypower/7140018 to your computer and use it in GitHub Desktop.
using Gravyframe.Service.Messages;
namespace Gravyframe.Service.Example
{
public class ExampleRequest : Request
{
}
}
using Gravyframe.Service.Messages;
namespace Gravyframe.Service.Example
{
public class ExampleResponse : Response
{
}
}
using System;
using System.Collections.Generic;
namespace Gravyframe.Service.Example
{
public class ExampleService : Service<ExampleRequest, ExampleResponse, ExampleService.NullExampleRequestException>
{
public ExampleService(IEnumerable<ResponseHydrator<ExampleRequest, ExampleResponse>> responseHydratationTasks)
: base(responseHydratationTasks)
{
}
[Serializable]
public class NullExampleRequestException : NullRequestException
{
}
}
}
using System.Collections.Generic;
using Gravyframe.Service.Example;
namespace Gravyframe.Service.Tests
{
public class ExampleServiceTests : ServiceTests<ExampleRequest, ExampleResponse, ExampleService, ExampleService.NullExampleRequestException>
{
public IEnumerable<ResponseHydrator<ExampleRequest, ExampleResponse>> ResponseHydratationTasks;
protected override void ServiceSetUp()
{
ResponseHydratationTasks = new List<ResponseHydrator<ExampleRequest, ExampleResponse>>();
Sut = new ExampleService(ResponseHydratationTasks);
}
}
}
using Gravyframe.Service.Messages;
using NUnit.Framework;
namespace Gravyframe.Service.Tests
{
[TestFixture]
public abstract class ServiceTests<TRequest, TResponce, TService, TNullRequestException>
where TResponce : Response, new()
where TRequest : Request, new()
where TService : Service<TRequest, TResponce, TNullRequestException>
where TNullRequestException : Service<TRequest, TResponce,TNullRequestException>.NullRequestException, new()
{
public TService Sut;
[SetUp]
protected void SetUp()
{
ServiceSetUp();
}
protected abstract void ServiceSetUp();
[Test]
public void CanCreateTService()
{
// Assert
Assert.IsNotNull(Sut);
}
[Test]
public void IsAssignableFromTService()
{
// Assert
Assert.IsInstanceOf<Service<TRequest, TResponce, TNullRequestException>>(Sut);
}
[Test]
public void WhenRequestIsNullTNullRequestThrown()
{
// Assert
Assert.Throws<TNullRequestException>(() => Sut.Get(null));
}
[Test]
public void
WhenTRequestInNotNullTNullRequestExceptionNotThrown()
{
// Assign
var request = new TRequest();
// Assert
Assert.DoesNotThrow(() => Sut.Get(request));
}
[Test]
public void WhenTRequestIsNotNullTResponceNotNull()
{
// Assign
var request = new TRequest();
// Act
var responce = Sut.Get(request);
// Assert
Assert.IsNotNull(responce);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment