Esempio n. 1
0
        public async Task Should_Purge_Other_Users_Items()
        {
            SetupEmptyPush();
            var assessmentContext          = _persistenceContextFactory.CreateFor <Assessment>();
            var attr1                      = CreateItem <AssessmentAttribute>();
            var attr2                      = CreateItem <AssessmentAttribute>();
            var assessmentAttributeContext = _persistenceContextFactory.CreateFor <AssessmentAttribute>();
            var assessments                = await SetupPurgeTest(assessmentContext, attr1, attr2, assessmentAttributeContext);

            assessmentAttributeContext.Received().Purge(attr1.ObjectId);
            assessmentContext.Received().Purge(assessments[0].ObjectId);

            assessmentAttributeContext.DidNotReceive().Purge(attr2.ObjectId);
            assessmentContext.DidNotReceive().Purge(assessments[1].ObjectId);
        }
        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);
        }
Esempio n. 3
0
        private void RecordLastSync()
        {
            var currentTime = GetCurrentTimeFunc();
            var syncInfo    = new SyncInfo {
                ObjectId = "x", LastSync = currentTime
            };
            var context = _persistenceContextFactory.CreateFor <SyncInfo>();

            context.Save(syncInfo);
        }
Esempio n. 4
0
        private void PurgeRelated <T>(HashSet <string> disasterIds) where T : Attributed
        {
            var context = _persistenceContextFactory.CreateFor <T>();
            var items   = context.LoadAll()
                          .Where(k => !disasterIds.Contains(k.DisasterId))
                          .ToList();

            foreach (var item in items)
            {
                context.Purge(item.ObjectId);
            }
        }
        public async Task Should_Record_Last_Sync_When_Successful()
        {
            _service1.Sync(_user).Returns(Task.FromResult(SyncResult.Success()));
            _service2.Sync(_user).Returns(Task.FromResult(SyncResult.Success()));
            var currentTime = DateTimeOffset.UtcNow;

            _syncService.GetCurrentTimeFunc = () => currentTime;

            await _syncService.Sync(_user);

            _persistenceContextFactory.CreateFor <SyncInfo>().Received().Save(Arg.Is <SyncInfo>(s => s.LastSync == currentTime && s.ObjectId == "x"));
        }
        private void RemoveOtherUsersItems(User user)
        {
            var itemContext   = _persistenceContextFactory.CreateFor <TItem>();
            var existingItems = itemContext.LoadAll()
                                .Where(a => !a.IsNew() && !user.ObjectId.Equals(a.OwnerId, StringComparison.CurrentCultureIgnoreCase));

            var attributeContext   = _persistenceContextFactory.CreateFor <TValuedAttribute>();
            var existingAttributes = attributeContext.LoadAll()
                                     .GroupBy(a => a.ItemId)
                                     .ToDictionary(g => g.Key, g => g.ToList());

            foreach (var existingItem in existingItems)
            {
                List <TValuedAttribute> attributes;
                if (existingAttributes.TryGetValue(existingItem.ObjectId, out attributes))
                {
                    foreach (var attribute in attributes)
                    {
                        attributeContext.Purge(attribute.ObjectId);
                    }
                }
                itemContext.Purge(existingItem.ObjectId);
            }
        }
Esempio n. 7
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();
        }
        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);
        }
Esempio n. 9
0
        public Task <IEnumerable <DisasterAid> > GetDisasterAids(string disasterId)
        {
            var context = _persistenceContextFactory.CreateFor <DisasterAid>();

            return(Asyncer.Async(() => context.LoadAll().Where(d => d.DisasterId == disasterId)));
        }