/// <summary> /// Full constructor. /// </summary> public BankAccount(string ownerName, User user, string number, string bankName, string bankSwift) : base(ownerName, user) { this.number = number; this.bankName = bankName; this.bankSwift = bankSwift; }
/// <summary> /// Full constructor. /// </summary> public Comment(Rating rating, string text, User fromUser, Item item) { this.rating = rating; this.text = text; this.fromUser = fromUser; this.item = item; }
/// <summary> Full constructor. </summary> public CreditCard(string ownerName, User user, string number, CreditCardType type, string expMonth, string expYear) : base(ownerName, user) { this.type = type; this.number = number; this.expMonth = expMonth; this.expYear = expYear; }
/// <summary> Full constructor.</summary> public Item(string name, string description, User seller, MonetaryAmount initialPrice, MonetaryAmount reservePrice, DateTime startDate, DateTime endDate, ISet categories, IList bids, Bid successfulBid) { this.name = name; this.seller = seller; this.description = description; this.initialPrice = initialPrice; this.reservePrice = reservePrice; this.startDate = startDate; this.endDate = endDate; categorizedItems = categories; this.bids = bids; this.successfulBid = successfulBid; state = ItemState.Draft; }
public void AuditLogInterceptor_Records_Log_Entry_When_Item_Persisted() { // Save a user without audit logging UserDAO userDAO = new UserDAO(); User seller = new User("Christian", "Bauer", "turin", "abc123", "*****@*****.**"); userDAO.MakePersistent(seller); NHibernateHelper.CommitTransaction(); NHibernateHelper.CloseSession(); // Enable interceptor AuditLogInterceptor interceptor = new AuditLogInterceptor(); NHibernateHelper.RegisterInterceptor(interceptor); interceptor.Session = NHibernateHelper.Session; interceptor.UserId = seller.Id; // Save an item with audit logging enabled Item item = new Item( "Warfdale Nearfield Monitors", "Pair of 150W nearfield monitors for the home studio.", seller, new MonetaryAmount(1.99, "USD"), new MonetaryAmount(50.33, "USD"), DateTime.Now, DateTime.Now.AddDays(1) ); ItemDAO itemDAO = new ItemDAO(); itemDAO.MakePersistent(item); // Synchronize state to trigger interceptor NHibernateHelper.Session.Flush(); // Check audit log IQuery findAuditLogRecord = NHibernateHelper.Session.CreateQuery("from AuditLogRecord record where record.EntityId = :id"); findAuditLogRecord.SetParameter("id", item.Id); AuditLogRecord foundRecord = findAuditLogRecord.UniqueResult<AuditLogRecord>(); Assert.IsNotNull(foundRecord); Assert.AreEqual(foundRecord.UserId, seller.Id); NHibernateHelper.CommitTransaction(); NHibernateHelper.CloseSession(); // Deregister interceptor NHibernateHelper.RegisterInterceptor(null); }
/// <summary> /// Full constructor /// </summary> protected internal BillingDetails(string ownerName, User user) { this.ownerName = ownerName; this.user = user; }
/// <summary> Full constructor. </summary> public Bid(MonetaryAmount amount, Item item, User bidder) { this.amount = amount; this.item = item; this.bidder = bidder; }
public void SetUpData() { //create database CreateDatabase(); //create common test data tobin = CreateTobin(); iMac = CreateAppleiMac(tobin); //save them using DAOs items = new ItemDAO(); users = new UserDAO(); users.MakePersistent(tobin); items.MakePersistent(iMac); //commit NHibernateHelper.CommitTransaction(); NHibernateHelper.CloseSession(); }
public User CreateTobin() { User t = new User( "Tobin", "Harris", "tobinharris", "I♥NHibernate", "*****@*****.**" ); t.HomeAddress = new Address("Monkbridge Road","LS6 4DX", "Leeds"); t.BillingAddress = new Address("Round Foundry Media Center", "LS11 4QP", "Leeds"); return t; }
public Item CreateAppleiMac(User seller) { return new Item( "Apple iMac 2.4Ghz", "Used Apple iMac in great condition", seller, new MonetaryAmount(999.99, "GBP"), new MonetaryAmount(100.00, "GBP"), DateTime.Now, DateTime.Now.AddDays(5) ); }
/// <summary> Approve this item for auction and set its state to active. </summary> public virtual void Approve(User byUser) { if (!byUser.IsAdmin) throw new PermissionException("Not an administrator."); /* if(state != ItemState.Pending) throw new BusinessException("Item still in draft."); state = ItemState.Active; approvedBy = byUser; approvalDatetime = DateTime.Now;*/ }
/// <summary> Create test data for our domain model. /// /// </summary> /// <throws> Exception </throws> protected internal virtual void InitData() { CreateDatabase(); // Prepare DAOS CategoryDAO catDAO = new CategoryDAO(); UserDAO userDAO = new UserDAO(); ItemDAO itemDAO = new ItemDAO(); CommentDAO commentDAO = new CommentDAO(); // Categories cars = new Category("Cars"); carsLuxury = new Category("Luxury Cars"); cars.AddChildCategory(carsLuxury); carsSUV = new Category("SUVs"); cars.AddChildCategory(carsSUV); catDAO.MakePersistent(cars); // Users u1 = new User("Christian", "Bauer", "turin", "abc123", "*****@*****.**"); u1.HomeAddress = new Address("Foo", "12345", "Bar"); u1.IsAdmin = true; u2 = new User("Gavin", "King", "gavin", "abc123", "*****@*****.**"); u2.HomeAddress = new Address("Foo", "12345", "Bar"); u3 = new User("Max", "Andersen", "max", "abc123", "*****@*****.**"); u3.HomeAddress = new Address("Foo", "12345", "Bar"); userDAO.MakePersistent(u1); userDAO.MakePersistent(u2); userDAO.MakePersistent(u3); // BillingDetails BillingDetails ccOne = new CreditCard( "Christian Bauer", u1, "1234567890", CreditCardType.MasterCard, "10", "2005"); BillingDetails accOne = new BankAccount( "Christian Bauer", u1, "234234234234", "FooBar Rich Bank", "foobar123foobaz"); u1.AddBillingDetails(ccOne); u1.AddBillingDetails(accOne); // Items DateTime tempAux = DateTime.Now; DateTime tempAux2 = DateTime.Now.AddDays(3);// inThreeDays auctionOne = new Item("Item One", "An item in the carsLuxury category.", u2, new MonetaryAmount(1.99, "USD"), new MonetaryAmount(50.33, "USD"), tempAux, tempAux2); auctionOne.SetPendingForApproval(); auctionOne.Approve(u1); itemDAO.MakePersistent(auctionOne); new CategorizedItem(u1.Username, carsLuxury, auctionOne); DateTime tempAux3 = DateTime.Now; DateTime tempAux4 = DateTime.Now.AddDays(5); // inFiveDays auctionTwo = new Item("Item Two", "Another item in the carsLuxury category.", u2, new MonetaryAmount(2.22, "USD"), new MonetaryAmount(100.88, "USD"), tempAux3, tempAux4); itemDAO.MakePersistent(auctionTwo); new CategorizedItem(u1.Username, carsLuxury, auctionTwo); DateTime tempAux5 = DateTime.Now; DateTime tempAux6 = DateTime.Now.AddDays(3);// inThreeDays auctionThree = new Item("Item Three", "Don't drive SUVs.", u2, new MonetaryAmount(3.11, "USD"), new MonetaryAmount(300.55, "USD"), tempAux5, tempAux6); itemDAO.MakePersistent(auctionThree); new CategorizedItem(u1.Username, carsSUV, auctionThree); DateTime tempAux7 = DateTime.Now; DateTime tempAux8 = DateTime.Now.AddDays(7);// nextWeek auctionFour = new Item("Item Four", "Really, not even luxury SUVs.", u1, new MonetaryAmount(4.55, "USD"), new MonetaryAmount(40.99, "USD"), tempAux7, tempAux8); itemDAO.MakePersistent(auctionFour); new CategorizedItem(u1.Username, carsLuxury, auctionFour); new CategorizedItem(u1.Username, carsSUV, auctionFour); // Bids Model.Bid bidOne1 = new Model.Bid(new MonetaryAmount(12.12, "USD"), auctionOne, u3); Model.Bid bidOne2 = new Model.Bid(new MonetaryAmount(13.13, "USD"), auctionOne, u1); Model.Bid bidOne3 = new Model.Bid(new MonetaryAmount(14.14, "USD"), auctionOne, u3); auctionOne.AddBid(bidOne1); auctionOne.AddBid(bidOne2); auctionOne.AddBid(bidOne3); // Successful Bid auctionOne.SuccessfulBid = bidOne3; // Comments Comment commentOne = new Comment(Rating.Excellent, "This is Excellent.", u3, auctionOne); Comment commentTwo = new Comment(Rating.Low, "This is very Low.", u1, auctionThree); commentDAO.MakePersistent(commentOne); commentDAO.MakePersistent(commentTwo); NHibernateHelper.CommitTransaction(); NHibernateHelper.CloseSession(); }
/// <summary> Simple properties only constructor.</summary> public Item(string name, string description, User seller, MonetaryAmount initialPrice, MonetaryAmount reservePrice, DateTime startDate, DateTime endDate) { this.name = name; this.seller = seller; this.description = description; this.initialPrice = initialPrice; this.reservePrice = reservePrice; this.startDate = startDate; this.endDate = endDate; state = ItemState.Draft; }
/// <summary> Places a bid while checking business constraints. /// This method may throw a BusinessException if one of the requirements /// for the bid placement wasn't met, e.g. if the auction already ended. /// </summary> /// <param name="bidder"> /// </param> /// <param name="bidAmount"> /// </param> /// <param name="currentMaxBid"> the most valuable bid for this item /// </param> /// <param name="currentMinBid"> the least valuable bid for this item /// </param> /// <returns> /// </returns> public virtual Bid PlaceBid(User bidder, MonetaryAmount bidAmount, Bid currentMaxBid, Bid currentMinBid) { // Check highest bid (can also be a different Strategy (pattern)) if (currentMaxBid != null && currentMaxBid.Amount.CompareTo(bidAmount) > 0) { throw new BusinessException("Bid too low."); } // Auction is active if (state != ItemState.Active) throw new BusinessException("Auction is not active yet."); // Auction still valid if (EndDate < DateTime.Now) throw new BusinessException("Can't place new bid, auction already ended."); // Create new Bid var newBid = new Bid(bidAmount, this, bidder); // Place bid for this Item AddBid(newBid); return newBid; }