示例#1
0
 public AccountBase(IDataService dataService,
     EventActions eventActions,
     BusinessActions businessActions,
     PromotionActions promoActions,
     PromotionInstanceActions promoInstanceActions,
     ILogger log)
 {
     this.DataService = dataService;
     this.EventActions = eventActions;
     this.BusinessActions = businessActions;
     this.PromotionActions = promoActions;
     this.PromotionInstanceActions = promoInstanceActions;
     this.Log = log;
 }
        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();
                }
            }
        }
        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();
                }
            }
        }