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

            action(work, session);
        }
Exemplo n.º 2
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);
        }
 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);
 }
Exemplo n.º 4
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);
 }
        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);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
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();
        }
        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);
        }
        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();
        }
        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);
        }
Exemplo n.º 12
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);
        }
Exemplo n.º 14
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);
        }