Last active
December 26, 2015 10:58
-
-
Save gravypower/7140018 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 Gravyframe.Service.Messages; | |
namespace Gravyframe.Service.Example | |
{ | |
public class ExampleRequest : Request | |
{ | |
} | |
} |
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 Gravyframe.Service.Messages; | |
namespace Gravyframe.Service.Example | |
{ | |
public class ExampleResponse : Response | |
{ | |
} | |
} |
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 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 | |
{ | |
} | |
} | |
} |
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 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); | |
} | |
} | |
} |
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 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