public void TestCreateBusiness() { var a = EntityHelper.GetAccount("first", "lastName"); var b = EntityHelper.GetBusiness("business1", Category.ActiveLife); using (var Scope = new SQLiteDatabaseScope<PraLoupAutoMappingConfiguration>()) { using (ISession Session = Scope.OpenSession()) { Session.Transaction.Begin(); IRepository r = new GenericRepository(Session); EntityDataService<Business, BusinessValidator> bds = new EntityDataService<Business, BusinessValidator>(r, new BusinessValidator()); IDataService ds = new DataService(null, bds, null, null, null, null, null, null, null, new UnitOfWork(Session)); BusinessActions ba = new BusinessActions(a, ds, new PraLoup.Infrastructure.Logging.Log4NetLogger(), null); ba.CreateBusiness(b, a, Role.BusinessAdmin); Session.Transaction.Commit(); } using (ISession Session = Scope.OpenSession()) { IRepository r = new GenericRepository(Session); EntityDataService<Business, BusinessValidator> bds = new EntityDataService<Business, BusinessValidator>(r, new BusinessValidator()); var b1 = bds.Find(b.Id); Assert.IsNotNull(b1); Assert.AreEqual(b, b1); } } }
public void TestCreatePromotion() { var a = EntityHelper.GetAccount("first", "lastName"); var b = EntityHelper.GetBusiness("business1", Category.ActiveLife); var e = EntityHelper.GetEvent("ev name", "venue name"); var d = EntityHelper.GetDeal("dealname", 10); var p = new Promotion(b, e, d, 100, 5); using (var Scope = new SQLiteDatabaseScope<PraLoupAutoMappingConfiguration>()) { using (ISession Session = Scope.OpenSession()) { IRepository r = new GenericRepository(Session); EntityDataService<Business, BusinessValidator> bds = new EntityDataService<Business, BusinessValidator>(r, new BusinessValidator()); EntityDataService<Promotion, PromotionValidator> pds = new EntityDataService<Promotion, PromotionValidator>(r, new PromotionValidator()); IDataService ds = new DataService(null, bds, pds, null, null, null, null, null, null, new UnitOfWork(Scope.GetSessionFactory().OpenSession())); BusinessActions ba = new BusinessActions(a, ds, Log, null); PromotionActions pa = new PromotionActions(a, ds, Log, null); Session.Transaction.Begin(); b = ba.CreateBusiness(b, a, Role.BusinessAdmin); Assert.IsNotNull(b, "business should be saved succesfully"); Session.Transaction.Commit(); } using (ISession Session = Scope.OpenSession()) { IRepository r = new GenericRepository(Session); EntityDataService<Business, BusinessValidator> bds = new EntityDataService<Business, BusinessValidator>(r, new BusinessValidator()); EntityDataService<Promotion, PromotionValidator> pds = new EntityDataService<Promotion, PromotionValidator>(r, new PromotionValidator()); IDataService ds = new DataService(null, bds, pds, null, null, null, null, null, null, new UnitOfWork(Scope.GetSessionFactory().OpenSession())); BusinessActions ba = new BusinessActions(a, ds, Log, null); PromotionActions pa = new PromotionActions(a, ds, Log, null); Session.Transaction.Begin(); p = pa.SavePromotion(p); Assert.IsNotNull(p, "promotion should be saved succesfully"); Session.Transaction.Commit(); } using (ISession Session = Scope.OpenSession()) { IRepository r = new GenericRepository(Session); EntityDataService<Promotion, PromotionValidator> pds = new EntityDataService<Promotion, PromotionValidator>(r, new PromotionValidator()); var p1 = pds.Find(p.Id); Assert.IsNotNull(p1); Assert.AreEqual(p, p1); } } }
public void IsFriendGenerateOkSQL_Success() { using (var Scope = new SQLiteDatabaseScope<PraLoupAutoMappingConfiguration>()) { using (ISession Session = Scope.OpenSession()) { IRepository r = new GenericRepository(Session); EntityDataService<Account, AccountValidator> ads = new EntityDataService<Account, AccountValidator>(r, new AccountValidator()); var cds = new EntityDataService<Connection, ConnectionValidator>(r, new ConnectionValidator()); DataService ds = new DataService(ads, null, null, null, null, cds, null, null, null, new UnitOfWork(Session)); ds.UnitOfWork.Begin(); IEnumerable<string> s; ds.Account.SaveOrUpdateAll(new Account[] { myself, friend, friend2, friend3, friend4 }, out s); ds.UnitOfWork.End(); } using (ISession Session = Scope.OpenSession()) { IRepository r = new GenericRepository(Session); EntityDataService<Account, AccountValidator> ads = new EntityDataService<Account, AccountValidator>(r, new AccountValidator()); var cds = new EntityDataService<Connection, ConnectionValidator>(r, new ConnectionValidator()); DataService ds = new DataService(ads, null, null, null, null, cds, null, null, null, new UnitOfWork(Session)); ds.UnitOfWork.Begin(); var c = ads.GetAll().ToList(); var m = ads.Find(myself.Id); var f = ads.Find(friend.Id); var f3 = ads.Find(friend3.Id); Log.Debug("executing isfriend"); Assert.IsTrue(m.IsFriend(f, ds)); Log.Debug("executing isfriendoffriend"); Assert.IsTrue(m.IsFriendOfFriend(f3, ds)); ds.UnitOfWork.End(); } } }
public void IsFriendOfFriend_Success() { using (var Scope = new SQLiteDatabaseScope<PraLoupAutoMappingConfiguration>()) { using (ISession Session = Scope.OpenSession()) { IRepository r = new GenericRepository(Session); EntityDataService<Account, AccountValidator> ads = new EntityDataService<Account, AccountValidator>(r, new AccountValidator()); EntityDataService<Connection, ConnectionValidator> cds = new EntityDataService<Connection, ConnectionValidator>(r, new ConnectionValidator()); DataService ds = new DataService(ads, null, null, null, null, cds, null, null, null, new UnitOfWork(Session)); ds.UnitOfWork.Begin(); IEnumerable<string> s; ds.Account.SaveOrUpdateAll(new Account[] { myself, friend, friend2, friend3, friend4 }, out s); ds.UnitOfWork.Commit(); Assert.IsTrue(myself.IsFriendOfFriend(friend3, ds)); Assert.IsTrue(friend3.IsFriendOfFriend(myself, ds)); Assert.IsFalse(myself.IsFriendOfFriend(friend4, ds)); Assert.IsFalse(friend4.IsFriendOfFriend(myself, ds)); } } }
public void TestAcceptDeclinePromotionInstance() { var a = EntityHelper.GetAccount("first", "lastName"); var i1 = EntityHelper.GetAccount("invite1", "lastName"); var i2 = EntityHelper.GetAccount("invite2", "lastName"); var i3 = EntityHelper.GetAccount("invite3", "lastName"); var b = EntityHelper.GetBusiness("business1", Category.ActiveLife); var e = EntityHelper.GetEvent("ev name", "venue name"); var d = EntityHelper.GetDeal("dealname", 10); var p = new Promotion(b, e, d, 100, 5); using (var Scope = new SQLiteDatabaseScope<PraLoupAutoMappingConfiguration>()) { using (ISession Session = Scope.OpenSession()) { IRepository r = new GenericRepository(Session); EntityDataService<Business, BusinessValidator> bds = new EntityDataService<Business, BusinessValidator>(r, new BusinessValidator()); EntityDataService<Promotion, PromotionValidator> pds = new EntityDataService<Promotion, PromotionValidator>(r, new PromotionValidator()); IDataService ds = new DataService(null, bds, pds, null, null, null, null, null, null, new UnitOfWork(Session)); BusinessActions ba = new BusinessActions(a, ds, Log, null); PromotionActions pa = new PromotionActions(a, ds, Log, null); Session.Transaction.Begin(); b = ba.CreateBusiness(b, a, Role.BusinessAdmin); Assert.IsNotNull(b, "business should be saved succesfully"); Session.Transaction.Commit(); } using (ISession Session = Scope.OpenSession()) { IRepository r = new GenericRepository(Session); EntityDataService<Business, BusinessValidator> bds = new EntityDataService<Business, BusinessValidator>(r, new BusinessValidator()); EntityDataService<Promotion, PromotionValidator> pds = new EntityDataService<Promotion, PromotionValidator>(r, new PromotionValidator()); IDataService ds = new DataService(null, bds, pds, null, null, null, null, null, null, new UnitOfWork(Session)); BusinessActions ba = new BusinessActions(a, ds, Log, null); PromotionActions pa = new PromotionActions(a, ds, Log, null); Session.Transaction.Begin(); p = pa.SavePromotion(p); Assert.IsNotNull(p, "promotion should be saved succesfully"); Session.Transaction.Commit(); } IEnumerable<PromotionInstance> promoInstances; using (ISession Session = Scope.OpenSession()) { IRepository r = new GenericRepository(Session); var bds = new EntityDataService<Business, BusinessValidator>(r, new BusinessValidator()); var pds = new EntityDataService<Promotion, PromotionValidator>(r, new PromotionValidator()); var pids = new EntityDataService<PromotionInstance, PromotionInstanceValidator>(r, new PromotionInstanceValidator()); IDataService ds = new DataService(null, bds, pds, null, pids, null, null, null, null, new UnitOfWork(Session)); BusinessActions ba = new BusinessActions(a, ds, Log, null); PromotionActions pa = new PromotionActions(a, ds, Log, null); PromotionInstanceActions pia = new PromotionInstanceActions(a, ds, Log, null); Session.Transaction.Begin(); promoInstances = pia.CreatePromoInstance(p, new Account[] { i1, i2, i3 }, "going here"); Assert.IsNotNull(promoInstances, "promotion should be saved succesfully"); Assert.AreEqual(3, promoInstances.Count(), "we should get 2 promotion instance"); Session.Transaction.Commit(); } using (ISession Session = Scope.OpenSession()) { IRepository r = new GenericRepository(Session); var bds = new EntityDataService<Business, BusinessValidator>(r, new BusinessValidator()); var pds = new EntityDataService<Promotion, PromotionValidator>(r, new PromotionValidator()); var pids = new EntityDataService<PromotionInstance, PromotionInstanceValidator>(r, new PromotionInstanceValidator()); IDataService ds = new DataService(null, bds, pds, null, pids, null, null, null, null, new UnitOfWork(Session)); PromotionInstanceActions pia = new PromotionInstanceActions(i1, ds, Log, null); Session.Transaction.Begin(); var pia1 = pia.Accept(promoInstances.First(), "this sound like fun"); Assert.IsNotNull(pia1); Assert.AreEqual(StatusType.Accept, pia1.Status.StatusType); Assert.IsNotNull(pia1.Coupons, "Coupoin should not be null"); Assert.IsNotNull(pia1.Coupons.First().CouponCode, "Coupon code should be generated"); Session.Transaction.Commit(); } using (ISession Session = Scope.OpenSession()) { IRepository r = new GenericRepository(Session); var bds = new EntityDataService<Business, BusinessValidator>(r, new BusinessValidator()); var pds = new EntityDataService<Promotion, PromotionValidator>(r, new PromotionValidator()); var pids = new EntityDataService<PromotionInstance, PromotionInstanceValidator>(r, new PromotionInstanceValidator()); IDataService ds = new DataService(null, bds, pds, null, pids, null, null, null, null, new UnitOfWork(Session)); PromotionInstanceActions pia = new PromotionInstanceActions(i2, ds, Log, null); Session.Transaction.Begin(); var pia2 = pia.Decline(promoInstances.ElementAt(1), "this sound like fun"); Assert.IsNotNull(pia2); Assert.AreEqual(StatusType.Decline, pia2.Status.StatusType); Assert.IsNull(pia2.Coupons, "Coupoin should not be null"); Session.Transaction.Commit(); } } }