- 
                Notifications
    You must be signed in to change notification settings 
- Fork 232
Writing Functional Tests
        Allon Guralnek edited this page Dec 12, 2017 
        ·
        1 revision
      
    MicroDot functional testing provides a way to checking running service with mocked dependencies.
public class MyServiceHost : MicrodotOrleansServiceHost
{
    protected override string ServiceName => "MyService";
    protected override void Configure(IKernel kernel, OrleansCommonConfig commonConfig)
    {
        // ...
    }
}
  
public class TestMyServiceHost : MyService
{
    protected override void Configure(IKernel kernel, OrleansCommonConfig commonConfig)
    {
        base.Configure();
        Rebind<IEventPublisher>().To<NullEventPublisher>().InSingletonScope();
        Rebind<ILog>().To<HttpLog>().InSingletonScope();
        Rebind<IMetricsInitializer>().To<MetricsInitializerFake>().InSingletonScope();
    }
}The TestingKernel already binds most subsystems to fakes for easy testing. With it can ask for a ServiceTester.
var kernel = new TestingKernel<ConsoleLog>();You should dispose of it at the end of your tests.
The ServiceTester starts the service in a new AppDomain. Every service in each assembly should run on a different port because by default NUnit parallelizes tests in different assemblies, so they must be in different ports in order not to conflict.
_serviceTester =_initializer.Kernel.GetServiceTester<MyServiceHost>(basePortOverride: ServiceTesterPort);You should dispose ServiceTester at the end of your tests.
[Test]
public async Task SimpleTest()
{
    var myService = _serviceTester.GetServiceProxy<IMyService>();
    (await myService.AreYouOk()).ShouldBeTrue();
}