public TableItem(SniperSnapshot snapshot) { ItemId = snapshot.ItemId; LastPrice = snapshot.LastPrice; LastBid = snapshot.LastBid; State = StatusText[(int)snapshot.State]; }
private void AssertRowMatchesSnapshot(int row, SniperSnapshot ss) { Assert.AreEqual(ss.ItemId, _snipersDataSet.Rows[row][(int)SnipersDataSet.Column.ITEM_IDENTIFIER]); Assert.AreEqual(ss.LastPrice.ToString(), _snipersDataSet.Rows[row][(int)SnipersDataSet.Column.LAST_PRICE]); Assert.AreEqual(ss.LastBid.ToString(), _snipersDataSet.Rows[row][(int)SnipersDataSet.Column.LAST_BID]); Assert.AreEqual(ss.State.ToString(), _snipersDataSet.Rows[row][(int)SnipersDataSet.Column.SNIPER_STATUS]); }
private void assertRowMatchesSnapShot(int rowIndex, SniperSnapshot snapShot) { assertColumnEquals(Column.ITEM_IDENTIFIER, rowIndex, snapShot.ItemId); assertColumnEquals(Column.LAST_PRICE, rowIndex, snapShot.LastPrice.ToString()); assertColumnEquals(Column.LAST_BID, rowIndex, snapShot.LastBid.ToString()); assertColumnEquals(Column.SNIPER_STATE, rowIndex, Status.GetStateText(snapShot.State)); }
public void HoldsSnipersInAdditionOrder() { model.AddSniperSnapShot(SniperSnapshot.Joining("item 0")); model.AddSniperSnapShot(SniperSnapshot.Joining("item 1")); StringAssert.AreEqualIgnoringCase("item 0", cellValue(0, Column.ITEM_IDENTIFIER).ToString()); StringAssert.AreEqualIgnoringCase("item 1", cellValue(1, Column.ITEM_IDENTIFIER).ToString()); }
public void HoldsSnipersInAdditionOrder() { _snipersDataSet.AddSniper(SniperSnapshot.Joining("item 0")); _snipersDataSet.AddSniper(SniperSnapshot.Joining("item 1")); Assert.AreEqual("item 0", _snipersDataSet.Rows[0][(int)SnipersDataSet.Column.ITEM_IDENTIFIER]); Assert.AreEqual("item 1", _snipersDataSet.Rows[1][(int)SnipersDataSet.Column.ITEM_IDENTIFIER]); }
public virtual void AddSniper(SniperSnapshot sniperSnapshot) { Rows.Add(new object[] { sniperSnapshot.ItemId, sniperSnapshot.LastBid, sniperSnapshot.LastPrice, sniperSnapshot.State }); }
public AuctionSniperService(string itemId, Auction auction, ISniperListener listener) { _itemId = itemId; _auction = auction; _listener = listener; _snapshot = SniperSnapshot.Joining(itemId); _listener.AddSniper(_snapshot); }
public void SetsSniperValuesInColumns() { SniperSnapshot joining = SniperSnapshot.Joining(ITEM_ID); SniperSnapshot bidding = joining.Bidding(555, 666); _snipersDataSet.AddSniper(joining); _snipersDataSet.SniperStateChanged(bidding); AssertRowMatchesSnapshot(0, bidding); }
public void NotifiesListenersWhenAddingASniper() { SniperSnapshot joining = SniperSnapshot.Joining(ITEM_ID); Assert.AreEqual(0, _snipersDataSet.Rows.Count); _snipersDataSet.AddSniper(joining); Assert.AreEqual(1, _snipersDataSet.Rows.Count); AssertRowMatchesSnapshot(0, joining); }
public void SetSniperValuesInColumns() { SniperSnapshot joining = SniperSnapshot.Joining("item id"); SniperSnapshot bidding = joining.Bidding(555, 666); model.AddSniperSnapShot(joining); model.SniperStateChanged(bidding); assertRowMatchesSnapShot(0, bidding); }
public void NotifiesListenersWhenAddingASniper() { SniperSnapshot joining = SniperSnapshot.Joining("item123"); Assert.AreEqual(0, model.Rows.Count); model.AddSniperSnapShot(joining); Assert.AreEqual(1, model.Rows.Count); assertRowMatchesSnapShot(0, joining); }
public void BidsHigherAndReportsBiddingWhenNewPriceArrives() { int price = 1001; int increment = 25; int bid = price + increment; SniperSnapshot state = new SniperSnapshot(ITEM_ID, price, bid, SniperState.Bidding); sniper.CurrentPrice(price, increment, PriceSource.FromOtherBidder); A.CallTo(() => sniperListener.SniperStateChanged(A<SniperSnapshot>.That.Matches(ss => ss.Equals(state)))) .MustHaveHappened(Repeated.AtLeast.Once); A.CallTo(() => auction.Bid(price + increment)).MustHaveHappened(Repeated.Exactly.Once); }
public void BidsHigherAndReportsBiddingWhenNewPriceArrives() { int price = 1001; int increment = 25; int bid = price + increment; SniperSnapshot state = new SniperSnapshot(ITEM_ID, price, bid, SniperState.Bidding); sniper.CurrentPrice(price, increment, PriceSource.FromOtherBidder); A.CallTo(() => sniperListener.SniperStateChanged(A <SniperSnapshot> .That.Matches(ss => ss.Equals(state)))) .MustHaveHappened(Repeated.AtLeast.Once); A.CallTo(() => auction.Bid(price + increment)).MustHaveHappened(Repeated.Exactly.Once); }
public void CurrentPrice(int price, int increment, PriceSource priceSource) { switch(priceSource) { case PriceSource.FromSniper: _snapshot = _snapshot.Winning(price); break; case PriceSource.FromOtherBidder: int bid = price + increment; _auction.Bid(bid); _snapshot = _snapshot.Bidding(price, bid); break; } NotifyChange(); }
public virtual void SniperStateChanged(SniperSnapshot sniperSnapshot) { foreach(DataRow row in Rows) { if(row[0].ToString() == sniperSnapshot.ItemId) { row[(int)Column.LAST_BID] = sniperSnapshot.LastBid; row[(int)Column.LAST_PRICE] = sniperSnapshot.LastPrice; row[(int)Column.SNIPER_STATUS] = sniperSnapshot.State.ToString(); return; } } throw new Exception("Unknown auction id"); }
public void CurrentPrice(int price, int increment, PriceSource priceSource) { switch (priceSource) { case PriceSource.FromSniper: _snapshot = _snapshot.Winning(price); break; case PriceSource.FromOtherBidder: int bid = price + increment; _auction.Bid(bid); _snapshot = _snapshot.Bidding(price, bid); break; } NotifyChange(); }
public void UpdatesCorrectRowForSniper() { SniperSnapshot joining = SniperSnapshot.Joining("item 0"); SniperSnapshot joining2 = SniperSnapshot.Joining("item 1"); SniperSnapshot bidding = joining.Bidding(555, 666); SniperSnapshot bidding2 = joining2.Bidding(666, 777); _snipersDataSet.AddSniper(joining); _snipersDataSet.AddSniper(joining2); _snipersDataSet.SniperStateChanged(bidding); _snipersDataSet.SniperStateChanged(bidding2); AssertRowMatchesSnapshot(0, bidding); AssertRowMatchesSnapshot(1, bidding2); }
public void ThrowsDefectIfNoExistingSniperForAnUpdate() { SniperSnapshot bidding = new SniperSnapshot("item 0", 0, 0, SniperState.Bidding); _snipersDataSet.SniperStateChanged(bidding); }
public void SniperStateChanged(SniperSnapshot sniperSnapshot) { _dispatcher.Invoke(() => _model.SniperStatusChanged(sniperSnapshot)); }
private int GetRowForSniper(SniperSnapshot newSnapshot) { var item = Items.Single(i => i.ItemId == newSnapshot.ItemId); return(Items.IndexOf(item)); }
public Sniper(IAuction auction, Item item) { _auction = auction; _item = item; _snapshot = SniperSnapshot.Joining(item.Identifier); }
public void AuctionClosed() { _snapshot = _snapshot.Closed(); NotifyChanged(); }
public void AuctionClosed() { _snapshot = _snapshot.Closed(); NotifyChange(); }
private void AddSniperSnapshot(SniperSnapshot state) { Add(new TableItem(state)); }
public void SniperStatusChanged(SniperSnapshot newSnapshot) { int row = GetRowForSniper(newSnapshot); SetItem(row, new TableItem(newSnapshot)); }