Ejemplo n.º 1
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"));
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
        }