public void Insert_BidderOwnsThePreviousBid() { var bidder = new Bidder(); var prevBid = new Bid { Bidder = bidder }; var auction = new DomainModel.Auction { CurrentPrice = 200, Bids = { prevBid } }; var bid = new Bid { Bidder = bidder, Auction = auction, Value = 210 }; this.mockRepository.Setup(x => x.Insert(It.IsAny <Bid>())); var bidServices = new BidService(this.mockRepository.Object); bidServices.Insert(bid).Should().NotBeEmpty(); }
public static void AddAuction() { Auction auction = new Auction(); User user = new User(); Product product = new Product(); auction.Product = product; IAuctionService auctionService = new AuctionService(); auctionService.AddNewAuction(auction, user); }
public void AddNewAuction(Auction auction) { using(var context=new AuctionModelContainer()) { context.Users.Attach(auction.User); context.Currencies.Attach(auction.Currency); context.Products.Attach(auction.Product); context.Auctions.Add(auction); context.SaveChanges(); } }
/// <summary> /// The CreateAuction. /// </summary> /// <returns>The <see cref="Auction"/>.</returns> public static Auction CreateAuction() { var auction = new DomainModel.Auction { Id = auctionId, Name = nameof(DomainModel.Auction) + auctionId, Address = "online", BeginDate = DateTime.Now, EndDate = DateTime.Now.AddDays(1), BeginPrice = 100, CurrentPrice = 100, CurrencyName = "Euro", Active = true }; auctionId++; return(auction); }
internal static void Validate(Auction auction, ValidationResults results) { if (auction.StartPrice > 10000000 || auction.StartPrice < 0.1)//some business-logic derived condition { results.AddResult ( new ValidationResult("In a auction start price must be between 0.1 and 10000000", auction, "ValidateMethod", "error", null) ); } if (auction.BeginDate > auction.EndDate)//some business-logic derived condition { results.AddResult ( new ValidationResult("In a auction begin date can not be grater than end date", auction, "ValidateMethod", "error", null) ); } }
public void Insert_BidWithTooHighValue() { var auction = new DomainModel.Auction { CurrentPrice = 200 }; var bid = new Bid { Bidder = new Bidder(), Auction = auction, Value = 300 }; this.mockRepository.Setup(x => x.Insert(It.IsAny <Bid>())); var bidServices = new BidService(this.mockRepository.Object); bidServices.Insert(bid).Should().NotBeEmpty(); }
public void AddNewAuction(User user,Product product,Currency currency,double startPrice,DateTime startDate,DateTime endDate) { try { logger.logInfo("User "+user.Email+" try to add a new auction."); CheckUser(user); CheckProduct(product,user); Auction auction = new Auction(); auction.User = user; auction.Product = product; auction.Currency = currency; auction.StartPrice = startPrice; auction.BeginDate = startDate; auction.EndDate = endDate; var validationResults = Validation.Validate<Auction>(auction); if (!validationResults.IsValid) { throw new ValidationException("Invalid auction"); } DataMapperFactoryMethod.GetCurrentFactory().AuctionFactory.AddNewAuction(auction); } catch (EntityDoesNotExistException exc) { logger.logError(exc); throw exc; } catch (ValidationException validationException) { logger.logError(validationException); throw validationException; } catch (AuctionException auctioException) { logger.logError(auctioException); throw auctioException; } }
public ICollection<User> GetAllUsersThatParticipateToAnAuction(Auction auction) { using (var context = new AuctionModelContainer()) { var userVar = (from user in context.Users join productAuction in context.ProductAuctions on user.IdUser equals productAuction.UserIdUser join auxAuction in context.Auctions on productAuction.AuctionIdAuction equals auxAuction.IdAuction where auxAuction.IdAuction == auction.IdAuction select user).ToList(); return userVar; } }