コード例 #1
0
        public void CreateSkippedFragments()
        {
            INamedVersionedUniqueId uid1 = SharedDicTestContext.Plugins[0];
            INamedVersionedUniqueId uid2 = SharedDicTestContext.Plugins[1];

            // Creates a dummy dictionnary and writes it.
            SharedDictionaryImpl dic = CreateDummySharedDic(this, uid1, uid2);

            string path = TestBase.GetTestFilePath("SharedDic", "SkippedFragments");

            SharedDicTestContext.Write("Test", path, dic, this);
            Assert.IsTrue(new FileInfo(path).Length > 0, "File must exist and be not empty.");
            Assert.That(dic.Fragments.Count, Is.EqualTo(0), "There is no skipped fragments for this dic.");

            // Creates a second dictionnary to load previous data (with skippedFragments)
            IList <ReadElementObjectInfo> errors;
            SharedDictionaryImpl          dic2 = (SharedDictionaryImpl)SharedDicTestContext.Read("Test", path, this, out errors);

            dic2.Ensure(uid1);

            Assert.That(errors.Count, Is.EqualTo(0));
            Assert.That(dic2.Fragments.Count, Is.EqualTo(1));
            Assert.That(dic2[this, uid2, "key1"], Is.Null);
            Assert.That(dic2[this, uid2, "key2"], Is.Null);
        }
コード例 #2
0
        public void ReloadSkippedFragments()
        {
            INamedVersionedUniqueId uid1 = SharedDicTestContext.Plugins[0];
            INamedVersionedUniqueId uid2 = SharedDicTestContext.Plugins[1];

            // Creates a dummy dictionnary and writes it.
            SharedDictionaryImpl dic = CreateDummySharedDic(this, uid1, uid2);

            // Creates a second dictionnary to load previous data (with skippedFragments)
            string path = TestBase.GetTestFilePath("SharedDic", "ReloadSkippedFragments");

            SharedDicTestContext.Write("Test", path, dic, this);

            IList <ReadElementObjectInfo> errors;

            ISharedDictionary    dic2     = SharedDicTestContext.Read("Test", path, this, d => d.Ensure(uid1), out errors);
            SharedDictionaryImpl implDic2 = (SharedDictionaryImpl)dic2;

            Assert.IsTrue(new FileInfo(path).Length > 0, "File must exist and be not empty.");

            Assert.That(errors.Count, Is.EqualTo(0));
            Assert.That(implDic2.Fragments.Count, Is.EqualTo(1));
            Assert.That(dic2[this, uid2, "key1"], Is.Null);
            Assert.That(dic2[this, uid2, "key2"], Is.Null);

            // Now we have skippedFragments. Let's try to reload it.
            dic2.Ensure(uid2);

            Assert.That(dic2[this, uid2, "key1"], Is.EqualTo("value1"));
            Assert.That(dic2[this, uid2, "key2"], Is.EqualTo("value2"));

            Assert.That(implDic2.Fragments.Count, Is.EqualTo(0));
        }
コード例 #3
0
 public ISharedDictionary WriteAndReadWithTests(Action <XmlDocument> afterWrite, Action <ISharedDictionary> beforeRead)
 {
     SharedDicTestContext.Write(_testName, _path, _dic, _o, afterWrite);
     _dicRead = SharedDicTestContext.Read(_testName, _path, _o, beforeRead, out _errors);
     if (_dicRead.Contains(_uid1))
     {
         CheckRandomProperties(_dicRead, _o, _uid1, 10, _seed);
         CheckRandomProperties(_dicRead, _o, _uid1, 10, _seed2);
     }
     if (_dicRead.Contains(_uid2))
     {
         CheckRandomProperties(_dicRead, _o, _uid2, 20, _seed3);
     }
     return(_dicRead);
 }
コード例 #4
0
        public void ImportReloadedSkippedFragments()
        {
            INamedVersionedUniqueId uid1 = SharedDicTestContext.Plugins[0];
            INamedVersionedUniqueId uid2 = SharedDicTestContext.Plugins[1];

            string path = TestBase.GetTestFilePath("SharedDic", "ImportReloadedSkippedFragments");

            #region Creates actual fragments

            // Creates a dummy dictionnary and writes it.
            SharedDictionaryImpl dic = CreateDummySharedDic(this, uid1, uid2);
            SharedDicTestContext.Write("Test", path, dic, this);

            // Creates a second dictionnary to load previous data (with skippedFragments).
            IList <ReadElementObjectInfo> errors;
            SharedDictionaryImpl          dicFrag = (SharedDictionaryImpl)SharedDicTestContext.Read("Test", path, this, out errors);
            Assert.IsTrue(new FileInfo(path).Length > 0, "File must exist and be not empty.");

            Assert.That(errors.Count, Is.EqualTo(0));
            Assert.That(dicFrag.GetSkippedFragments(this).Count == 2);
            Assert.That(dicFrag[this, uid1, "key1"], Is.Null);
            Assert.That(dicFrag[this, uid2, "key2"], Is.Null);

            #endregion

            ISharedDictionary dic2 = SharedDictionary.Create(SharedDicTestContext.ServiceProvider);
            dic2[this, uid1, "key1"] = "value1";
            dic2[this, uid1, "key2"] = "value2";

            Assert.That(dic2[this, uid2, "key1"], Is.Null);
            Assert.That(dic2[this, uid2, "key2"], Is.Null);

            dic2.Ensure(uid2);

            SharedDictionaryImpl implDic2 = (SharedDictionaryImpl)dic2;
            implDic2.ImportFragments(dicFrag.Fragments, MergeMode.None);
            Assert.That(implDic2.GetSkippedFragments(this) == null);

            Assert.That(dic2[this, uid2, "key1"], Is.EqualTo("value1"));
            Assert.That(dic2[this, uid2, "key2"], Is.EqualTo("value2"));
        }
コード例 #5
0
        public void MergeFragments_PreserveExisting()
        {
            INamedVersionedUniqueId uid1 = SharedDicTestContext.Plugins[0];
            INamedVersionedUniqueId uid2 = SharedDicTestContext.Plugins[1];
            INamedVersionedUniqueId uid3 = SharedDicTestContext.Plugins[2];

            SharedDictionaryImpl dic = new SharedDictionaryImpl(SharedDicTestContext.ServiceProvider);

            dic[this, uid1, "key1"] = "value1";
            dic[this, uid1, "key2"] = "value2";
            dic[this, uid2, "key1"] = "value1";
            dic[this, uid2, "key2"] = "value2";
            dic[this, uid3, "key1"] = "value1";
            dic[this, uid3, "key2"] = "value2";

            string path = TestBase.GetTestFilePath("SharedDic", "MergeFragments");

            SharedDicTestContext.Write("Test", path, dic, this);

            IList <ReadElementObjectInfo> errors;
            SharedDictionaryImpl          dicFullFrag = (SharedDictionaryImpl)SharedDicTestContext.Read("Test", path, this, out errors);

            Assert.That(errors.Count == 0);
            Assert.That(dicFullFrag.GetSkippedFragments(this).Count == 3);

            SharedDictionaryImpl dicFrag = (SharedDictionaryImpl)SharedDicTestContext.Read("Test", path, this, d => { d.Ensure(uid1); d.Ensure(uid2); }, out errors);

            Assert.That(errors.Count == 0);
            Assert.That(dicFrag.GetSkippedFragments(this).Count == 1);

            int hashCode = dicFrag.GetSkippedFragments(this)[0].GetHashCode();

            dicFrag.ImportFragments(dicFullFrag.Fragments, MergeMode.PreserveExisting);

            Assert.That(dicFrag.GetSkippedFragments(this) != null);
            Assert.That(dicFrag.GetSkippedFragments(this).Count == 1);
            Assert.That(dicFrag.GetSkippedFragments(this)[0].GetHashCode() == hashCode);
        }
コード例 #6
0
        public void MergeFragments_ErrorDuplicate()
        {
            INamedVersionedUniqueId uid1 = SharedDicTestContext.Plugins[0];
            INamedVersionedUniqueId uid2 = SharedDicTestContext.Plugins[1];
            INamedVersionedUniqueId uid3 = SharedDicTestContext.Plugins[2];

            SharedDictionaryImpl dic = new SharedDictionaryImpl(SharedDicTestContext.ServiceProvider);

            dic[this, uid1, "key1"] = "value1";
            dic[this, uid1, "key2"] = "value2";
            dic[this, uid2, "key1"] = "value1";
            dic[this, uid2, "key2"] = "value2";
            dic[this, uid3, "key1"] = "value1";
            dic[this, uid3, "key2"] = "value2";
            Assert.That(dic.Contains(uid1) && dic.Contains(uid2) && dic.Contains(uid3));

            string path = TestBase.GetTestFilePath("SharedDic", "ErrorDuplicate");

            SharedDicTestContext.Write("Test", path, dic, this);

            IList <ReadElementObjectInfo> errors;
            SharedDictionaryImpl          dicFullFrag = (SharedDictionaryImpl)SharedDicTestContext.Read("Test", path, this, out errors);

            Assert.That(errors.Count == 0);

            SharedDictionaryImpl dicFrag = (SharedDictionaryImpl)SharedDicTestContext.Read("Test", path, this, d => { d.Ensure(uid1); d.Ensure(uid2); }, out errors);

            Assert.That(errors.Count == 0);

            Assert.That(dic.GetSkippedFragments(this) == null);
            Assert.That(dicFullFrag.GetSkippedFragments(this).Count == 3);
            Assert.That(dicFrag.GetSkippedFragments(this).Count == 1);

            Assert.Throws <CKException>(() => dicFrag.ImportFragments(dicFullFrag.Fragments, MergeMode.ErrorOnDuplicate));

            Assert.That(dicFrag.GetSkippedFragments(this).Count == 1);
        }
コード例 #7
0
        void TryReloadNestedSkippedFragments(ITestObject complexObject)
        {
            object rootObject = new object();

            SimpleNamedVersionedUniqueId p1 = new SimpleNamedVersionedUniqueId(Guid.NewGuid(), new Version(1, 0, 0), "plugin1");
            SimpleNamedVersionedUniqueId p2 = new SimpleNamedVersionedUniqueId(Guid.NewGuid(), new Version(1, 0, 0), "plugin2");

            string path = TestBase.GetTestFilePath("SharedDic", "NestedSkippedFragments");

            // Write !
            {
                SharedDictionaryImpl dic = new SharedDictionaryImpl(SharedDicTestContext.ServiceProvider);
                dic[rootObject, p1, "complexObject"] = complexObject;
                dic[complexObject, p2, "subKey"]     = "subValue";

                SharedDicTestContext.Write("Test", path, dic, rootObject);

                TestBase.DumpFileToConsole(path);
            }
            // Read nothing then p1 and p2
            {
                IList <ReadElementObjectInfo> errors = new List <ReadElementObjectInfo>();
                SharedDictionaryImpl          dic    = (SharedDictionaryImpl)SharedDicTestContext.Read("Test", path, rootObject, out errors);

                dic.Ensure(p1);
                dic.Ensure(p2);

                CheckAllDataLoaded(rootObject, complexObject, p1, p2, dic);
            }
            // Read nothing then p2 and p1
            {
                IList <ReadElementObjectInfo> errors = new List <ReadElementObjectInfo>();
                SharedDictionaryImpl          dic    = (SharedDictionaryImpl)SharedDicTestContext.Read("Test", path, rootObject, out errors);

                dic.Ensure(p2);
                dic.Ensure(p1);

                CheckAllDataLoaded(rootObject, complexObject, p1, p2, dic);
            }
            // Ensure p1 then read p2
            {
                IList <ReadElementObjectInfo> errors = new List <ReadElementObjectInfo>();
                SharedDictionaryImpl          dic    = (SharedDictionaryImpl)SharedDicTestContext.Read("Test", path, rootObject, d => d.Ensure(p1), out errors);

                dic.Ensure(p2);

                CheckAllDataLoaded(rootObject, complexObject, p1, p2, dic);
            }
            // Ensure p2 then read p1
            {
                IList <ReadElementObjectInfo> errors = new List <ReadElementObjectInfo>();
                SharedDictionaryImpl          dic    = (SharedDictionaryImpl)SharedDicTestContext.Read("Test", path, rootObject, d => d.Ensure(p2), out errors);

                dic.Ensure(p1);

                CheckAllDataLoaded(rootObject, complexObject, p1, p2, dic);
            }
            // Ensure p1 and p2 then read nothing
            {
                IList <ReadElementObjectInfo> errors = new List <ReadElementObjectInfo>();
                SharedDictionaryImpl          dic    = (SharedDictionaryImpl)SharedDicTestContext.Read("Test", path, rootObject, d => { d.Ensure(p1); d.Ensure(p2); }, out errors);

                CheckAllDataLoaded(rootObject, complexObject, p1, p2, dic);
            }
            // Ensure p2 and p1 then read nothing
            {
                IList <ReadElementObjectInfo> errors = new List <ReadElementObjectInfo>();
                SharedDictionaryImpl          dic    = (SharedDictionaryImpl)SharedDicTestContext.Read("Test", path, rootObject, d => { d.Ensure(p2); d.Ensure(p1); }, out errors);

                CheckAllDataLoaded(rootObject, complexObject, p1, p2, dic);
            }
        }
コード例 #8
0
        public void SyncDestroyObject()
        {
            INamedVersionedUniqueId uid1 = SharedDicTestContext.Plugins[0];
            INamedVersionedUniqueId uid2 = SharedDicTestContext.Plugins[1];
            INamedVersionedUniqueId uid3 = SharedDicTestContext.Plugins[2];

            string path = TestBase.GetTestFilePath("SharedDic", "MergeFragments");
            SharedDictionaryImpl dicFullFrag;

            // Create fragments file.
            {
                SharedDictionaryImpl dic = new SharedDictionaryImpl(SharedDicTestContext.ServiceProvider);
                dic[this, uid1, "key1"] = "value1";
                dic[this, uid1, "key2"] = "value2";
                dic[this, uid2, "key1"] = "value1";
                dic[this, uid2, "key2"] = "value2";
                dic[this, uid3, "key1"] = "value1";
                dic[this, uid3, "key2"] = "value2";

                SharedDicTestContext.Write("Test", path, dic, this);
            }
            {
                IList <ReadElementObjectInfo> errors;
                dicFullFrag = (SharedDictionaryImpl)SharedDicTestContext.Read("Test", path, this, out errors);
                Assert.That(errors.Count == 0);
                Assert.That(dicFullFrag.GetSkippedFragments(this).Count == 3);

                dicFullFrag.Destroy(this);
                Assert.That(dicFullFrag.GetSkippedFragments(this) == null, "Destroying the object destroyed the fragments.");
            }

            {
                IList <ReadElementObjectInfo> errors;
                dicFullFrag = (SharedDictionaryImpl)SharedDicTestContext.Read("Test", path, this, out errors);
                Assert.That(errors.Count == 0);
                Assert.That(dicFullFrag.GetSkippedFragments(this).Count == 3);

                // If we Ensure() the id, then the fragment will be restored.
                // We test here the ClearFragments internal.
                dicFullFrag.ClearFragments(uid1);
                Assert.That(dicFullFrag.GetSkippedFragments(this).Count == 2, "Destroying the fragment explicitely.");

                dicFullFrag.Destroy(uid2);
                Assert.That(dicFullFrag.GetSkippedFragments(this).Count == 1, "Destroying the fragment explicitely.");

                dicFullFrag.Destroy(uid3);
                Assert.That(dicFullFrag.GetSkippedFragments(this) == null, "Destroying the fragment explicitely.");
            }

            {
                IList <ReadElementObjectInfo> errors;
                dicFullFrag = (SharedDictionaryImpl)SharedDicTestContext.Read("Test", path, this, out errors);
                Assert.That(errors.Count == 0);
                Assert.That(dicFullFrag.GetSkippedFragments(this).Count == 3);

                // This destroy an unknown plugin:
                // we must destroy the fragments even if the id is not known.
                dicFullFrag.Destroy(uid2);
                Assert.That(dicFullFrag.GetSkippedFragments(this).Count == 2, "Destroying the fragment via an unknown Id.");

                dicFullFrag.Destroy(uid3);
                Assert.That(dicFullFrag.GetSkippedFragments(this).Count == 1, "Destroying the fragment via an unknown Id.");

                // No op.
                dicFullFrag.Destroy(uid3);

                dicFullFrag.Destroy(uid1);
                Assert.That(dicFullFrag.GetSkippedFragments(this) == null);
            }

            {
                IList <ReadElementObjectInfo> errors;
                dicFullFrag = (SharedDictionaryImpl)SharedDicTestContext.Read("Test", path, this, out errors);
                Assert.That(errors.Count == 0);
                Assert.That(dicFullFrag.GetSkippedFragments(this).Count == 3);

                dicFullFrag.ClearAll();

                Assert.That(dicFullFrag.GetSkippedFragments(this) == null);
            }
        }
コード例 #9
0
ファイル: ReadWrites.cs プロジェクト: macdarwin/ck-desktop
        public void SimpleConfig()
        {
            INamedVersionedUniqueId id1 = SharedDicTestContext.Plugins[0];
            INamedVersionedUniqueId id2 = SharedDicTestContext.Plugins[1];

            SharedDictionaryImpl dic1 = new SharedDictionaryImpl(SharedDicTestContext.ServiceProvider);

            // 1 - Writes the data to the file without any skipped fragments since we do not have any yet.
            dic1[this, id1, "AnIntParam"]   = 1;
            dic1[this, id1, "ABoolParam"]   = true;
            dic1[this, id1, "AStringParam"] = "This marvellous API works!";
            dic1[this, id1, "ANullObject"]  = null;

            dic1[this, id2, "AnIntParam"]   = 1;
            dic1[this, id2, "ABoolParam"]   = true;
            dic1[this, id2, "AStringParam"] = "This must not be reloaded since the plugin is not runnable for dic2.";

            Assert.That(dic1.Contains(id1) && dic1.Contains(id2));

            string path1 = TestBase.GetTestFilePath("SharedDic", "SimpleConfig");

            SharedDicTestContext.Write("Test", path1, dic1, this);
            Assert.IsTrue(new FileInfo(path1).Length > 0, "File must exist and be not empty.");

            // 2 - Reloads the file in another dictionary: fragments are now updated with data from the not runnable plugin.
            IList <ReadElementObjectInfo> errors;
            ISharedDictionary             dic2 = SharedDicTestContext.Read("Test", path1, this, d => d.Ensure(id1), out errors);

            Assert.AreEqual(0, errors.Count, "This file has no errors in it.");

            Assert.That(dic1[this, id1, "AnIntParam"], Is.EqualTo(dic2[this, id1, "AnIntParam"]));
            Assert.That(dic1[this, id1, "ABoolParam"], Is.EqualTo(dic2[this, id1, "ABoolParam"]));
            Assert.That(dic1[this, id1, "AStringParam"], Is.EqualTo(dic2[this, id1, "AStringParam"]));
            Assert.That(dic1[this, id1, "ANullObject"], Is.EqualTo(dic2[this, id1, "ANullObject"]));
            Assert.That(dic1.Contains(this, id1, "ANullObject") && dic2.Contains(this, id1, "ANullObject"), "The null value has a key.");
            Assert.That(dic2.Contains(this, id2, "AnUnexistingKey"), Is.False, "Any other key is not defined.");

            // _notRunnables data are not loaded...
            Assert.That(dic2[this, id2, "AnIntParam"], Is.Null);
            Assert.That(dic2.Contains(this, id2, "AnIntParam"), Is.False);
            Assert.That(dic2[this, id2, "ABoolParam"], Is.Null);
            Assert.That(dic2.Contains(this, id2, "ABoolParam"), Is.False);
            Assert.That(dic2[this, id2, "AStringParam"], Is.Null);
            Assert.That(dic2.Contains(this, id2, "AStringParam"), Is.False);
            Assert.That(dic2.Contains(this, id2, "ANullObject"), Is.False);

            // 3 - Rewrites the file n°2 from dic2 with the skipped fragments.
            string path2 = TestBase.GetTestFilePath("SharedDic", "SimpleConfig2");

            SharedDicTestContext.Write("Test", path2, dic2, this);
            Assert.IsTrue(new FileInfo(path2).Length > 0, "File must exist and be not empty.");

            // Files are not equal due to whitespace handling and node reordering.
            // To compare them we should reload the 2 documents and to be independant of the element ordering
            // we need to ensure that every element of d1 exists with the same attributes in d2 and vice-versa.

            // 4 - In fragments, we have the NotRunnables[0] plugin fragment.
            SharedDictionaryImpl implDic2 = (SharedDictionaryImpl)dic2;

            Assert.That(implDic2.GetSkippedFragments(this).Count == 1);
            Assert.That(implDic2.GetSkippedFragments(this)[0].PluginId == id2.UniqueId);

            // Activate the previously not runnable plugin.
            dic2.Ensure(id2);

            Assert.That(implDic2.GetSkippedFragments(this), Is.Null, "Fragment has been read (no more fragments).");
            Assert.AreEqual(dic1[this, id2, "AnIntParam"], dic2[this, id1, "AnIntParam"]);
            Assert.AreEqual(dic1[this, id2, "ABoolParam"], dic2[this, id1, "ABoolParam"]);
            Assert.AreEqual(dic1[this, id2, "AStringParam"], "This must not be reloaded since the plugin is not runnable for dic2.");
            Assert.AreEqual(dic1[this, id1, "AStringParam"], "This marvellous API works!");
        }