public void Fill_ThrowsException_IfOpenQuantityIsLessThanFillQuantity() { QuantityTrackingPriceLevel quantityTrackingPriceLevel = new QuantityTrackingPriceLevel(100); Order order1 = new Order() { IsBuy = true, OrderId = 1, Price = 100, Sequnce = 1, OpenQuantity = 1000 }; quantityTrackingPriceLevel.AddOrder(order1); Assert.Equal(1000, quantityTrackingPriceLevel.Quantity); Assert.Equal(1, quantityTrackingPriceLevel.OrderCount); Order order2 = new Order() { IsBuy = true, OrderId = 2, Price = 100, Sequnce = 2, OpenQuantity = 1000 }; quantityTrackingPriceLevel.AddOrder(order2); Assert.Equal(2000, quantityTrackingPriceLevel.Quantity); Assert.Equal(2, quantityTrackingPriceLevel.OrderCount); Exception ex = Assert.Throws <Exception>(() => quantityTrackingPriceLevel.Fill(order1, 1100)); Assert.Equal("Order quantity is less then requested fill quanity", ex.Message); Assert.Equal(2000, quantityTrackingPriceLevel.Quantity); Assert.Equal(2, quantityTrackingPriceLevel.OrderCount); }
public void Fill_RemovesOrder_IfOpenQuantityIs0() { QuantityTrackingPriceLevel quantityTrackingPriceLevel = new QuantityTrackingPriceLevel(100); Order order1 = new Order() { IsBuy = true, OrderId = 1, Price = 100, OpenQuantity = 1000, Sequnce = 1 }; quantityTrackingPriceLevel.AddOrder(order1); Assert.Equal(1000, quantityTrackingPriceLevel.Quantity); Assert.Equal(1, quantityTrackingPriceLevel.OrderCount); Order order2 = new Order() { IsBuy = true, OrderId = 2, Price = 100, OpenQuantity = 1000, Sequnce = 2 }; quantityTrackingPriceLevel.AddOrder(order2); Assert.Equal(2000, quantityTrackingPriceLevel.Quantity); Assert.Equal(2, quantityTrackingPriceLevel.OrderCount); quantityTrackingPriceLevel.Fill(order1, 1000); Assert.Equal(1000, quantityTrackingPriceLevel.Quantity); Assert.Equal(1, quantityTrackingPriceLevel.OrderCount); Assert.Contains(order2, quantityTrackingPriceLevel); }
public void Fill_DoesNotRemoveOrder_IfOpenQuantityIsNot0() { QuantityTrackingPriceLevel quantityTrackingPriceLevel = new QuantityTrackingPriceLevel(100); Order order1 = new Order() { IsBuy = true, OrderId = 1, OpenQuantity = 1000, Price = 100, Sequnce = 1 }; quantityTrackingPriceLevel.AddOrder(order1); Assert.Equal(1000, quantityTrackingPriceLevel.Quantity); Assert.Equal(1, quantityTrackingPriceLevel.OrderCount); Order order2 = new Order() { IsBuy = true, OrderId = 2, OpenQuantity = 1000, Price = 100, Sequnce = 2 }; quantityTrackingPriceLevel.AddOrder(order2); Assert.Equal(2000, quantityTrackingPriceLevel.Quantity); Assert.Equal(2, quantityTrackingPriceLevel.OrderCount); quantityTrackingPriceLevel.Fill(order1, 900); Assert.Equal(1100, quantityTrackingPriceLevel.Quantity); Assert.Equal(2, quantityTrackingPriceLevel.OrderCount); Assert.Contains(order1, quantityTrackingPriceLevel); Assert.Contains(order2, quantityTrackingPriceLevel); Assert.True(100 == order1.OpenQuantity, "Quantity should be 100"); }