public void Process_WithInvalidTrigger_ReturnsFailure() { // Arrange var stateMachine = OrderFsmFactory.Create(); // Act // Assert Assert.Throws <InvalidOperationException>(() => stateMachine.Process(Trigger.Event(typeof(OrderExpired)))); }
public void Process_WithValidTrigger_ReturnsExpectedState() { // Arrange var stateMachine = OrderFsmFactory.Create(); // Act stateMachine.Process(Trigger.Event(typeof(OrderSubmitted))); // Assert Assert.Equal(OrderState.Submitted, stateMachine.State); }
public void State_WithNewStateMachine_EqualsStartingState() { // Arrange var stateMachine = OrderFsmFactory.Create(); // Act var result = stateMachine.State; // Assert Assert.Equal(OrderState.Initialized, result); }
public void Process_MultipleValidTriggersThenInvalidTrigger_ReturnsFailure() { // Arrange var stateMachine = OrderFsmFactory.Create(); // Act stateMachine.Process(Trigger.Event(typeof(OrderSubmitted))); stateMachine.Process(Trigger.Event(typeof(OrderAccepted))); stateMachine.Process(Trigger.Event(typeof(OrderWorking))); stateMachine.Process(Trigger.Event(typeof(OrderPartiallyFilled))); // Assert Assert.Throws <InvalidOperationException>(() => stateMachine.Process(Trigger.Event(typeof(OrderRejected)))); }
public void Process_ThroughFullCycle_ReturnsExpectedState() { // Arrange var stateMachine = OrderFsmFactory.Create(); // Act stateMachine.Process(Trigger.Event(typeof(OrderSubmitted))); stateMachine.Process(Trigger.Event(typeof(OrderAccepted))); stateMachine.Process(Trigger.Event(typeof(OrderWorking))); stateMachine.Process(Trigger.Event(typeof(OrderPartiallyFilled))); stateMachine.Process(Trigger.Event(typeof(OrderFilled))); // Assert Assert.Equal(OrderState.Filled, stateMachine.State); }
/// <summary> /// Initializes a new instance of the <see cref="Order"/> class. /// </summary> /// <param name="initial">The initial order event.</param> public Order(OrderInitialized initial) : base(initial.OrderId, initial) { this.orderFiniteStateMachine = OrderFsmFactory.Create(); this.executionIds = new UniqueList <ExecutionId>(); this.Symbol = initial.Symbol; this.OrderSide = initial.OrderSide; this.OrderType = initial.OrderType; this.Quantity = initial.Quantity; this.FilledQuantity = Quantity.Zero(); this.Price = initial.Price; this.TimeInForce = initial.TimeInForce; this.ExpireTime = this.ValidateExpireTime(initial.ExpireTime); this.IsBuy = this.OrderSide == OrderSide.Buy; this.IsSell = this.OrderSide == OrderSide.Sell; this.IsWorking = false; this.IsCompleted = false; this.CheckInitialization(); }