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 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_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); }
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); }
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); }
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(); }
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(); }