public IEnumerable <IAuction> WonAuctions() { if (!UserSite.IsUserInSite(this.Username)) { throw new InvalidOperationException(); } IAuction currAuction = null; IEnumerable <IAuction> wonAuctions; IEnumerable <IAuction> allAuctions = UserSite.GetAuctions(false); IEnumerator <IAuction> auctionIterator = allAuctions.GetEnumerator(); List <IAuction> l = new List <IAuction>(); while (auctionIterator.MoveNext()) { currAuction = auctionIterator.Current; //if (currAuction.CurrentWinner() as User == this && currAuction.EndsOn >= UserSite.Now) if (currAuction != null) { if ((currAuction.CurrentWinner() as User).Equals(this) && currAuction.EndsOn >= UserSite.Now) { l.Add(currAuction); } } } auctionIterator.Dispose(); wonAuctions = l; return(wonAuctions); }
private void _auctionCall(IAuction auction) { AuctionStarter auctionStarter = new AuctionStarter(auction, Agents); auctionStarter.startAuction(); if (auction.AgentsName.Count != 0) { AuctionManager auctionManager = new AuctionManager(auction); Console.WriteLine($"\nThe auction on {auction.Product.Name} starts now!!! The min price is : {auction.BestPrice}"); auctionManager.Manage(); _restAgentsFlag(); try { Auctions.RemoveAt(Auctions.IndexOf(auction)); } catch (ArgumentOutOfRangeException ex) { Console.WriteLine($"Can't delete {auction.Product.Name} "); } } else { try { Auctions.RemoveAt(Auctions.IndexOf(auction)); } catch (ArgumentOutOfRangeException ex) { Console.WriteLine($"Can't delete {auction.Product.Name} "); } } }
public AuctionInfo(IAuction auction, bool partial) { this.lowPrice = auction.LowPrice; this.auctionID = auction.Id; IItem i = auction.Item; if (i != null) this.itemName = i.ItemName; if (partial) { //not used this.bids = new ArrayList(); this.itemGraphicFilename="not needed"; this.sellerName = "not needed"; this.itemID = "not needed"; this.description = "not needed"; } else { this.bids = BidInfo.Bids(auction.Bids); IUser u = auction.Seller; if (u!=null) { sellerName = u.Id; } if (i!=null) { description = i.Description; itemID = i.Id; itemGraphicFilename = i.GraphicFilename; } } }
public string Place2Bids(String auctionId1, String auctionId2, String bidId1, String bidId2, String userId, System.Double amount1, System.Double amount2, System.Double maxAmount1, System.Double maxAmount2) { string sql = ""; try { IUser user = persistentAuctions.GetUser(userId); IAuction auction1 = persistentAuctions.GetAuction(auctionId1); IBid newBid1 = persistentAuctions.CreateBid(bidId1, auction1, user, amount1, maxAmount1); IAuction auction2 = persistentAuctions.GetAuction(auctionId2); IBid newBid2 = persistentAuctions.CreateBid(bidId2, auction2, user, amount2, maxAmount2); // The next operation is for Object-Relational mapping software that needs to be explicitly cleaned up. // Those that do not simply ignore this operation. persistentAuctions.Close(); sql = persistentAuctions.Sql; } catch (Exception e) { // The next operation is for Object-Relational mapping software that needs to be explicitly cleaned up. // Those that do not simply ignore this operation. if (persistentAuctions != null) { persistentAuctions.Close(); } throw new AuctionServiceException(e); } return(sql); }
public AuctionInfo ListPartialAuction(String auctionId) { try { IAuction auction = persistentAuctions.GetPartialAuction(auctionId); AuctionInfo ai = persistentAuctions.CreateAuctionInfo(auction, true); // The next operation is for Object-Relational mapping software that needs to be explicitly cleaned up. // Those that do not simply ignore this operation. persistentAuctions.Close(); ai.Sql = persistentAuctions.Sql; return(ai); } catch (Exception e) { // The next operation is for Object-Relational mapping software that needs to be explicitly cleaned up. // Those that do not simply ignore this operation. if (persistentAuctions != null) { persistentAuctions.Close(); } throw new AuctionServiceException(e); } }
public void TestSetup() { _mocks = new MockRepository(); _mockAuction = _mocks.StrictMock <IAuction>(); _mockSniperListener = _mocks.StrictMock <ISniperListener>(); _sniper = new Domain.AuctionSniper(_mockAuction, _mockSniperListener); }
public void Initialize() { Site = CreateAndLoadEmptySite(Timezone, SiteName, 360, 7, out AlarmClock); Seller = CreateAndLogUser(SellerName, out SellerSession, Site); TheAuction = SellerSession.CreateAuction("lidl socks", AlarmClock.Object.Now.AddDays(3), 2); Assert.That(Seller, Is.Not.Null, "Set up should be successful"); }
public AuctionInfo(IAuction auction, bool partial) { this.lowPrice = auction.LowPrice; this.auctionID = auction.Id; IItem i = auction.Item; if (i != null) { this.itemName = i.ItemName; } if (partial) { //not used this.bids = new ArrayList(); this.itemGraphicFilename = "not needed"; this.sellerName = "not needed"; this.itemID = "not needed"; this.description = "not needed"; } else { this.bids = BidInfo.Bids(auction.Bids); IUser u = auction.Seller; if (u != null) { sellerName = u.Id; } if (i != null) { description = i.Description; itemID = i.Id; itemGraphicFilename = i.GraphicFilename; } } }
public override IAuction GetAuction(string auctionId) { IContext context = GetContext(); IAuction auction = (IAuction)context.GetObjectById(auctionId, typeof(Auction), true); return(auction); }
public void NotifiesAuctionLostWhenAuctionCloses() { sniperListener.Expects.One.Method(x => x.AuctionLost()); IAuction nullAuction = null; var auctionSniper = new Domain.AuctionSniper(sniperListener.MockObject, nullAuction); auctionSniper.AuctionClosed(); }
public void Initialize() { Site = CreateAndLoadSite(-5, "site for user tests", 360, 7, out AlarmClock); User = CreateAndLogUser(UserName, out UserSession, Site); Seller = CreateAndLogUser("seller", out SellerSession, Site); EndsOn = AlarmClock.Object.Now.AddDays(7); TheAuction = SellerSession.CreateAuction(Description, EndsOn, StartingPrice); }
public AuctionController(DBModel context, UserManager <UserAccount> userManager, SignInManager <UserAccount> signInManager, IEmailSender emailSender, IProducts assets, IAuction auction) { _context = context; _userManager = userManager; _signInManager = signInManager; _emailSender = emailSender; _assets = assets; _auction = auction; }
public AuctionsTests() { _sut = AuctionFactory.Create(); _completeListOfProvices = new List <Provider> { _provider1, _provider2, _provider3 }; _providers = new AuctionProviders(_completeListOfProvices); _sut.AddProvider(_provider1, new CheckWhatInviteStrategy(), new InviteProviderToSecondLastRoundStrategy()); }
public void Setup() { sniperListener = Substitute.For <ISniperListener>(); auction = Substitute.For <IAuction>(); item = new Item("test item", Int32.MaxValue); sniper = new AuctionSniper(item, auction); sniper.AddSniperListener(sniperListener); }
public void SiteUSersAuctionInitialize() { siteFactory.CreateSiteOnDb(connectionString, SiteName, Timezone, 300, 7); AlarmClockMock(Timezone, out AlarmClock); Site = siteFactory.LoadSite(connectionString, SiteName, AlarmClock.Object); Seller = CreateAndLogUser("seller", out SellerSession, Site); Bidder1 = CreateAndLogUser("bidder1", out Bidder1Session, Site); TheAuction = SellerSession.CreateAuction("Lidl socks", AlarmClock.Object.Now.AddDays(7), 5); }
protected bool CheckAuctionValues(IAuction auction, int auctionId, string sellerUsername, DateTime endsOn, string auctionDescription, double auctionCurrentPrice, string currentWinnerUsername = null) { IUser currentWinner = auction.CurrentWinner(); var correctCurrentWinner = (currentWinnerUsername == null && currentWinner == null) || (currentWinner != null && currentWinner.Username != null && currentWinner.Username == currentWinnerUsername); return(auction.Id == auctionId && auction.Seller.Username == sellerUsername && SameDateTime(auction.EndsOn, endsOn) && auction.Description == auctionDescription && correctCurrentWinner && Math.Abs(auction.CurrentPrice() - auctionCurrentPrice) < .001); }
public void Setup() { List <ISession> expectedSessionList1; var newSite1 = CreateAndLoadSite(timeZone, siteName, sessionExpirationTimeInSeconds, minimumBidIncrement, userList, userList, 0, out expectedSessionList1, out alarmClockMoq, password); var aliceExpectedSession = expectedSessionList1.FirstOrDefault(s => s.User.Username == alice); var barbaraExpectedSession = expectedSessionList1.FirstOrDefault(s => s.User.Username == barbara); var carlottaExpectedSession = expectedSessionList1.FirstOrDefault(s => s.User.Username == carlotta); var dalilaExpectedSession = expectedSessionList1.FirstOrDefault(s => s.User.Username == dalila); barbaraAuctionEndsOn = new DateTime(2035, 12, 7); barbaraAuction = barbaraExpectedSession.CreateAuction(barbaraAuctionDescription, barbaraAuctionEndsOn, barbaraStartingPrice); if (!barbaraAuction.BidOnAuction(dalilaExpectedSession, 7.75)) { Assert.Fail("Dalila's bid should have been accepted"); } dalilaExpectedSession.Logout(); if (!barbaraAuction.BidOnAuction(carlottaExpectedSession, 9.27)) { Assert.Fail("Carlotta's bid should have been accepted"); } carlottaExpectedSession.Logout(); aliceAuctionEndsOn = alarmClockMoq.Object.Now; aliceAuction = aliceExpectedSession.CreateAuction(aliceAuctionDescription, aliceAuctionEndsOn, aliceStartingPrice); expectedAuctionList = new List <IAuction> { barbaraAuction, aliceAuction }; SetNowToFutureTime(60 * 60 * 23, alarmClockMoq); barbaraExpectedSession = newSite1.Login(barbara, password); SetNowToFutureTime(60 * 30, alarmClockMoq); aliceExpectedSession = newSite1.Login(alice, password); SetNowToFutureTime(60 * 30, alarmClockMoq); var fine = alarmClockMoq.Object.Now; newSite1.CleanupSessions(); expectedSessionList1 = new List <ISession> { barbaraExpectedSession, aliceExpectedSession }; var yesterday = alarmClockMoq.Object.Now.AddDays(-1); var ok = yesterday.Year == aliceAuctionEndsOn.Year && yesterday.Month == aliceAuctionEndsOn.Month && yesterday.Day == aliceAuctionEndsOn.Day; Assert.That(ok, "Wrong setup: current time is not day after Alice's auction ends"); Assert.That(aliceExpectedSession.ValidUntil, Is.GreaterThanOrEqualTo(alarmClockMoq.Object.Now.AddHours(1)), "Wrong setup: Alice's session has not the expected validity"); Assert.That(barbaraExpectedSession.ValidUntil, Is.GreaterThanOrEqualTo(alarmClockMoq.Object.Now.AddMinutes(30)), "Wrong setup: Barbara's session has not the expected validity"); expectedSessionList = expectedSessionList1; }
public void OnCreatorDelete_Null_CurrentWinner() { Bidder1 = CreateAndLogUser("bidder1", out Bidder1Session, Site); TheAuction = SellerSession.CreateAuction("lidl socks", AlarmClock.Object.Now.AddDays(3), 2); TheAuction.BidOnAuction(Bidder1Session, 8); var now = AlarmClock.Object.Now; AlarmClock.Setup(ac => ac.Now).Returns(now.AddDays(8)); Bidder1.Delete(); Assert.That(TheAuction.CurrentWinner(), Is.Null); }
#pragma warning disable CS0246 // Il nome di tipo o di spazio dei nomi 'IAuction' non è stato trovato. Probabilmente manca una direttiva using o un riferimento all'assembly. protected bool CheckAuctionValues(IAuction auction, int auctionId, string sellerUsername, DateTime endsOn, #pragma warning restore CS0246 // Il nome di tipo o di spazio dei nomi 'IAuction' non è stato trovato. Probabilmente manca una direttiva using o un riferimento all'assembly. string auctionDescription, double auctionCurrentPrice, string currentWinnerUsername = null) { IUser currentWinner = auction.CurrentWinner(); var correctCurrentWinner = (currentWinnerUsername == null && currentWinner == null) || (currentWinner != null && currentWinner.Username != null && currentWinner.Username == currentWinnerUsername); return(auction.Id == auctionId && auction.Seller.Username == sellerUsername && SameDateTime(auction.EndsOn, endsOn) && auction.Description == auctionDescription && correctCurrentWinner && Math.Abs(auction.CurrentPrice() - auctionCurrentPrice) < .001); }
public override IBid CreateBid(string id, IAuction auction, IUser buyer, System.Double amount, System.Double maxAmount) { IContext context = GetContext(); Bid bid = (Bid) context.CreateObject(typeof(Bid)); bid.Id = id; bid.Auction = auction; bid.Buyer = buyer; bid.Amount = amount; bid.MaxAmount = maxAmount; return bid; }
public void JoinAuction(string sniperId, Item item) { List <IAuctionEventListener> eventListeners = new List <IAuctionEventListener>(); IAuction auction = auctionHouse.AuctionFor(item); AuctionSniper sniper = new AuctionSniper(item, auction); auction.AddAuctionEventListener(sniper); eventListeners.Add(sniper); collector.AddSniper(sniper); auction.Join(); }
#pragma warning restore CS0246 // Il nome di tipo o di spazio dei nomi 'SetUpAttribute' non è stato trovato. Probabilmente manca una direttiva using o un riferimento all'assembly. #pragma warning restore CS0246 // Il nome di tipo o di spazio dei nomi 'SetUp' non è stato trovato. Probabilmente manca una direttiva using o un riferimento all'assembly. public void SiteUSersAuctionInitialize() { const int timeZone = -2; siteFactory.CreateSiteOnDb(connectionString, SiteName, timeZone, 300, 7); AlarmClockMock(timeZone, out AlarmClock); Site = siteFactory.LoadSite(connectionString, SiteName, AlarmClock.Object); Seller = CreateAndLogUser("seller", out SellerSession, Site); Bidder1 = CreateAndLogUser("bidder1", out Bidder1Session, Site); Bidder2 = CreateAndLogUser("bidder2", out Bidder2Session, Site); TheAuction = SellerSession.CreateAuction("Beautiful object to be desired by everybody", AlarmClock.Object.Now.AddDays(7), 5); }
public override IBid CreateBid(string id, IAuction auction, IUser buyer, System.Double amount, System.Double maxAmount) { IContext context = GetContext(); Bid bid = (Bid)context.CreateObject(typeof(Bid)); bid.Id = id; bid.Auction = auction; bid.Buyer = buyer; bid.Amount = amount; bid.MaxAmount = maxAmount; return(bid); }
private void JoinAuction(JabberClient inConnection, string inItemId) { mAuction = new XMPPAuction( new Chat(this.ToJid(inItemId, inConnection), inConnection), new SniperStateDisplayer() ); if (this.BeginJoining != null) { this.BeginJoining(inConnection); } inConnection.Connect(); ConsoleAppHelper.WaitConnectingTo(inConnection); mAuction.Join(); }
public void CreateAuction() { string name, desc; int startBid; Console.WriteLine("Creating an auction:"); Console.Write("Name: "); do { name = Console.ReadLine(); if (name == null) { Console.WriteLine("Name is required."); Console.Write("Name: "); } } while (name == null); Console.Write("Description: "); desc = Console.ReadLine(); Console.Write("Starting bid: "); startBid = Convert.ToInt32(Console.ReadLine()); Item item; if (desc == null && startBid == 0) { item = new Item(name); } else if (desc == null && startBid != 0) { item = new Item(name, startBid); } else if (desc != null && startBid == 0) { item = new Item(name, desc); } else { item = new Item(name, desc, startBid); } Auction = new ProxyAuction(item); }
public void AddsNewSniperToCollectorAndThenJoinsAuction() { Item item = new Item("item 123", Int32.MaxValue); IAuctionHouse auctionHouse = Substitute.For <IAuctionHouse>(); IAuction auction = Substitute.For <IAuction>(); ISniperCollector collector = Substitute.For <ISniperCollector>(); auctionHouse.AuctionFor(item).Returns(auction); auction.When(a => a.Join()).Do(a => { auction.Received(1).AddAuctionEventListener(Arg.Is <AuctionSniper>(s => s.Item.Equals(item))); collector.Received(1).AddSniper(Arg.Is <AuctionSniper>(s => s.Item.Equals(item))); }); SniperLauncher launcher = new SniperLauncher(auctionHouse, collector); launcher.JoinAuction(ApplicationRunner.SNIPER_ID, item); auction.Received(1).Join(); }
public void Delete() { if (!UserSite.IsUserInSite(this.Username)) { throw new InvalidOperationException(); } IAuction currAuction = null; IEnumerable <IAuction> allOpenAuctions = UserSite.GetAuctions(true); //Solo aste aperte IEnumerator <IAuction> auctionIterator = allOpenAuctions.GetEnumerator(); while (auctionIterator.MoveNext()) { currAuction = auctionIterator.Current; if ((currAuction.Seller as User).Equals(this) || (currAuction.CurrentWinner() as User).Equals(this)) { throw new InvalidOperationException(); } } auctionIterator.Dispose(); /* * Se arrivo qui vuol dire che l'utente può essere tranquillamente cancellato in quanto * non fa parte di aste in corso */ this.factoryContext = new SiteFactoryContext(UserSite.ConnectionString); IEnumerable <IAuction> allAuctions = UserSite.GetAuctions(false); auctionIterator = allAuctions.GetEnumerator(); while (auctionIterator.MoveNext()) { currAuction = auctionIterator.Current; if ((currAuction.Seller as User).Equals(this)) { /* * Se sono arrivato a poter fare questo if vuol dire che sto valutando * per forza un'asta chiusa * (se fosse aperta sarei caduto nell'exception precedente!) */ currAuction.Delete(); } else { if ((currAuction.CurrentWinner() as User).Equals(this)) { /* * Stesso discorso di sopra; * se sono arrivato qui sono sicuro che quest'asta è chiusa altrimenti * sarei caduto nell'exception precedente! */ /*Update Auction on DB*/ factoryContext.Database.ExecuteSqlCommand("update dbo.Auctions set AuctionCurrentWinner_Username = '' where Id = " + currAuction.Id); } } } auctionIterator.Dispose(); /*In ogni caso cancello l'utente dal db*/ factoryContext.Database.ExecuteSqlCommand("delete from dbo.Users where Username = '******'"); factoryContext.Database.Connection.Close(); }
public AuctionSniper(IAuction auction, ISniperListener sniperListener) { _auction = auction; _sniperListener = sniperListener; }
public AuctionSniper(ISniperListener sniperListener, IAuction auction) { this.sniperListener = sniperListener; this.auction = auction; }
public AuctionStarter(IAuction auction, List <IAgent> agents) { _auction = auction; _agents = agents; }
public AuctionInfo CreateAuctionInfo(IAuction auction, bool partial) { return new AuctionInfo(auction, partial); }
public Sniper(IAuction auction, Item item) { _auction = auction; _item = item; _snapshot = SniperSnapshot.Joining(item.Identifier); }
public AuctionSniper(IAuction inAuction, ISniperListener inListener) { mAuction = inAuction; mListener = inListener; }
public void TestSetup() { _mocks = new MockRepository(); _mockAuction = _mocks.StrictMock<IAuction>(); _mockSniperListener = _mocks.StrictMock<ISniperListener>(); _sniper = new Domain.AuctionSniper(_mockAuction, _mockSniperListener); }
public AuctionSniper(Item item, IAuction auction) { this.item = item; this.auction = auction; this.snapShot = SniperSnapshot.Joining(item.Identifier); }
public abstract IBid CreateBid(string id, IAuction auction, IUser buyer, System.Double amount, System.Double maxAmount);