예제 #1
0
    public async Task Try()
    {
        var persister  = new InMemorySagaPersister();
        var inbox      = new InMemoryInbox();
        var dispatcher = new FakeDispatcher();
        var manager    = new SagaManager(persister, inbox, dispatcher);

        await manager.Process <SagaData>("messageId", "correlationId", new ContextBag(),
                                         HandlerCallback);

        var dataContainer = await persister.LoadByCorrelationId("correlationId");

        var sagaData = (SagaData)dataContainer.SagaData;

        Assert.AreEqual(1, sagaData.Counter);
    }
예제 #2
0
    public async Task PerformScenario(string scenario)
    {
        var controller = new TestController(scenario);
        var persister  = new InMemorySagaPersister();
        var inbox      = new InMemoryInbox();
        var dispatcher = new FakeDispatcher();
        var persisterA = new TestingSagaDataPersister(persister, inbox, 'A', controller.GetBarrier);
        var persisterB = new TestingSagaDataPersister(persister, inbox, 'B', controller.GetBarrier);

        var managerA = new SagaManager(persisterA, persisterA, dispatcher);
        var managerB = new SagaManager(persisterB, persisterB, dispatcher);

        var processA = Task.Run(() => ProcessMessage(managerA, controller));
        var processB = Task.Run(() => ProcessMessage(managerB, controller));

        var done = Task.WhenAll(processA, processB);
        await done.ConfigureAwait(false);

        var dataContainer = await persister.LoadByCorrelationId("correlationId");

        var sagaData = (SagaData)dataContainer.SagaData;

        Assert.AreEqual(1, sagaData.Counter);
    }