public void SubFieldCollection_ReadOnly2()
        {
            SubFieldCollection collection = new SubFieldCollection();

            collection.SetReadOnly();
            collection.Add(new SubField());
        }
        public void SubFieldCollection_ClearItems1()
        {
            SubFieldCollection collection = _GetCollection();

            collection.Clear();
            Assert.AreEqual(0, collection.Count);
        }
        public void SubFieldCollection_FromJson1()
        {
            const string text = @"["
                                + @"  {"
                                + @"    ""code"": ""a"","
                                + @"    ""value"": ""Subfield A"""
                                + @"  },"
                                + @"  {"
                                + @"    ""code"": ""b"","
                                + @"    ""value"": ""Subfield B"""
                                + @"  },"
                                + @"  {"
                                + @"    ""code"": ""c"","
                                + @"    ""value"": ""Subfield C"""
                                + @"  }"
                                + @"]";
            SubFieldCollection collection
                = SubFieldCollection.FromJson(text);

            Assert.AreEqual(3, collection.Count);
            Assert.AreEqual('a', collection[0].Code);
            Assert.AreEqual("Subfield A", collection[0].Value);
            Assert.AreEqual('b', collection[1].Code);
            Assert.AreEqual("Subfield B", collection[1].Value);
            Assert.AreEqual('c', collection[2].Code);
            Assert.AreEqual("Subfield C", collection[2].Value);
        }
        private void _TestSerialization
        (
            params SubField[] subFields
        )
        {
            SubFieldCollection collection1 = new SubFieldCollection();

            collection1.AddRange(subFields);

            //collection1.SaveToFile("collection1.bin");
            //collection1.SaveToZipFile("collection1.biz");

            byte[] bytes = collection1.SaveToMemory();

            SubFieldCollection collection2 = bytes
                                             .RestoreObjectFromMemory <SubFieldCollection>();

            Assert.AreEqual(collection1.Count, collection2.Count);

            for (int i = 0; i < collection1.Count; i++)
            {
                Assert.AreEqual
                (
                    0,
                    SubField.Compare
                    (
                        collection1[i],
                        collection2[i]
                    )
                );
            }
        }
        public void SubFieldCollection_RemoveItem1()
        {
            SubFieldCollection collection = _GetCollection();

            Assert.AreEqual(3, collection.Count);
            collection.Remove(collection[1]);
            Assert.AreEqual(2, collection.Count);
        }
Exemplo n.º 6
0
        public void SubFieldUtility_GetSubField_6()
        {
            SubFieldCollection collection = _GetCollection();
            int counter = 0;
            Action <SubField> action = sub => counter++;

            SubField[] found = collection.GetSubField(action);
            Assert.AreEqual(6, found.Length);
            Assert.AreEqual(6, counter);
        }
        public void SubFieldCollection_InsertItem1()
        {
            SubFieldCollection collection = _GetCollection();

            Assert.AreEqual(3, collection.Count);
            SubField subField = new SubField('d', "Subfield D");

            collection.Insert(1, subField);
            Assert.AreEqual(subField, collection[1]);
            Assert.AreEqual(4, collection.Count);
        }
        private SubFieldCollection _GetCollection()
        {
            SubFieldCollection result = new SubFieldCollection
            {
                new SubField('a', "Subfield A"),
                new SubField('b', "Subfield B"),
                new SubField('c', "Subfield C")
            };

            return(result);
        }
        public void SubFieldCollection_NotNull_1()
        {
            SubFieldCollection collection = new SubFieldCollection
            {
                new SubField(),
                null,
                new SubField('a')
            };

            Assert.AreEqual(2, collection.Count);
        }
        public void SubFieldCollection_SetItem_1()
        {
            SubFieldCollection collection = _GetCollection();

            Assert.AreEqual(3, collection.Count);
            SubField subField = new SubField('d', "Subfield D");

            collection[1] = subField;
            Assert.AreEqual(3, collection.Count);
            Assert.AreEqual(subField, collection[1]);
        }
        public void SubFieldCollection_Constructor1()
        {
            SubFieldCollection collection =
                new SubFieldCollection
            {
                new SubField(),
                new SubField('a'),
                new SubField('b', "Value")
            };

            Assert.AreEqual(3, collection.Count);
        }
Exemplo n.º 12
0
        public void SubFieldUtility_GetSubField_2()
        {
            SubFieldCollection collection = _GetCollection();

            SubField[] found = collection.GetSubField('a');
            Assert.AreEqual(2, found.Length);
            Assert.AreEqual("SubFieldA1", found[0].Value);
            Assert.AreEqual("SubFieldA2", found[1].Value);

            found = collection.GetSubField('d');
            Assert.AreEqual(0, found.Length);
        }
Exemplo n.º 13
0
        public void SubFieldUtility_GetFirstSubField_6()
        {
            SubFieldCollection collection = _GetCollection();
            SubField           found      = collection.GetFirstSubField('a', "SubFieldA2");

            Assert.AreEqual("SubFieldA2", found.Value);

            found = collection.GetFirstSubField('c', "SubFieldC3");
            Assert.IsNull(found);

            found = collection.GetFirstSubField('d', "No such subfield");
            Assert.IsNull(found);
        }
        public void SubFieldCollection_AsReadOnly1()
        {
            SubFieldCollection collection = new SubFieldCollection();
            SubField           subFieldA  = new SubField('a', "Title1");

            collection.Add(subFieldA);
            SubField subFieldE = new SubField('e', "Subtitle");

            collection.Add(subFieldE);

            collection = collection.AsReadOnly();
            collection.Add(new SubField());
        }
Exemplo n.º 15
0
        public void SubFieldUtility_GetFirstSubField_4()
        {
            SubFieldCollection collection = _GetCollection();
            SubField           found      = collection.GetFirstSubField('a', 'b');

            Assert.AreEqual("SubFieldA1", found.Value);

            found = collection.GetFirstSubField('c', 'd');
            Assert.AreEqual("SubFieldC1", found.Value);

            found = collection.GetFirstSubField('d', 'e');
            Assert.IsNull(found);
        }
        public void SubFieldCollection_SetReadOnly1()
        {
            SubFieldCollection collection = new SubFieldCollection();
            SubField           subFieldA  = new SubField('a', "Title1");

            collection.Add(subFieldA);
            SubField subFieldE = new SubField('e', "Subtitle");

            collection.Add(subFieldE);

            collection.SetReadOnly();

            subFieldA.Value = "New value";
        }
        public void SubFieldCollection_Clone1()
        {
            SubFieldCollection collection = new SubFieldCollection();
            SubField           subFieldA  = new SubField('a', "Title1");

            collection.Add(subFieldA);
            SubField subFieldE = new SubField('e', "Subtitle");

            collection.Add(subFieldE);

            SubFieldCollection clone = collection.Clone();

            Assert.AreEqual(collection.Count, clone.Count);
        }
Exemplo n.º 18
0
        private SubFieldCollection _GetCollection()
        {
            SubFieldCollection result = new SubFieldCollection
            {
                new SubField('a', "SubFieldA1"),
                new SubField('b', "SubFieldB1"),
                new SubField('c', "SubFieldC1"),
                new SubField('a', "SubFieldA2"),
                new SubField('b', "SubFieldB2"),
                new SubField('c', "SubFieldC2"),
            };

            return(result);
        }
Exemplo n.º 19
0
        public void SubFieldUtility_GetSubField_4()
        {
            SubFieldCollection collection = _GetCollection();

            SubField[] found = collection.GetSubField('a', 'b');
            Assert.AreEqual(4, found.Length);
            Assert.AreEqual("SubFieldA1", found[0].Value);
            Assert.AreEqual("SubFieldB1", found[1].Value);
            Assert.AreEqual("SubFieldA2", found[2].Value);
            Assert.AreEqual("SubFieldB2", found[3].Value);

            found = collection.GetSubField('c', 'd');
            Assert.AreEqual(2, found.Length);
            Assert.AreEqual("SubFieldC1", found[0].Value);
            Assert.AreEqual("SubFieldC2", found[1].Value);

            found = collection.GetSubField('d', 'e');
            Assert.AreEqual(0, found.Length);
        }
        public void SubFieldCollection_AssignClone1()
        {
            SubFieldCollection source = _GetCollection();
            SubFieldCollection target = new SubFieldCollection();

            target.AssignClone(source);

            Assert.AreEqual(source.Field, target.Field);
            Assert.AreEqual(source.Count, target.Count);
            for (int i = 0; i < source.Count; i++)
            {
                Assert.AreEqual
                (
                    0,
                    SubField.Compare
                    (
                        source[i],
                        target[i]
                    )
                );
            }
        }
        public void SubFieldCollection_FindAll1()
        {
            SubFieldCollection collection = new SubFieldCollection();
            SubField           subFieldA  = new SubField('a', "Title1");

            collection.Add(subFieldA);
            SubField subFieldE = new SubField('e', "Subtitle");

            collection.Add(subFieldE);

            SubField[] found = collection.FindAll
                               (
                x => x.Value.SameString("Subtitle")
                               );
            Assert.AreEqual(1, found.Length);

            found = collection.FindAll
                    (
                x => x.Value.SameString("Notitle")
                    );
            Assert.AreEqual(0, found.Length);
        }
        public void SubFieldCollection_ToJson1()
        {
            SubFieldCollection collection = _GetCollection();

            string actual = collection.ToJson()
                            .Replace("\r", "").Replace("\n", "");
            const string expected = @"["
                                    + @"  {"
                                    + @"    ""code"": ""a"","
                                    + @"    ""value"": ""Subfield A"""
                                    + @"  },"
                                    + @"  {"
                                    + @"    ""code"": ""b"","
                                    + @"    ""value"": ""Subfield B"""
                                    + @"  },"
                                    + @"  {"
                                    + @"    ""code"": ""c"","
                                    + @"    ""value"": ""Subfield C"""
                                    + @"  }"
                                    + @"]";

            Assert.AreEqual(expected, actual);
        }
        public void SubFieldCollection_Find1()
        {
            SubFieldCollection collection = new SubFieldCollection();
            SubField           subFieldA  = new SubField('a', "Title1");

            collection.Add(subFieldA);
            SubField subFieldE = new SubField('e', "Subtitle");

            collection.Add(subFieldE);

            SubField found = collection.Find
                             (
                x => x.Value.SameString("Subtitle")
                             );

            Assert.AreEqual(subFieldE, found);

            found = collection.Find
                    (
                x => x.Value.SameString("Notitle")
                    );
            Assert.IsNull(found);
        }
        public void SubFieldCollection_SetItem_2()
        {
            SubFieldCollection collection = _GetCollection();

            collection[1] = null;
        }
        public void SubFieldCollection_InsertItem_Exception()
        {
            SubFieldCollection collection = _GetCollection();

            collection.Insert(1, null);
        }