static void Run(Action <RavenDbUnitOfWork, Mock <IDocumentSession> > action)
        {
            var session = Pleasure.Mock <IDocumentSession>();
            var work    = new RavenDbUnitOfWork(session.Object, IsolationLevel.ReadCommitted);

            action(work, session);
        }
 protected Context_inc_controller_base()
 {
     dispatcher           = Pleasure.Mock <IDispatcher>();
     httpContext          = Pleasure.Mock <HttpContextBase>();
     controller           = new FakeController(dispatcher.Object, httpContext.Object);
     modelStateDictionary = new ModelStateDictionary();
     controller.ViewData.SetValue("_modelState", modelStateDictionary);
 }
Beispiel #3
0
        static void Run(Action <EntityFrameworkUnitOfWork, Mock <DbContext> > action, bool isOpen = true)
        {
            var isolationLevel = IsolationLevel.ReadCommitted;
            var dbContext      = Pleasure.Mock <DbContext>();
            var unitOfWork     = new EntityFrameworkUnitOfWork(dbContext.Object, isolationLevel, true);

            action(unitOfWork, dbContext);
        }
Beispiel #4
0
        public static string TheUserId()
        {
            const string userid         = "userId";
            var          sessionContext = Pleasure.MockStrictAsObject <ISessionContext>(mock => mock.SetupGet(r => r.UserId).Returns(userid));

            IoCFactory.Instance.StubTryResolve(sessionContext);
            return(userid);
        }
Beispiel #5
0
 protected Context_inc_controller_base()
 {
     dispatcher  = Pleasure.Mock <IDispatcher>();
     httpContext = Pleasure.Mock <HttpContextBase>();
     IoCFactory.Instance.StubTryResolve(dispatcher.Object);
     controller           = new FakeController(httpContext.Object);
     modelStateDictionary = new ModelStateDictionary();
     controller.ViewData.SetValue("_modelState", modelStateDictionary);
 }
Beispiel #6
0
        static void Run(ActionPolicy policy, Action <Mock <ISpy> > verify)
        {
            var spy = Pleasure.Spy();

            spy.Setup(r => r.Is()).Throws <ArgumentException>();
            var exception = Catch.Exception(() => policy.Do(() => spy.Object.Is()));

            exception.ShouldNotBeNull();
            verify(spy);
        }
        public static IRepository Init(this IRepository repository)
        {
            foreach (var entity in repository.Query <DbEntity>())
            {
                repository.Delete(entity);
            }

            foreach (var entity in repository.Query <DbEntityByInt>())
            {
                repository.Delete(entity);
            }

            foreach (var entity in repository.Query <DbEntityAsGuid>())
            {
                repository.Delete(entity);
            }

            foreach (var entity in repository.Query <DbEntityReference>())
            {
                repository.Delete(entity);
            }

            foreach (var entity in repository.Query <DbEntityItem>())
            {
                repository.Delete(entity);
            }

            foreach (var entity in repository.Query <DbEntityQuery>())
            {
                repository.Delete(entity);
            }

            foreach (var entity in repository.Query <DbEntityReference>())
            {
                repository.Delete(entity);
            }

            foreach (var entity in repository.Query <DbEntityQueryAsItem>())
            {
                repository.Delete(entity);
            }

            repository.Flush();

            Pleasure.Do10((i) => repository.Save(Pleasure.Generator.Invent <DbEntityQuery>(dsl => dsl.GenerateTo(r => r.Reference)
                                                                                           .Callback(query =>
            {
                var item = Pleasure.Generator.Invent <DbEntityQueryAsItem>(factoryDsl => factoryDsl.Tuning(r => r.Parent, query));
                query.Items.Add(item);
            }))));
            repository.Flush();
            Pleasure.Sleep100Milliseconds(); // wait for apply data base.
            return(repository);
        }
        static void Run(Action <NhibernateUnitOfWork, Mock <ISession>, Mock <ITransaction> > action, bool isFlush = true)
        {
            var transaction = Pleasure.Mock <ITransaction>();

            var session = Pleasure.Mock <ISession>(mock => mock.Setup(r => r.BeginTransaction(IsolationLevel.RepeatableRead)).Returns(transaction.Object));

            var nhibernateUnit = new NhibernateUnitOfWork(session.Object, IsolationLevel.RepeatableRead, isFlush);

            session.Verify(r => r.BeginTransaction(IsolationLevel.RepeatableRead), Times.Once());
            action(nhibernateUnit, session, transaction);
        }
Beispiel #9
0
        static void Run(Action <RavenDbUnitOfWork, Mock <IDocumentSession> > action, bool isOpen = true)
        {
            var session        = Pleasure.Mock <IDocumentSession>();
            var sessionFactory = Pleasure.MockAsObject <IRavenDbSessionFactory>(mock => mock.Setup(r => r.Open(Pleasure.MockIt.IsNotNull <string>())).Returns(session.Object));
            var work           = new RavenDbUnitOfWork(sessionFactory, Pleasure.Generator.String(), IsolationLevel.ReadCommitted);

            if (isOpen)
            {
                work.Open();
            }
            action(work, session);
        }
 public HttpResponseMessage GetAllPleasures()
 {
     try
     {
         Pleasure        p     = new Pleasure();
         List <Pleasure> PList = p.Read();
         return(Request.CreateResponse(HttpStatusCode.OK, PList));
     }
     catch (Exception e)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, e));
     }
 }
Beispiel #11
0
        protected Context_default_dispatcher()
        {
            unitOfWorkFactory = Pleasure.MockStrict <IUnitOfWorkFactory>(unitOfWorkFactoryMock =>
            {
                unitOfWork = Pleasure.Mock <IUnitOfWork>(mock => mock.Setup(r => r.GetRepository()).Returns(Pleasure.MockAsObject <IRepository>()));
                unitOfWorkFactoryMock.Setup(r => r.Create(IsolationLevel.ReadCommitted, true, Pleasure.MockIt.IsNull <string>())).Returns(unitOfWork.Object);
                unitOfWorkFactoryMock.Setup(r => r.Create(IsolationLevel.ReadUncommitted, false, Pleasure.MockIt.IsNull <string>())).Returns(unitOfWork.Object);
            });
            IoCFactory.Instance.StubTryResolve(unitOfWorkFactory.Object);


            dispatcher = new DefaultDispatcher();
        }
        public Behavior_default_dispatcher_push_with_connection_string()
        {
            unitOfWorkFactory = Pleasure.Mock <IUnitOfWorkFactory>(unitOfWorkFactoryMock =>
            {
                unitOfWork = new Mock <IUnitOfWork>();
                unitOfWorkFactoryMock.Setup(r => r.Create(IsolationLevel.ReadCommitted, Pleasure.MockIt.IsAny <string>()))
                .Returns(unitOfWork.Object);
            });

            IoCFactory.Instance.StubTryResolve(unitOfWorkFactory.Object);
            IoCFactory.Instance.StubTryResolve(Pleasure.MockAsObject <IEventBroker>());

            dispatcher = new DefaultDispatcher();
        }
        static void Run(Action <EntityFrameworkUnitOfWork, Mock <DbContext> > action, bool isOpen = true)
        {
            var    dbContext        = Pleasure.Mock <DbContext>();
            string connectionString = ConfigurationManager.ConnectionStrings["IncRealEFDb"].ConnectionString;
            var    sessionFactory   = Pleasure.MockStrictAsObject <IEntityFrameworkSessionFactory>(mock => mock.Setup(r => r.Open(connectionString)).Returns(dbContext.Object));
            var    unitOfWork       = new EntityFrameworkUnitOfWork(sessionFactory, IsolationLevel.ReadCommitted, connectionString);

            if (isOpen)
            {
                unitOfWork.Open();
            }

            action(unitOfWork, dbContext);
        }
        protected Context_default_dispatcher()
        {
            unitOfWorkFactory = Pleasure.MockStrict <IUnitOfWorkFactory>(unitOfWorkFactoryMock =>
            {
                unitOfWork = new Mock <IUnitOfWork>();
                unitOfWorkFactoryMock.Setup(r => r.Create(IsolationLevel.ReadCommitted, Pleasure.MockIt.IsNull <string>())).Returns(unitOfWork.Object);
                unitOfWorkFactoryMock.Setup(r => r.Create(IsolationLevel.ReadUncommitted, Pleasure.MockIt.IsNull <string>())).Returns(unitOfWork.Object);
            });
            IoCFactory.Instance.StubTryResolve(unitOfWorkFactory.Object);

            eventBroker = Pleasure.Mock <IEventBroker>();
            IoCFactory.Instance.StubTryResolve(eventBroker.Object);

            dispatcher = new DefaultDispatcher();
        }
        protected Context_nhibernate_unit_of_work()
        {
            session = Pleasure.Mock <ISession>();

            var sessionFactoryImplementor = Pleasure.MockAsObject <ISessionFactoryImplementor>(mock => mock
                                                                                               .SetupGet(r => r.CurrentSessionContext)
                                                                                               .Returns(Pleasure.MockAsObject <CurrentSessionContext>()));

            session
            .Setup(r => r.SessionFactory)
            .Returns(sessionFactoryImplementor);

            const IsolationLevel isolationLevel = IsolationLevel.ReadCommitted;

            transaction = Pleasure.Mock <ITransaction>();
            session
            .Setup(r => r.BeginTransaction(isolationLevel))
            .Returns(transaction.Object);

            nhibernateUnit = new NhibernateUnitOfWork(session.Object, isolationLevel);
        }
Beispiel #16
0
        static Context_dispatcher_controller()
        {
            dispatcher = Pleasure.Mock <IDispatcher>();

            IoCFactory.Instance.StubTryResolve(dispatcher.Object);
            controller = new FakeDispatcher();

            requestBase = Pleasure.Mock <HttpRequestBase>(mock =>
            {
                mock.SetupGet(r => r.Headers).Returns(new NameValueCollection {
                    { "X-Requested-With", "XMLHttpRequest" }
                });
            });

            responseBase = Pleasure.MockStrict <HttpResponseBase>();
            controller.ControllerContext = new ControllerContext(Pleasure.MockStrictAsObject <HttpContextBase>(mock =>
            {
                mock.SetupGet(r => r.Request).Returns(requestBase.Object);
                mock.SetupGet(r => r.Response).Returns(responseBase.Object);
            }), new RouteData(), controller);
            controller.ValueProvider = Pleasure.MockStrictAsObject <IValueProvider>(mock => mock.Setup(r => r.GetValue(Pleasure.MockIt.IsAny <string>())).Returns(new ValueProviderResult(string.Empty, string.Empty, Thread.CurrentThread.CurrentCulture)));
        }
        protected static void Establish(Type[] types = null, bool isAjax = true)
        {
            typeof(DispatcherControllerBase).GetField("types", BindingFlags.Static | BindingFlags.NonPublic).SetValue(null, new List <Type>());

            dispatcher = Pleasure.Mock <IDispatcher>();
            IoCFactory.Instance.StubTryResolve(dispatcher.Object);
            controller = new FakeDispatcher();

            var requestBase = Pleasure.MockAsObject <HttpRequestBase>(mock =>
            {
                if (isAjax)
                {
                    mock.SetupGet(r => r.Headers).Returns(new NameValueCollection {
                        { "X-Requested-With", "XMLHttpRequest" }
                    });
                }

                mock.SetupGet(r => r.Form).Returns(new NameValueCollection()
                {
                    { "[0].Name", "Value" },
                    { "[1].Name", "Value" },
                });
            });

            controller.ControllerContext = new ControllerContext(Pleasure.MockStrictAsObject <HttpContextBase>(mock => mock.SetupGet(r => r.Request).Returns(requestBase)), new RouteData(), controller);
            controller.ValueProvider     = Pleasure.MockStrictAsObject <IValueProvider>(mock => mock.Setup(r => r.GetValue(Pleasure.MockIt.IsAny <string>())).Returns(new ValueProviderResult(string.Empty, string.Empty, Thread.CurrentThread.CurrentCulture)));

            var modelBinderDictionary = new ModelBinderDictionary();
            var modelBinder           = Pleasure.MockAsObject <IModelBinder>(mock => mock.Setup(r => r.BindModel(Pleasure.MockIt.IsAny <ControllerContext>(),
                                                                                                                 Pleasure.MockIt.IsAny <ModelBindingContext>())));

            foreach (var type in types.Recovery(new Type[] { }))
            {
                modelBinderDictionary.Add(type, modelBinder);
            }
            controller.SetValue("Binders", modelBinderDictionary);
        }
        public List <Pleasure> GetPlistByUser(string email)
        {
            SqlConnection   con       = null;
            List <Pleasure> userPList = new List <Pleasure>();

            try
            {
                con = connect("DBConnectionString");

                String     selectSTR = "SELECT * FROM student_pleasure_P INNER JOIN pleasure_P ON pleasurepCode = pCode where studentmail = '" + email + "'";
                SqlCommand cmd       = new SqlCommand(selectSTR, con);

                SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);

                while (dr.Read())
                {
                    Pleasure p = new Pleasure();
                    p.Pcode = Convert.ToInt32(dr["pCode"]);
                    p.Pname = (string)(dr["pName"]);
                    p.Picon = (string)(dr["pIcon"]);
                    userPList.Add(p);
                }
                return(userPList);
            }
            catch (Exception ex)
            {
                writeToLog(ex);
                throw (ex);
            }
            finally
            {
                if (con != null)
                {
                    con.Close();
                }
            }
        }
        public List <Pleasure> GetAllPleasures()
        {
            SqlConnection   con   = null;
            List <Pleasure> PList = new List <Pleasure>();

            try
            {
                con = connect("DBConnectionString");

                String     selectSTR = "SELECT * FROM pleasure_P";
                SqlCommand cmd       = new SqlCommand(selectSTR, con);

                SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);

                while (dr.Read())
                {
                    Pleasure p = new Pleasure();
                    p.Pcode = Convert.ToInt32(dr["pCode"]);
                    p.Pname = (string)(dr["pName"]);
                    p.Picon = (string)(dr["pIcon"]);
                    PList.Add(p);
                }
                return(PList);
            }
            catch (Exception ex)
            {
                throw (ex);
            }

            finally
            {
                if (con != null)
                {
                    con.Close();
                }
            }
        }
Beispiel #20
0
        static void Run(Action <NhibernateUnitOfWork, Mock <ISession>, Mock <ITransaction> > action, bool isOpen = true, bool isDispose = false)
        {
            var transaction = Pleasure.Mock <ITransaction>();

            string dbConnection = Pleasure.Generator.Invent <SqlConnection>().ConnectionString;
            var    session      = Pleasure.Mock <ISession>(mock =>
            {
                mock.Setup(r => r.SessionFactory).Returns(Pleasure.MockAsObject <ISessionFactoryImplementor>(r => r.SetupGet(implementor => implementor.CurrentSessionContext)
                                                                                                             .Returns(Pleasure.MockAsObject <CurrentSessionContext>())));
                mock.Setup(r => r.BeginTransaction(IsolationLevel.RepeatableRead)).Returns(transaction.Object);
            });

            var nhibernateUnit = new NhibernateUnitOfWork(Pleasure.MockStrictAsObject <INhibernateSessionFactory>(mock =>
            {
                mock.Setup(r => r.Open(dbConnection)).Returns(session.Object);
            }), dbConnection, IsolationLevel.RepeatableRead);

            if (isOpen)
            {
                nhibernateUnit.Open();
            }

            action(nhibernateUnit, session, transaction);
        }
Beispiel #21
0
        public bool FillOutForm(string Year, string Make, string Model, string BodyType, FinanceType FinanceType, Use Use)
        {
            dayStrings = new List <string>();
            bool driverInfoPageExist;

            SelectElement sltYear = driver.FindSelectElementWhenPopulated(By.Id("vehicleYear"), 30);

            sltYear.SelectByText(Year);

            SelectElement sltMake = driver.FindSelectElementWhenPopulated(By.Id("vehicleMake"), 30);

            sltMake.SelectByText(Make);

            SelectElement sltModel = driver.FindSelectElementWhenPopulated(By.Id("vehicleModel"), 30);

            sltModel.SelectByText(Model);

            try
            {
                SelectElement sltBody = driver.FindSelectElementWhenPopulated(By.Id("bodyStyles"), 30);
                sltBody.SelectByText(BodyType);
            }
            catch (Exception) {}


            System.Threading.Thread.Sleep(500);


            switch (FinanceType)
            {
            case FinanceType.Owned:
                owned.Click();
                break;

            case FinanceType.Financed:
                financed.Click();
                break;

            case FinanceType.Leased:
                Leased.Click();
                break;

            default:
                break;
            }

            SelectElement annualMileageSlt;
            SelectElement daysDrivenSlt;
            SelectElement businessUseSlt;


            switch (Use)
            {
            case Use.Commute:
                Commute.Click();
                //System.Threading.Thread.Sleep(3000);

                daysDrivenSlt = driver.FindSelectElementWhenPopulated(By.Id("daysDriven"), 30);
                IList <IWebElement> days; days = daysDrivenSlt.Options;
                foreach (var day in days)
                {
                    dayStrings.Add(day.GetAttribute("value").ToString());
                }



                daysDrivenSlt.SelectByValue("5");
                milesDriven.SendKeys("15");

                annualMileageSlt = driver.FindSelectElementWhenPopulated(By.Id("annualMileage"), 30);
                annualMileageSlt.SelectByText("12,001 - 15,000");



                break;

            case Use.Pleasure:
                Pleasure.Click();


                annualMileageSlt = driver.FindSelectElementWhenPopulated(By.Id("annualMileage"), 30);

                IList <IWebElement> miles = annualMileageSlt.Options;
                annualMileageSlt.SelectByText("12,001 - 15,000");
                break;

            case Use.Business:
                Business.Click();

                businessUseSlt = driver.FindSelectElementWhenPopulated(By.Id("typeOfBusinessUse"), 30);
                businessUseSlt.SelectByText("Clergy");
                annualMileageSlt = driver.FindSelectElementWhenPopulated(By.Id("annualMileage"), 30);
                annualMileageSlt.SelectByText("12,001 - 15,000");
                break;

            default:
                break;
            }


            Submit.Click();


            try
            {
                wait.Until(ExpectedConditions.ElementExists(By.Id("maritalStatus")));
                driverInfoPageExist = true;
            }
            catch (Exception e)
            {
                driverInfoPageExist = false;
            }

            //IWebElement radioBtnOwnership = this.RbOwned;
            //IJavaScriptExecutor executor = (IJavaScriptExecutor)driver;
            //executor.ExecuteScript("arguments[0].click();", radioBtnOwnership);

            return(driverInfoPageExist);
        }
Beispiel #22
0
 public override void Execute()
 {
     Pleasure.Do10(i => this.EventBroker.Publish(new FakeEvent()));
 }
 public void Subscribe(FakeEventAsyncSleep @event)
 {
     Pleasure.SleepMilliseconds(200);
     SetAfterThreadSleep = true;
 }
Beispiel #24
0
 protected static void Establish()
 {
     provider = Pleasure.MockStrict <IIoCProvider>(mock => mock.Setup(r => r.TryGet <IRepository>()).Returns(Pleasure.MockAsObject <IRepository>()));
     IoCFactory.Instance.Initialize(init => init.WithProvider(provider.Object));
     message = new FakeMessage();
 }
 protected override void Execute()
 {
     Pleasure.Do10(i => Repository.Delete <FakeEntityForNew>(i));
 }
Beispiel #26
0
 public override void Execute()
 {
     Pleasure.Do10(i => this.Repository.Delete <FakeEntityForNew>(i));
 }