Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [TestFixture]
- public class MyProcessStateMachineTests
- {
- InMemoryTestHarness _Harness;
- MyProcessStateMachine _Machine;
- StateMachineSagaTestHarness<MyProcess, MyProcessStateMachine> _Saga;
- [OneTimeSetUp]
- public void ConfigureMessages()
- {
- MessageCorrelation.UseCorrelationId<RequestMyDetails>(x => x.CorrelationId);
- MessageCorrelation.UseCorrelationId<FileAttached>(x => x.CorrelationId);
- MessageCorrelation.UseCorrelationId<PDFGenerated>(x => x.CorrelationId);
- MessageCorrelation.UseCorrelationId<CustomerAttachFile>(x => x.CorrelationId);
- MessageCorrelation.UseCorrelationId<AddCustomerNote>(x => x.CorrelationId);
- MessageCorrelation.UseCorrelationId<EmailPublished>(x => x.CorrelationId);
- }
- [SetUp]
- public void InitializeTestHarness()
- {
- _Harness = new InMemoryTestHarness();
- _Machine = new MyProcessStateMachine( /* snip */ );
- _Saga = _Harness.StateMachineSaga<MyProcess, MyProcessStateMachine>(_Machine);
- _Harness.Start().Wait();
- }
- [TearDown]
- public void StopTestHarness()
- {
- _Harness.Stop();
- }
- [Test]
- public async Task ShouldAttachToCustomer()
- {
- var sagaId = Guid.NewGuid();
- var custId = Guid.NewGuid();
- var fileAttached = BuildFileAttachedMessage(sagaId);
- await _Harness.InputQueueSendEndpoint.Send(BuildStartMessage(sagaId));
- await _Harness.InputQueueSendEndpoint.Send(BuildDetailsReceivedMessage(sagaId));
- await _Harness.InputQueueSendEndpoint.Send(BuildPdfGeneratedMessage(sagaId));
- await _Harness.InputQueueSendEndpoint.Send(fileAttached);
- // Next line is based on [the answer here][1]
- // Once the above messages are all consumed and processed,
- // the state machine should be in AwaitingEmail state
- await _Saga.Match(x =>
- x.CorrelationId == sagaId
- && x.CurrentState == _Machine.AwaitingEmail.Name,
- new TimeSpan(0, 0, 30));
- // Grab the instance and Assert stuff...
- }
- // Snip...
- }
- var inst = _Saga.Sagas.FirstOrDefault(x => x.Saga.CorrelationId == sagaId);
- var test = _Harness.Published
- .FirstOrDefault(x => x.MessageType == typeof(IAttachFile) && x.Context.CorrelationId == sagaId);
Add Comment
Please, Sign In to add comment