public void Deserialise() { var wrapped = new WrappedObjectState(Market); using (var session = Database.OpenSession()) { session.Store(wrapped, string.Concat(wrapped.Value.GetType().Name, "/market")); session.SaveChanges(); } using (var session = Database.OpenSession()) { var buyOrder = new BuyOrder {Id = Universe.BuyOrder.ObjectId}; var sellOrder = new SellOrder { Id = Universe.SellOrder.ObjectId }; var resolver = new IdResolutionContext(new IObject[] { buyOrder, sellOrder, new ItemInfo(ItemCode.Veldnium), new TradingStation { Id = Universe.TradingStation.ObjectId }, new Corporation { Id = Universe.MSCorp.ObjectId }, new Corporation { Id = Universe.AppleCorp.ObjectId } }); var state = session.Load<WrappedObjectState>(wrapped.Id).Value; Assert.That(state, Is.Not.Null); Assert.That(state.Settlements, Is.Not.Empty); var market = MarketPlace.Builder.Build(Market, null).Materialise(resolver); Assert.That(market, Is.InstanceOf<MarketPlace>()); Assert.That(market.BuyOrders, Is.Not.Empty); Assert.That(market.SellOrders, Is.Not.Empty); Assert.That(market.Settlements, Is.Not.Empty); } }
public void GetMarketPlace() { var a = new BuyOrder(); a.MarketPlace.ShouldBe(null); a.Location = _tradingStation; a.MarketPlace.ShouldBe(_sc.MarketPlace); }
public void Save() { var buyOrder = new BuyOrder { Id = Universe.BuyOrder.ObjectId }; var sellOrder = new SellOrder { Id = Universe.SellOrder.ObjectId }; var resolver = new IdResolutionContext(new IObject[] { buyOrder, sellOrder, new ItemInfo(ItemCode.Veldnium), new TradingStation { Id = Universe.TradingStation.ObjectId }, new Corporation { Id = Universe.MSCorp.ObjectId }, new Corporation { Id = Universe.AppleCorp.ObjectId } }); var market = MarketPlace.Builder.Build(Market, new StarCluster()).Materialise(resolver); Assert.That(market, Is.InstanceOf<MarketPlace>()); var state = market.Save(); var json = Database.Conventions.CreateSerializer().Serialize(state); Console.WriteLine(json); }
public void ChooseCheapestSellOrder() { var expensiveItem = new Item(new ItemInfo(ItemCode.Veldnium)) { Owner = new Corporation(), Quantity = 10, Location = _sc }; var expensive = new SellOrder { Item = expensiveItem, Location = _tradingStation, PricePerUnit = 100 }; var cheapItem = new Item(new ItemInfo(ItemCode.Veldnium)) { Owner = new Corporation(), Quantity = 10, Location = _sc }; var cheapest = new SellOrder { Item = cheapItem, Location = _tradingStation, PricePerUnit = 80 }; _sc.MarketPlace.Add(expensive); _sc.MarketPlace.Add(cheapest); _sc.MarketPlace.AuctionLength = 10; var item = new Item(new ItemInfo(ItemCode.Veldnium)) { Owner = new Corporation(), Quantity = 10, Location = _sc }; var a = new BuyOrder { Item = item, Location = _tradingStation, PricePerUnit = 120 }; var settlement = a.List(_sc.MarketPlace); settlement.Success.ShouldBe(true); settlement.Item.Quantity.ShouldBe(10u); settlement.Sum.ShouldBe(800); _sc.MarketPlace.Auctions.ShouldNotContain(a); _sc.MarketPlace.Auctions.ShouldNotContain(cheapest); }
public void ListBuyOrderWithOpposingSellOrder() { var selling = new Item(new ItemInfo(ItemCode.Veldnium)) { Owner = new Corporation(), Quantity = 10, Location = _sc }; var sellOrder = new SellOrder { Item = selling, Location = _tradingStation, PricePerUnit = 100 }; _sc.MarketPlace.Add(sellOrder); _sc.MarketPlace.AuctionLength = 10; var item = new Item(new ItemInfo(ItemCode.Veldnium)) { Owner = new Corporation(), Quantity = 10, Location = _sc }; var a = new BuyOrder { Item = item, Location = _tradingStation, PricePerUnit = 120 }; var settlement = a.List(_sc.MarketPlace); settlement.Success.ShouldBe(true); settlement.Sum.ShouldBe(1000); settlement.Item.Quantity.ShouldBe(10u); _sc.MarketPlace.Auctions.ShouldNotContain(a); _sc.MarketPlace.Auctions.ShouldNotContain(sellOrder); }
public void ListBuyOrder() { _sc.MarketPlace.AuctionLength = 10; var item = new Item(new ItemInfo(ItemCode.Veldnium)) { Owner = new Corporation(), Quantity = 10, Location = _sc }; var a = new BuyOrder { Item = item, PricePerUnit = 120 }; a.List(_sc.MarketPlace); _sc.MarketPlace.Auctions.ShouldContain(a); a.Expires.ShouldBe(_sc.MarketPlace.AuctionLength); }
public void ListAuctionWithNoMarketPlace() { var a = new BuyOrder(); Should.Throw<ArgumentNullException>(() => a.List(null)); }
public void AuctionQuantity() { var item = new Item(new ItemInfo(ItemCode.Veldnium)) {Owner = new Corporation(), Quantity = 10}; var a = new BuyOrder { Item = item }; a.Quantity.ShouldBe(item.Quantity); }
public void OwnerIsSet() { var item = new Item(new ItemInfo(ItemCode.Veldnium)) {Owner = new Corporation(), Quantity = 10}; var a = new BuyOrder {Item = item}; a.Owner.ShouldBe(item.Owner); }
public void ListSellOrderWithIncompatibleBlockSizes() { var selling = new Item(new ItemInfo(ItemCode.Veldnium)) { Owner = new Corporation(), Quantity = 150, Location = _sc }; var sellOrder = new SellOrder { Item = selling, Location = _tradingStation, PricePerUnit = 100, BlockSize = 150 }; _sc.MarketPlace.Add(sellOrder); _sc.MarketPlace.AuctionLength = 10; var item = new Item(new ItemInfo(ItemCode.Veldnium)) { Owner = new Corporation(), Quantity = 180, Location = _sc }; var a = new BuyOrder { Item = item, Location = _tradingStation, PricePerUnit = 120, BlockSize = 100 }; var settlement = a.List(_sc.MarketPlace); settlement.Success.ShouldBe(false); settlement.Sum.ShouldBe(0); }
public void ListBuyOrderWithPartialBuy() { var selling = new Item(new ItemInfo(ItemCode.Veldnium)) { Owner = new Corporation(), Quantity = 150, Location = _sc }; var sellOrder = new SellOrder { Item = selling, Location = _tradingStation, PricePerUnit = 100, BlockSize = 10 }; _sc.MarketPlace.Add(sellOrder); _sc.MarketPlace.AuctionLength = 10; var item = new Item(new ItemInfo(ItemCode.Veldnium)) { Owner = new Corporation(), Quantity = 200, Location = _sc }; var a = new BuyOrder { Item = item, Location = _tradingStation, PricePerUnit = 120, BlockSize = 100 }; var settlement = a.List(_sc.MarketPlace); settlement.Success.ShouldBe(true); settlement.Item.Quantity.ShouldBe(100u); settlement.Sum.ShouldBe(100 * 100); settlement.Timer = _sc.MarketPlace.SettlementDelay; _sc.MarketPlace.Auctions.ShouldContain(sellOrder); _sc.MarketPlace.Auctions.ShouldContain(a); _sc.MarketPlace.Settlements.ShouldContain(settlement); }