public async Task RemoteWithWorkSpaceAutoTest()
        {
            var repo  = new ControlledRepository <NumberWorkSpace>();
            var repo2 = new ControlledRepository <NumberWorkSpace>();

            var remote = new ObjectRemoteWithWorkSpace <NumberWorkSpace>(repo2, true, true);
            await remote.AttachAsync(repo);

            var workspacePointer = repo.WorkSpace;

            Assert.AreEqual(0, remote.RemoteWorkSpace.NumberStore);
            Assert.AreEqual(0, repo.WorkSpace.NumberStore);
            Assert.AreEqual(0, repo2.WorkSpace.NumberStore);

            repo.ApplyChange(new AddModification(5));
            repo.ApplyChange(new AddModification(50));

            await Task.Delay(10);

            var workspacePointerNew = repo.WorkSpace;

            Assert.AreEqual(55, remote.RemoteWorkSpace.NumberStore);
            Assert.AreEqual(55, repo.WorkSpace.NumberStore);
            Assert.AreEqual(55, repo2.WorkSpace.NumberStore);
            Assert.AreEqual(workspacePointer, workspacePointerNew);
        }
        public async Task ObserveTheChange()
        {
            var repo         = new ControlledRepository <NumberWorkSpace>();
            var happendTimes = 0;

            repo.PropertyChanged += (_, e) =>
            {
                if (e.PropertyName == nameof(repo.WorkSpace))
                {
                    happendTimes++;
                }
            };

            Assert.AreEqual(0, happendTimes);
            repo.ApplyChange(new AddModification(5));
            Assert.AreEqual(1, happendTimes);

            var repo2 = new ControlledRepository <NumberWorkSpace>();

            repo.ApplyChange(new AddModification(5000));
            var remote = new ObjectRemoteWithWorkSpace <NumberWorkSpace>(repo2);
            await remote.AttachAsync(repo);

            await remote.PullAsync();

            Assert.AreEqual(2, happendTimes);
        }
Exemplo n.º 3
0
        public async Task TestMerge()
        {
            var repo = new CollectionRepository <Book>();

            repo.Add(new Book {
                Id = 0, Title = "Book first."
            });
            repo.Add(new Book {
                Id = 0, Title = "Book first."
            });
            repo.Add(new Book {
                Id = 0, Title = "Book first."
            });

            var repoB = new CollectionRepository <Book>();

            repoB.Add(new Book {
                Id = 0, Title = "Book second."
            });
            repoB.Add(new Book {
                Id = 0, Title = "Book second."
            });
            repoB.Add(new Book {
                Id = 0, Title = "Book second."
            });

            var remote = new ObjectRemoteWithWorkSpace <CollectionWorkSpace <Book> >(repo, true, true);
            await remote.AttachAsync(repoB);

            Assert.AreEqual(6, repo.WorkSpace.Count());
            Assert.AreEqual(6, repoB.WorkSpace.Count());
            Assert.AreEqual("Book first.", string.Join(' ', repo.WorkSpace[0].Title));
            Assert.AreEqual("Book second.", string.Join(' ', repoB.WorkSpace[3].Title));

            await Task.Delay(50);

            Assert.AreEqual(6, repo.WorkSpace.Count());
            Assert.AreEqual(6, repoB.WorkSpace.Count());
            Assert.AreEqual("Book first.", string.Join(' ', repo.WorkSpace[0].Title));
            Assert.AreEqual("Book second.", string.Join(' ', repoB.WorkSpace[3].Title));
        }
Exemplo n.º 4
0
        public async Task TestMerge(int _)
        {
            var repo = new TextRepository();

            repo.UpdateText(new[] { "a", "a", "a" });
            Assert.AreEqual("a a a", string.Join(' ', repo.WorkSpace.List));

            var repoB = new TextRepository();

            repoB.UpdateText(new[] { "b", "b", "b" });
            Assert.AreEqual("b b b", string.Join(' ', repoB.WorkSpace.List));

            var remote = new ObjectRemoteWithWorkSpace <CollectionWorkSpace <string> >(repo, true, true);
            await remote.AttachAsync(repoB);

            Assert.AreEqual("b b b a a a", string.Join(' ', repo.WorkSpace.List));
            Assert.AreEqual("b b b a a a", string.Join(' ', repoB.WorkSpace.List));

            await Task.Delay(50);

            Assert.AreEqual("b b b a a a", string.Join(' ', repo.WorkSpace.List));
            Assert.AreEqual("b b b a a a", string.Join(' ', repoB.WorkSpace.List));
        }
        public async Task RemoteWithWorkSpaceTest()
        {
            var repo = new ControlledRepository <NumberWorkSpace>();

            repo.ApplyChange(new AddModification(5));
            repo.ApplyChange(new AddModification(50));

            var repo2  = new ControlledRepository <NumberWorkSpace>();
            var remote = new ObjectRemoteWithWorkSpace <NumberWorkSpace>(repo2);
            await remote.AttachAsync(repo);

            await remote.PushAsync();

            Assert.AreEqual(55, repo.WorkSpace.NumberStore);
            Assert.AreEqual(55, repo2.WorkSpace.NumberStore);
            Assert.AreEqual(0, remote.RemoteWorkSpace.NumberStore);

            await remote.PullAsync();

            Assert.AreEqual(55, repo.WorkSpace.NumberStore);
            Assert.AreEqual(55, repo2.WorkSpace.NumberStore);
            Assert.AreEqual(55, remote.RemoteWorkSpace.NumberStore);
        }
        public async Task RemoteWithMergeWorkSpaceTest(bool commitBefore)
        {
            var repo   = new ControlledRepository <NumberWorkSpace>();
            var repo2  = new ControlledRepository <NumberWorkSpace>();
            var remote = new ObjectRemoteWithWorkSpace <NumberWorkSpace>(repo2);
            await remote.AttachAsync(repo);

            Assert.AreEqual(0, remote.RemoteWorkSpace.NumberStore);
            Assert.AreEqual(0, repo.WorkSpace.NumberStore);
            Assert.AreEqual(0, repo2.WorkSpace.NumberStore);

            repo.ApplyChange(new AddModification(5));
            repo.ApplyChange(new AddModification(50));

            Assert.AreEqual(0, remote.RemoteWorkSpace.NumberStore);
            Assert.AreEqual(55, repo.WorkSpace.NumberStore); // 5, 50
            Assert.AreEqual(0, repo2.WorkSpace.NumberStore); // 0

            await remote.PushAsync();

            Assert.AreEqual(0, remote.RemoteWorkSpace.NumberStore);
            Assert.AreEqual(55, repo.WorkSpace.NumberStore);  // 5, 50
            Assert.AreEqual(55, repo2.WorkSpace.NumberStore); // 5, 50

            await remote.PullAsync();

            Assert.AreEqual(55, remote.RemoteWorkSpace.NumberStore);
            Assert.AreEqual(55, repo.WorkSpace.NumberStore);  // 5, 50
            Assert.AreEqual(55, repo2.WorkSpace.NumberStore); // 5, 50

            repo.ApplyChange(new AddModification(100));
            Assert.AreEqual(55, remote.RemoteWorkSpace.NumberStore);
            Assert.AreEqual(155, repo.WorkSpace.NumberStore); // 5, 50, 100
            Assert.AreEqual(55, repo2.WorkSpace.NumberStore); // 5, 50

            repo2.ApplyChange(new AddModification(1000));
            Assert.AreEqual(55, remote.RemoteWorkSpace.NumberStore);
            Assert.AreEqual(155, repo.WorkSpace.NumberStore);   // 5, 50, 100
            Assert.AreEqual(1055, repo2.WorkSpace.NumberStore); // 5, 50, 1000

            await remote.PushAsync();

            Assert.AreEqual(55, remote.RemoteWorkSpace.NumberStore);
            Assert.AreEqual(155, repo.WorkSpace.NumberStore);   // 5, 50, 100
            Assert.AreEqual(1155, repo2.WorkSpace.NumberStore); // 5, 50, 1000, 100
            if (commitBefore)
            {
                repo.ApplyChange(new AddModification(3));
                await remote.PullAsync();

                Assert.AreEqual(1155, remote.RemoteWorkSpace.NumberStore);
                Assert.AreEqual(1158, repo.WorkSpace.NumberStore);  // 5, 50, 1000, 100, 3
                Assert.AreEqual(1155, repo2.WorkSpace.NumberStore); // 5, 50, 1000, 100
            }
            else
            {
                await remote.PullAsync();

                Assert.AreEqual(1155, remote.RemoteWorkSpace.NumberStore);
                Assert.AreEqual(1155, repo.WorkSpace.NumberStore);  // 5, 50, 1000, 100
                Assert.AreEqual(1155, repo2.WorkSpace.NumberStore); // 5, 50, 1000, 100
            }
        }