Tôi đang cố gắng làm theo bài viết này (http://blog.zoolutions.se/post/2010/04/01/Conquering-NServiceBus-part-4-e28093-Testing.aspx) để tạo kiểm tra đơn vị cho sservicebus saga của tôi dự ánLàm thế nào để tạo các bài kiểm tra đơn vị cho NServiceBus Saga?
Xem mã sau, không chắc chắn lý do tại sao nó luôn luôn khiếu nại bất cứ ai biết làm thế nào tôi có thể sửa chữa nó?
(Tôi đang sử dụng xe buýt nservice 2,0)
public class ReportSaga : Saga<ReportSagaData>,
IAmStartedByMessages<RequestReportMessage>,
IHandleMessages<PollingReportStatusMessage>
{
// implementation
}
[TestFixture]
public class ReportSaga_HandleRequestReportMessageTests
{
[TestFixtureSetUp]
public void SetUp()
{
var assemblies = new[]
{
typeof (ReportSaga).Assembly,
typeof (RequestReportMessage).Assembly,
typeof (PollingReportStatusMessage).Assembly,
Assembly.Load("NServiceBus"),
Assembly.Load("NServiceBus.Core")
};
Test.Initialize(assemblies);
}
[Test]
public void HandleRequestReportMessageTests()
{
Test.Handler<ReportSaga>()
.OnMessage<RequestReportMessage>(x =>
{
x.Id = 1234;
x.ReportDate = DateTime.Now;
});
}
}
Test 'UnitTests.ReportSaga_HandleRequestReportMessageTests.HandleRequestReportMessageTests' failed: System.ArgumentException : GenericArguments[0], 'ReportSagaData', on 'NServiceBus.IMessageHandler`1[T]' violates the constraint of type 'T'.
----> System.TypeLoadException : GenericArguments[0], 'ReportSagaData', on 'NServiceBus.IMessageHandler`1[T]' violates the constraint of type parameter 'T'.
at System.RuntimeType.ValidateGenericArguments(MemberInfo definition, RuntimeType[] genericArguments, Exception e)
at System.RuntimeType.MakeGenericType(Type[] instantiation)
at NServiceBus.Testing.Test.Handler[T](T handler)
at NServiceBus.Testing.Test.Handler[T]()
ReportSaga_HandleRequestReportMessageTests.cs(34,0): at UnitTests.ReportSaga_HandleRequestReportMessageTests.HandleRequestReportMessageTests()
--TypeLoadException
at System.RuntimeTypeHandle.Instantiate(RuntimeTypeHandle handle, IntPtr* pInst, Int32 numGenericArgs, ObjectHandleOnStack type)
at System.RuntimeTypeHandle.Instantiate(Type[] inst)
at System.RuntimeType.MakeGenericType(Type[] instantiation)
0 passed, 1 failed, 0 skipped, took 1.11 seconds (NUnit 2.5.5).