Guest User

Untitled

a guest
Jun 22nd, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. [TestFixture]
  2. public class MyProcessStateMachineTests
  3. {
  4. InMemoryTestHarness _Harness;
  5. MyProcessStateMachine _Machine;
  6. StateMachineSagaTestHarness<MyProcess, MyProcessStateMachine> _Saga;
  7.  
  8. [OneTimeSetUp]
  9. public void ConfigureMessages()
  10. {
  11. MessageCorrelation.UseCorrelationId<RequestMyDetails>(x => x.CorrelationId);
  12. MessageCorrelation.UseCorrelationId<FileAttached>(x => x.CorrelationId);
  13. MessageCorrelation.UseCorrelationId<PDFGenerated>(x => x.CorrelationId);
  14. MessageCorrelation.UseCorrelationId<CustomerAttachFile>(x => x.CorrelationId);
  15. MessageCorrelation.UseCorrelationId<AddCustomerNote>(x => x.CorrelationId);
  16. MessageCorrelation.UseCorrelationId<EmailPublished>(x => x.CorrelationId);
  17. }
  18.  
  19.  
  20. [SetUp]
  21. public void InitializeTestHarness()
  22. {
  23. _Harness = new InMemoryTestHarness();
  24. _Machine = new MyProcessStateMachine( /* snip */ );
  25. _Saga = _Harness.StateMachineSaga<MyProcess, MyProcessStateMachine>(_Machine);
  26.  
  27. _Harness.Start().Wait();
  28. }
  29.  
  30. [TearDown]
  31. public void StopTestHarness()
  32. {
  33. _Harness.Stop();
  34. }
  35.  
  36.  
  37. [Test]
  38. public async Task ShouldAttachToCustomer()
  39. {
  40. var sagaId = Guid.NewGuid();
  41. var custId = Guid.NewGuid();
  42. var fileAttached = BuildFileAttachedMessage(sagaId);
  43.  
  44. await _Harness.InputQueueSendEndpoint.Send(BuildStartMessage(sagaId));
  45. await _Harness.InputQueueSendEndpoint.Send(BuildDetailsReceivedMessage(sagaId));
  46. await _Harness.InputQueueSendEndpoint.Send(BuildPdfGeneratedMessage(sagaId));
  47. await _Harness.InputQueueSendEndpoint.Send(fileAttached);
  48.  
  49. // Next line is based on [the answer here][1]
  50. // Once the above messages are all consumed and processed,
  51. // the state machine should be in AwaitingEmail state
  52. await _Saga.Match(x =>
  53. x.CorrelationId == sagaId
  54. && x.CurrentState == _Machine.AwaitingEmail.Name,
  55. new TimeSpan(0, 0, 30));
  56.  
  57. // Grab the instance and Assert stuff...
  58. }
  59.  
  60. // Snip...
  61. }
  62.  
  63. var inst = _Saga.Sagas.FirstOrDefault(x => x.Saga.CorrelationId == sagaId);
  64.  
  65. var test = _Harness.Published
  66. .FirstOrDefault(x => x.MessageType == typeof(IAttachFile) && x.Context.CorrelationId == sagaId);
Add Comment
Please, Sign In to add comment