Ejemplo n.º 1
0
 public PersistenceScopeImpl(IPersistenceContextFactory persistenceContextFactory) :
     this(persistenceContextFactory,
          PersistenceUnitOfWorkOption.JoinExisting,
          readOnly : false,
          isolationLevel : null)
 {
 }
        public AssemblyTypeRepository(IPersistenceContextFactory contextFactory)
        {
            //Contract.Requires<ArgumentNullException>(contextFactory == null);
            if (contextFactory == null)
                throw new ArgumentNullException("contextFactory");

            this.contextFactory = contextFactory;
        }
 public AttributedItemSyncService(IPushService pushService, IPullService pullService,
                                  IBackendlessQueryProvider queryProvider, IPersistenceContextFactory persistenceContextFactory)
 {
     _pushService               = pushService;
     _pullService               = pullService;
     _queryProvider             = queryProvider;
     _persistenceContextFactory = persistenceContextFactory;
 }
Ejemplo n.º 4
0
        public TenantRepository(IPersistenceContextFactory contextFactory)
        {
            //Contract.Requires<ArgumentNullException>(contextFactory == null);
            if (contextFactory == null)
            {
                throw new ArgumentNullException("contextFactory");
            }

            this.contextFactory = contextFactory;
        }
Ejemplo n.º 5
0
        public void Setup()
        {
            _user = new User {
                ObjectId = Guid.NewGuid().ToString()
            };
            _service1 = Substitute.For <ISyncService>();
            _service2 = Substitute.For <ISyncService>();
            _persistenceContextFactory = Substitute.For <IPersistenceContextFactory>();

            _syncService = new SyncService(_persistenceContextFactory, new [] { _service1, _service2 });
        }
Ejemplo n.º 6
0
            public PersistenceScopeImpl(
                IPersistenceContextFactory persistenceContextFactory,
                PersistenceUnitOfWorkOption joiningOption,
                bool readOnly,
                IsolationLevel?isolationLevel)
            {
                _persistenceContextFactory = persistenceContextFactory;
                if (isolationLevel.HasValue &&
                    joiningOption == PersistenceUnitOfWorkOption.JoinExisting)
                {
                    throw new ArgumentException(
                              @"Cannot join an ambient persistence scope when an explicit database transaction is required. 
When requiring explicit database transactions to be used (i.e. when the 'isolationLevel' parameter is set), 
you must not also ask to join the ambient scope (i.e. the 'joinAmbient' parameter must be set to false).");
                }

                _disposed    = false;
                _completed   = false;
                _readOnly    = readOnly;
                _parentScope = GetAmbientScope();

                if (_parentScope != null && joiningOption == PersistenceUnitOfWorkOption.JoinExisting)
                {
                    if (_parentScope._readOnly && !this._readOnly)
                    {
                        throw new InvalidOperationException("Cannot nest a read/write Scope within a read-only Scope.");
                    }
                    _nested             = true;
                    _persistenceContext = _parentScope._persistenceContext;

                    if (_persistenceContext as IPersistenceContextExplicit == null)
                    {
                        throw new InvalidProgramException($"Parent PersistenceContext does not implement {typeof(IPersistenceContextExplicit).Name}");
                    }
                }
                else
                {
                    _nested             = false;
                    _persistenceContext = _persistenceContextFactory.Create();

                    var explicitContext = _persistenceContext as IPersistenceContextExplicit;
                    if (explicitContext == null)
                    {
                        throw new InvalidProgramException($"PersistenceContext does not implement {typeof(IPersistenceContextExplicit).Name}");
                    }

                    if (isolationLevel.HasValue)
                    {
                        _persistenceTransaction = explicitContext.BeginTransaction(isolationLevel.Value);
                    }
                }
                SetAmbientScope(this);
            }
        public void Setup()
        {
            _user        = new User();
            _pullService = Substitute.For <IPullService>();
            _persistenceContextFactory = Substitute.For <IPersistenceContextFactory>();
            _assessmentContext         = Substitute.For <IPersistenceContext <Assessment> >();
            _shelterContext            = Substitute.For <IPersistenceContext <Shelter> >();

            _assessments = new List <Assessment>();
            _assessmentContext.LoadAll().Returns(_assessments);
            _shelters = new List <Shelter>();
            _shelterContext.LoadAll().Returns(_shelters);

            _persistenceContextFactory.CreateFor <Assessment>().Returns(_assessmentContext);
            _persistenceContextFactory.CreateFor <Shelter>().Returns(_shelterContext);

            _service = new DisasterSyncService(_pullService, _persistenceContextFactory);
        }
Ejemplo n.º 8
0
        public override void CreateTestableObject()
        {
            _jsonSerializer            = Substitute.For <IJsonSerializer>();
            _persistenceContextFactory = Substitute.For <IPersistenceContextFactory>();
            _persistenceContext        = Substitute.For <IPersistenceContext <Assessment> >();
            _responseParser            = Substitute.For <IBackendlessResponseParser>();
            _restServiceCaller         = Substitute.For <IRestServiceCaller>();

            _persistenceContextFactory.CreateFor <Assessment>().Returns(_persistenceContext);

            Ioc.RegisterSingleton(_jsonSerializer);
            Ioc.RegisterSingleton(_persistenceContextFactory);
            Ioc.RegisterSingleton(_responseParser);
            Ioc.RegisterSingleton(_restServiceCaller);
            Ioc.RegisterSingleton(_connection);

            _service = new RemovalPushService();
        }
Ejemplo n.º 9
0
        public override void CreateTestableObject()
        {
            _service    = new PullService();
            _connection = new Connection {
                AppId = "foo", SecretKey = "bar"
            };

            _restServiceCaller         = Substitute.For <IRestServiceCaller>();
            _responseParser            = Substitute.For <IBackendlessResponseParser>();
            _persistenceContextFactory = Substitute.For <IPersistenceContextFactory>();
            _persistenceContext        = Substitute.For <IPersistenceContext <TestModel> >();
            _persistenceContextFactory.CreateFor <TestModel>().Returns(_persistenceContext);

            _restServiceCaller.Get(Connection.GenerateTableUrl <TestModel>(), _connection.Headers).Returns(Task.FromResult(Json));

            Ioc.RegisterSingleton(_connection);
            Ioc.RegisterSingleton(_restServiceCaller);
            Ioc.RegisterSingleton(_persistenceContextFactory);
            Ioc.RegisterSingleton(_responseParser);
        }
Ejemplo n.º 10
0
        public void Setup()
        {
            _pushService = Substitute.For <IPushService>();
            _pullService = Substitute.For <IPullService>();
            _persistenceContextFactory = Substitute.For <IPersistenceContextFactory>();

            _queryProvider = Substitute.For <IBackendlessQueryProvider>();
            _query         = Substitute.For <IBackendlessQuery>();
            _queryProvider.Where().Returns(_query);
            _pullService.Pull <Assessment>().ReturnsForAnyArgs(Task.FromResult(new UpdateResult <Assessment>()));
            _pullService.Pull <AssessmentAttribute>().ReturnsForAnyArgs(Task.FromResult(new UpdateResult <AssessmentAttribute>()));

            _user = new User {
                Token = "blah", ObjectId = "xyz"
            };
            _query.OwnedBy(_user.ObjectId).IsActive().Returns(_query);

            _syncService = new AttributedItemSyncService <Assessment, AssessmentAttribute>(_pushService, _pullService,
                                                                                           _queryProvider, _persistenceContextFactory);
        }
Ejemplo n.º 11
0
 public Tap2GiveService(ITap2HelpService service, IPullService pullService, IPersistenceContextFactory persistenceContextFactory)
 {
     _service     = service;
     _pullService = pullService;
     _persistenceContextFactory = persistenceContextFactory;
 }
Ejemplo n.º 12
0
 public SyncService(IPersistenceContextFactory persistenceContextFactory, IEnumerable <ISyncService> syncServices)
 {
     _persistenceContextFactory = persistenceContextFactory;
     _syncServices = syncServices.ToList();
 }
Ejemplo n.º 13
0
 public DisasterSyncService(IPullService pullService, IPersistenceContextFactory persistenceContextFactory)
 {
     _pullService = pullService;
     _persistenceContextFactory = persistenceContextFactory;
 }
Ejemplo n.º 14
0
 public PersistenceUnitOfWorkFactory(IPersistenceContextFactory persistenceContextFactory)
 {
     _persistenceContextFactory = persistenceContextFactory;
 }