public void DoCheck_ShouldBeValid() { var offeror = InstanceHelper.GetPersonOfferor(); var auction = InstanceHelper.GetAuction(); var offerorAuction = new List <Auction>(); var allProducts = new List <Product>(); var result = CanAuctionBePostedCheck.DoCheck(offeror, auction, offerorAuction, allProducts); Assert.True(result); }
public void DoCheckSimiliarAuctions_ShouldNotBeValid() { var offeror = InstanceHelper.GetPersonOfferor(); var auction = InstanceHelper.GetAuction(); var offerorAuction = new List <Auction>(); var allProducts = new List <Product>(); allProducts.Add(InstanceHelper.GetProduct()); var result = CanAuctionBePostedCheck.DoCheck(offeror, auction, offerorAuction, allProducts); Assert.False(result); }
public void DoCheckBanned_ShouldNotBeValid() { var offeror = InstanceHelper.GetPersonOfferor(); offeror.LastBannedDate = DateTime.Now; var auction = InstanceHelper.GetAuction(); var offerorAuction = new List <Auction>(); var allProducts = new List <Product>(); var result = CanAuctionBePostedCheck.DoCheck(offeror, auction, offerorAuction, allProducts); Assert.False(result); }
public void DoCheckMaxCategory_ShouldNotBeValid() { var offeror = InstanceHelper.GetPersonOfferor(); var auction = InstanceHelper.GetAuction(); var offerorAuction = new List <Auction>(); for (int i = 0; i < 2; i++) { offerorAuction.Add(InstanceHelper.GetAuction()); } var allProducts = new List <Product>(); var result = CanAuctionBePostedCheck.DoCheck(offeror, auction, offerorAuction, allProducts); Assert.False(result); }
/// <summary> /// Registers the auction. /// </summary> /// <param name="person">The person.</param> /// <param name="auction">The auction.</param> /// <returns> /// False if the register auction has failed. /// </returns> /// <exception cref="System.Exception">Person is not registered!</exception> public Auction RegisterAuction(Person person, Auction auction) { IPersonOfferorTable personOfferorTable = this.tablesProvider.GetPersonOfferorTable(); IProductTable productTable = this.tablesProvider.GetProductTable(); IAuctionTable auctionTable = this.tablesProvider.GetAuctionTable(); PersonOfferor offeror = personOfferorTable.FetchPersonOfferorByPerson(person); offeror.Person = person; Currency currency = auction.Currency; Category category = auction.Product.Category; try { auction.PersonOfferor = offeror ?? throw new Exception("BAD OFFEROR"); auction.ValidateObject(); auction.Currency.ValidateObject(); auction.Product.ValidateObject(); if (auction.Currency.IdCurrency == 0) { throw new Exception("Invalid currency."); } Product product = productTable.FetchProductByAllAttributes(auction.Product.Category.IdCategory, auction.Product); if (product != null) { product.Category = category; Auction fetched = auctionTable.FetchAuctionByIds(offeror.IdOfferor, product.IdProduct); if (fetched.IdAuction != 0) { fetched.PersonOfferor = offeror; fetched.Product = product; fetched.Currency = currency; return(fetched); ////throw new Exception("Auction is already registered"); } } } catch (Exception e) { throw e; } List <Auction> offerorAuctions = auctionTable.FetchOfferorAuctions(offeror); List <Product> existingProducts = productTable.FetchAllProducts(); bool canPost = CanAuctionBePostedCheck.DoCheck(offeror, auction, offerorAuctions, existingProducts); if (!canPost) { throw new Exception("CanAuctionBePostedCheck failed!"); } productTable.InsertProduct(category.IdCategory, auction.Product); Product selectedProduct = productTable.FetchProductByAllAttributes(category.IdCategory, auction.Product); selectedProduct.Category = category; auctionTable.InsertAuction(offeror.IdOfferor, selectedProduct.IdProduct, currency.IdCurrency, auction); auction = auctionTable.FetchAuctionByIds(offeror.IdOfferor, selectedProduct.IdProduct); auction.PersonOfferor = offeror; auction.Product = selectedProduct; auction.Currency = currency; this.auctions.Add(auction); AuctionService auctionService = new AuctionService(auction); auctionService.StartTimers(); return(auction); }