-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed MassTransit/MassTransit#717 so that conditions on trigger event…
…s is supported
- Loading branch information
Showing
6 changed files
with
165 additions
and
5 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
// Copyright 2011-2016 Chris Patterson, Dru Sellers | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use | ||
// this file except in compliance with the License. You may obtain a copy of the | ||
// License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software distributed | ||
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | ||
// CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations under the License. | ||
namespace Automatonymous.Tests | ||
{ | ||
using System.Threading.Tasks; | ||
using NUnit.Framework; | ||
|
||
|
||
[TestFixture] | ||
public class When_specifying_a_condition_on_a_composite_event | ||
{ | ||
[Test] | ||
public async Task Should_skip_when_not_met() | ||
{ | ||
_machine = new TestStateMachine(); | ||
_instance = new Instance(); | ||
await _machine.RaiseEvent(_instance, _machine.Start); | ||
|
||
await _machine.RaiseEvent(_instance, _machine.First); | ||
await _machine.RaiseEvent(_instance, _machine.Second); | ||
|
||
Assert.IsFalse(_instance.Called); | ||
Assert.IsFalse(_instance.SecondFirst); | ||
} | ||
|
||
[Test] | ||
public async Task Should_call_when_met() | ||
{ | ||
_machine = new TestStateMachine(); | ||
_instance = new Instance(); | ||
await _machine.RaiseEvent(_instance, _machine.Start); | ||
|
||
await _machine.RaiseEvent(_instance, _machine.Second); | ||
await _machine.RaiseEvent(_instance, _machine.First); | ||
|
||
Assert.IsTrue(_instance.Called); | ||
Assert.IsTrue(_instance.SecondFirst); | ||
} | ||
|
||
|
||
TestStateMachine _machine; | ||
Instance _instance; | ||
|
||
|
||
class Instance | ||
{ | ||
public CompositeEventStatus CompositeStatus { get; set; } | ||
public bool Called { get; set; } | ||
public bool CalledAfterAll { get; set; } | ||
public State CurrentState { get; set; } | ||
public bool SecondFirst { get; set; } | ||
public bool First { get; set; } | ||
public bool Second { get; set; } | ||
} | ||
|
||
|
||
sealed class TestStateMachine : | ||
AutomatonymousStateMachine<Instance> | ||
{ | ||
public TestStateMachine() | ||
{ | ||
Initially( | ||
When(Start) | ||
.TransitionTo(Waiting)); | ||
|
||
During(Waiting, | ||
When(First) | ||
.Then(context => | ||
{ | ||
context.Instance.First = true; | ||
context.Instance.CalledAfterAll = false; | ||
}), | ||
When(Second) | ||
.Then(context => | ||
{ | ||
context.Instance.SecondFirst = !context.Instance.First; | ||
context.Instance.Second = true; | ||
context.Instance.CalledAfterAll = false; | ||
}) | ||
); | ||
|
||
CompositeEvent(() => Third, x => x.CompositeStatus, First, Second); | ||
|
||
During(Waiting, | ||
When(Third, context => context.Instance.SecondFirst) | ||
.Then(context => | ||
{ | ||
context.Instance.Called = true; | ||
context.Instance.CalledAfterAll = true; | ||
}) | ||
.Finalize()); | ||
} | ||
|
||
public State Waiting { get; private set; } | ||
|
||
public Event Start { get; private set; } | ||
|
||
public Event First { get; private set; } | ||
public Event Second { get; private set; } | ||
public Event Third { get; private set; } | ||
} | ||
} | ||
} |
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
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
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