private async Task RunPurgeUnrelatedItemsTest <T>(IPersistenceContext <T> context) where T : Attributed, new()
        {
            var item1 = CreateItem <T>();

            item1.DisasterId = "abc";
            var item2 = CreateItem <T>();

            item2.DisasterId = "def";
            var items = new List <T> {
                item1, item2
            };

            context.LoadAll().Returns(items);

            var disaster = new Disaster {
                ObjectId = "abc"
            };
            var result = new UpdateResult <Disaster>();

            result.Success(disaster, "xxx");
            _pullService.Pull <Disaster>().Returns(Task.FromResult(result));

            var syncResult = await _service.Sync(_user);

            Assert.That(syncResult.HasErrors, Is.False);
            context.Received().Purge(item2.ObjectId);
            context.DidNotReceive().Purge(item1.ObjectId);
        }
Ejemplo n.º 2
0
        public async Task Should_Clear_All_Non_New_Items_When_Pull_Is_Successful()
        {
            var existing = CreateTestModel();
            var newItem  = new TestModel();

            newItem.StampNewId();
            _persistenceContext.LoadAll().Returns(new[] { existing, newItem });

            var pulled = CreateTestModel();

            SetupSuccessfulPull(pulled);

            await _service.Pull <TestModel>();

            _persistenceContext.Received().Purge(existing.ObjectId);
            _persistenceContext.DidNotReceive().Purge(newItem.ObjectId);
        }
        public async Task Should_Update_Existing_Items()
        {
            var localAssessment = CreateSavedAssessment();
            var savedAssessment = SetupSuccessfulPut(localAssessment);

            _persistenceContext.LoadAll().Returns(new[] { localAssessment });

            var result = await _service.Push <Assessment>(UserToken);

            var items = result.SuccessfulItems.ToList();

            Assert.That(items.Count, Is.EqualTo(1));
            Assert.That(items.Contains(savedAssessment));
            Assert.That(result.FailedItems, Is.Empty);
            _persistenceContext.Received().Save(savedAssessment);
            _persistenceContext.DidNotReceive().Purge(localAssessment.ObjectId);
        }
Ejemplo n.º 4
0
        public async Task Should_Report_Failures()
        {
            var assessment1 = CreateAssessment();

            _persistenceContext.LoadDeletedObjects().Returns(new[] { assessment1 });
            var failedResponse = SetFailedDeletion(assessment1, "Error deleting object");

            var result = await _service.Push <Assessment>(UserToken);

            Assert.That(result.GetErrorMessage(assessment1), Is.EqualTo(failedResponse.ToString()));
            var items = result.FailedItems.ToList();

            Assert.That(items.Count, Is.EqualTo(1));
            Assert.That(items.Contains(assessment1));
            Assert.That(result.SuccessfulItems, Is.Empty);
            _persistenceContext.DidNotReceive().Purge(assessment1.ObjectId);
        }
        public async Task Should_Return_Failure_When_Pull_Is_Not_Successful()
        {
            var result = new UpdateResult <Disaster>();

            result.Success(new Disaster {
                ObjectId = "fff"
            }, "ccc");
            result.Failed(null, "test error");
            _assessmentContext.LoadAll().Returns(new[] { CreateItem <Assessment>() });
            _shelterContext.LoadAll().Returns(new[] { CreateItem <Shelter>() });
            _pullService.Pull <Disaster>().Returns(Task.FromResult(result));

            var syncResult = await _service.Sync(_user);

            Assert.That(syncResult.HasErrors);
            _assessmentContext.DidNotReceive().Purge(Arg.Any <string>());
            _shelterContext.DidNotReceive().Purge(Arg.Any <string>());
        }