3
votes

When I create a Service with ServiceStack and can them easily test when just instanciating the class and running my unit tests.

But with this approach the validators don't get fires, because the runtime binds them and they are triggert before the serivce is called.

Do I have to make IntegrationTests with a running service ? Or is there a smarter way`?

2

2 Answers

10
votes

We do both: unit test the actual validator and then also full integration test - so we can test out the whole filter pipeline.

Our unit tests look some thing like:

    [Test]
    public void Validate_POST_ValidRequest_ExpectIsValidTrue()
    {
        var request = new MyRequest { Id =99, Name = "fr", Venue = "My Venue", Age = 9 };

        var validateRunner = new MyValidator();
        var result = validateRunner.Validate(request, ruleSet: "POST");

        Assert.That(result.IsValid, Is.True);
    }
3
votes

It depends on what actually you want to test. You can make a test just for your validator class passing different DTO Request objects. You can also make an integration test by inheriting your test fixture from TestBase.