2

我曾经有过这个测试,它通过得很好(一旦处理了所有三个消息,传奇就完成了。

        Test.Saga<TestSagaHandler>(sagaId)
            .When(x =>
            {
                x.Handle(new TestSagaStartMessageOne
                {
                    Id = sagaId
                });
                x.Handle(new TestSagaStartMessageTwo
                {
                    Id = sagaId
                });
                x.Handle(new TestSagaNonStartingMessage
                {
                    Id = sagaId
                });
            });
            .AssertSagaCompletionIs(true);

我现在想将 TestSagaNonStartingMessage 分解为它自己的处理程序,并执行以下操作:

        Test.Saga<TestSagaHandler>(sagaId)
            .When(x =>
            {
                x.Handle(new TestSagaStartMessageOne
                {
                    Id = sagaId
                });
                x.Handle(new TestSagaStartMessageTwo
                {
                    Id = sagaId
                });
            });

        Test.Saga<TestSagaHandlerSingleMessage>(sagaId)
            .When(x =>
                x.Handle(new TestSagaNonStartingMessage
                {
                    Id = sagaId
                })
            )
        .AssertSagaCompletionIs(true);

但是,在处理 TestSagaNonStartingMessage 时 - 传奇数据不会从以前的处理程序中保留下来。

我是否有持久性问题,或者测试构建得不好?

4

2 回答 2

3

测试构造不正确 - 请查看制造样本中的测试项目以了解其结构。简短的回答是在第一个之后链接第二个 .When(...) 。

于 2011-06-02T21:06:39.677 回答
1

供其他读者参考,正确的测试结构应该类似于:

    Test.Saga<TestSagaHandler>(sagaId)
        .When(x =>
        {
            x.Handle(new TestSagaStartMessageOne { Id = sagaId });
            x.Handle(new TestSagaStartMessageTwo { Id = sagaId });
        })
        .When(x =>
            x.Handle(new TestSagaNonStartingMessage { Id = sagaId })
        )
        .AssertSagaCompletionIs(true);

正如 Udi 所指出的,将“When”子句链接在一起。

此外,为了从测试中获得更多价值,请考虑引入异常,例如ExpectSend<>ExpectPublish等。

参考:http ://docs.particular.net/nservicebus/testing/

于 2015-11-12T15:00:34.043 回答