public Member Save(Member member) { var foundMember = this.repository.GetMembers().FirstOrDefault(m => m.UniqueId == member.UniqueId); if (foundMember == null) { throw new ArgumentException("Cannot save an unknown member"); } foundMember.DisplayName = member.DisplayName; foundMember.EMail = member.DisplayName; this.repository.SaveChanges(); return foundMember; }
public void Auction_BidIsBelowStartPrice_HasNoImpact() { var repo = new InMemoryMainRepository(); var auctioneer = new Auctioneer(repo); var auction = CreateAndStoreAuction(repo, DateTime.UtcNow, DateTime.UtcNow.AddHours(1)); auctioneer.DoAllWork(); var bidder = new Member() { DisplayName = "Bidder1", UniqueId = Guid.NewGuid().ToString() }; repo.Add(bidder); repo.Add(new Bid() { ReceivedOnUtc = DateTime.UtcNow, Auction = auction, Amount = auction.StartPrice - 10, Bidder = bidder }); auctioneer.DoAllWork(); Assert.AreEqual(1, auction.Bids.Count); Assert.IsNull(auction.ActiveBid); }
public Member GetCurrentMember() { var uniqueId = string.Format(CultureInfo.CurrentCulture, "{0}@{1}.local", Environment.UserName, Environment.UserDomainName); var member = this.repository.GetMembers().FirstOrDefault(m => m.UniqueId == uniqueId); if (member == null) { member = new Member { UniqueId = uniqueId, DisplayName = Environment.UserName, EMail = string.Format(CultureInfo.CurrentCulture, "{0}@{1}.local", Environment.UserName, Environment.UserDomainName) }; this.repository.Add(member); this.repository.SaveChanges(); } return member; }
public Member Add(string displayName, string mail) { var uniqueId = mail; if (this.repository.GetMembers().All(m => m.UniqueId != uniqueId)) { var member = new Member() { UniqueId = uniqueId, DisplayName = displayName, EMail = mail }; this.repository.Add(member); this.repository.SaveChanges(); return member; } return null; }
private static Auction CreateAndStoreAuction(InMemoryMainRepository repo, DateTime startDateTimeUtc, DateTime endDateTimeUtc) { var seller = new Member() { DisplayName = "Seller", UniqueId = Guid.NewGuid().ToString() }; var auction = new Auction() { Title = "TestAuction", Seller = seller, StartPrice = 50, StartDateTimeUtc = startDateTimeUtc, EndDateTimeUtc = endDateTimeUtc }; repo.Add(seller); repo.Add(auction); Assert.AreEqual(1, repo.GetAuctions().Count()); Assert.AreEqual(1, repo.GetMembers().Count()); return auction; }
private static void AddInitialBidToAuction(InMemoryMainRepository repo, Auction auction) { var bidder = new Member() { DisplayName = "Bidder1", UniqueId = Guid.NewGuid().ToString() }; repo.Add(bidder); repo.Add(new Bid() { ReceivedOnUtc = DateTime.UtcNow, Auction = auction, Amount = auction.StartPrice + 10, Bidder = bidder }); }
public void Bid_WhenDeclined_EventIsRaised() { var repo = new InMemoryMainRepository(); var auctioneer = new Auctioneer(repo); var auction = CreateAndStoreAuction(repo, DateTime.UtcNow.AddHours(-1), DateTime.UtcNow.AddHours(1)); AddInitialBidToAuction(repo, auction); auctioneer.DoAllWork(); ProcessedBidEventArgs raisedArgs = null; auctioneer.BidDeclined += (sender, args) => raisedArgs = args; var bidder2 = new Member() { DisplayName = "Bidder2", UniqueId = Guid.NewGuid().ToString() }; repo.Add(bidder2); repo.Add(new Bid() { ReceivedOnUtc = DateTime.UtcNow, Bidder = bidder2, Amount = 51, Auction = auction }); auctioneer.DoAllWork(); Assert.NotNull(raisedArgs); Assert.NotNull(raisedArgs.Auction); Assert.NotNull(raisedArgs.Bid); }
public void Auction_HasOneBidAndEnds_TheBidderShouldBeTheWinner() { var repo = new InMemoryMainRepository(); var auctioneer = new Auctioneer(repo); var auction = CreateAndStoreAuction(repo, DateTime.UtcNow.AddHours(-1), DateTime.UtcNow.AddHours(1)); auctioneer.DoAllWork(); var bidder2 = new Member() { DisplayName = "Bidder2", UniqueId = Guid.NewGuid().ToString() }; repo.Add(bidder2); repo.Add(new Bid() { ReceivedOnUtc = DateTime.UtcNow, Bidder = bidder2, Amount = 70, Auction = auction }); // Turn back the time auction.EndDateTimeUtc = DateTime.UtcNow; auctioneer.DoAllWork(); Assert.AreEqual(auction.Winner, bidder2); }
public void Auction_HasNewerButLowerBid_HasNoImpact() { var repo = new InMemoryMainRepository(); var auctioneer = new Auctioneer(repo); var auction = CreateAndStoreAuction(repo, DateTime.UtcNow, DateTime.UtcNow.AddHours(1)); AddInitialBidToAuction(repo, auction); auctioneer.DoAllWork(); var bidder2 = new Member() { DisplayName = "Bidder2", UniqueId = Guid.NewGuid().ToString() }; repo.Add(bidder2); repo.Add(new Bid() { ReceivedOnUtc = DateTime.UtcNow, Bidder = bidder2, Amount = 51, Auction = auction }); auctioneer.DoAllWork(); Assert.AreEqual(2, auction.Bids.Count); Assert.AreEqual(60, auction.CurrentPrice); }
public void Auction_GetsOlderButHigherBid_FailsWithException() { var repo = new InMemoryMainRepository(); var auctioneer = new Auctioneer(repo); var auction = CreateAndStoreAuction(repo, DateTime.UtcNow.AddHours(-1), DateTime.UtcNow.AddHours(1)); AddInitialBidToAuction(repo, auction); auctioneer.DoAllWork(); var bidder2 = new Member() { DisplayName = "Bidder2", UniqueId = Guid.NewGuid().ToString() }; repo.Add(bidder2); repo.Add(new Bid() { ReceivedOnUtc = DateTime.UtcNow.AddMinutes(-10), Bidder = bidder2, Amount = 70, Auction = auction }); auctioneer.DoAllWork(); }
public Member Add(Member member) { this.context.Members.Add(member); return member; }