Created
July 26, 2012 11:09
-
-
Save marek-stoj/3181525 to your computer and use it in GitHub Desktop.
MassTransit failing test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
using System.Threading; | |
using Magnum.StateMachine; | |
using MassTransit.Saga; | |
using NUnit.Framework; | |
namespace MassTransit.Tests | |
{ | |
public class SomeSaga : SagaStateMachine<SomeSaga>, ISaga | |
{ | |
public static State Initial { get; set; } | |
public static State Working { get; set; } | |
public static State Completed { get; set; } | |
public static Event<StartSagaEvent> StartSagaEvent { get; set; } | |
public static Event<ContinueSagaEvent> ContinueSagaEvent { get; set; } | |
public static Event<EndSagaEvent> EndSagaEvent { get; set; } | |
static SomeSaga() | |
{ | |
Define( | |
() => | |
{ | |
Initially( | |
When(StartSagaEvent) | |
.Then((saga, @event) => | |
{ | |
Console.WriteLine("GOT EVENT: " + @event.GetType()); | |
saga.Bus.Publish( | |
new ContinueSagaEvent | |
{ | |
CorrelationId = @event.CorrelationId, | |
}); | |
}) | |
.TransitionTo(Working)); | |
During( | |
Working, | |
When(ContinueSagaEvent) | |
.Then((saga, @event) => | |
{ | |
Console.WriteLine("GOT EVENT: " + @event.GetType()); | |
saga.Bus.Publish( | |
new EndSagaEvent | |
{ | |
CorrelationId = @event.CorrelationId, | |
}); | |
throw new InvalidOperationException(); | |
})); | |
During( | |
Working, | |
When(EndSagaEvent) | |
.Then((saga, @event) => | |
{ | |
Console.WriteLine("GOT EVENT: " + @event.GetType()); | |
}) | |
.TransitionTo(Completed)); | |
}); | |
} | |
protected SomeSaga(Guid correlationId) | |
{ | |
CorrelationId = correlationId; | |
} | |
public IServiceBus Bus { get; set; } | |
public Guid CorrelationId { get; set; } | |
} | |
public class StartSagaEvent : CorrelatedBy<Guid> | |
{ | |
public Guid CorrelationId { get; set; } | |
} | |
public class ContinueSagaEvent : CorrelatedBy<Guid> | |
{ | |
public Guid CorrelationId { get; set; } | |
} | |
public class EndSagaEvent : CorrelatedBy<Guid> | |
{ | |
public Guid CorrelationId { get; set; } | |
} | |
[TestFixture] | |
public class SomeSagaTests | |
{ | |
[Test] | |
public void Test() | |
{ | |
ISagaRepository<SomeSaga> sagaRepository = | |
new InMemorySagaRepository<SomeSaga>(); | |
Bus.Initialize( | |
sbc => | |
{ | |
sbc.UseMsmq(); | |
sbc.SetCreateMissingQueues(true); | |
sbc.SetCreateTransactionalQueues(true); | |
sbc.ReceiveFrom(string.Format("msmq://localhost/mt_transactions_test?tx=true")); | |
sbc.Subscribe( | |
sbsc => | |
{ | |
sbsc.Saga(sagaRepository); | |
}); | |
}); | |
Guid sagaId = Guid.NewGuid(); | |
var startSagaEvent = | |
new StartSagaEvent | |
{ | |
CorrelationId = sagaId, | |
}; | |
Bus.Instance.Publish(startSagaEvent); | |
Thread.Sleep(10000); | |
SomeSaga saga = | |
sagaRepository.Where(new SagaFilter<SomeSaga>(s => s.CorrelationId == sagaId)) | |
.Single(); | |
Console.WriteLine(saga.CurrentState); | |
Assert.AreEqual(SomeSaga.Working, saga.CurrentState); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment