Пример #1
0
        public void ShouldAddItemToTarget()
        {
            var testSource = new InMemoryDataEndpoint<TestResource>(r => r.Id);
            var testTarget = new InMemoryDataEndpoint<TestResource>(r => r.Id);
            var testResource = new TestResource(1) { Description = "Test" };
            testSource.Create(testResource);
            testTarget.AddSyncAction((e,r) => e.Get(e.IdentityResolver(r)) == null, (e, r) => e.Create(r), "Create");
            var testChannel = new SynchronizationChannel<TestResource>(testSource, testTarget, true);
            
            testChannel.Open();

            Assert.IsNotNull(testTarget.Get(1));
        }
Пример #2
0
        public void ShouldDeleteItemFromTarget()
        {
            var testSource = new InMemoryDataEndpoint<TestResource>(r => r.Id);
            var testTarget = new BatchListCleanupEndpointDecorator<TestResource>(
                new InMemoryDataEndpoint<TestResource>(r => r.Id));
            var testResource = new TestResource(1) { Description = "Test" };
            testTarget.Create(testResource);
            testTarget.AddSyncAction((e, r) => e.Get(e.IdentityResolver(r)) == null, (e, r) => e.Create(r), "Create");
            var testChannel = new SynchronizationChannel<TestResource>(testSource, testTarget, true);
            testChannel.Opening += (s, e) => testTarget.Initialize();
            testChannel.Closing += (s, e) => testTarget.Finish();

            testChannel.Open();

            Assert.IsNull(testTarget.Get(1));
            Assert.IsFalse(testChannel.IsOpen);
        }
Пример #3
0
        public void SetUpTest()
        {
            _testSource = new InMemoryDataEndpoint<TestResource>(t => t.Id);
            _testSource.ResourceDeleted.Subscribe(t => t.Deleted = true);
            _testTarget = new InMemoryDataEndpoint<TestResource>(t => t.Id);
            _testTarget.AddSyncAction(t => t.Deleted, (ds, t) => ds.Delete(t), "Delete");
            _testTarget.AddSyncAction(t => string.IsNullOrEmpty(t.CorrelationId), 
                (ds, r) => ds.Create(r), "Create");
            
            _testTarget.AddSyncAction(
                t => !string.IsNullOrEmpty(t.CorrelationId), (ds, r) =>
                {
                    var resourceToUpdate = ds.Get(r.Id);
                    if (resourceToUpdate != null)
                    {
                        resourceToUpdate.Update(r);
                        ds.Update(resourceToUpdate);
                    }
                }, "Update");

            _testChannel = new SynchronizationChannel<TestResource>(_testSource, _testTarget);
        }