Ejemplo n.º 1
0
        public Section CreateSection
        (
            [NotNull] string name
        )
        {
            CheckKeyName(name);

            if (ContainsSection(name))
            {
                Log.Error
                (
                    "IniFile::CreateSection: "
                    + "duplicate name="
                    + name
                );

                throw new DuplicateKeyException("name");
            }

            Section result = new Section(this, name);

            _sections.Add(result);

            return(result);
        }
Ejemplo n.º 2
0
        public void NonNullCollection_ToArray_3()
        {
            NonNullCollection <string> collection = new NonNullCollection <string>();

            collection.Add("hello");
            collection.Add("world");
            string[] array = collection.ToArray();
            Assert.AreEqual(2, array.Length);
            Assert.AreEqual("hello", array[0]);
            Assert.AreEqual("world", array[1]);
        }
Ejemplo n.º 3
0
        public void NonNullCollection_Unit_Add_ItemIsNull()
        {
            NonNullCollection<String> target = new NonNullCollection<String>();
            String item = null;

            target.Add(item);
        }
Ejemplo n.º 4
0
        public void NonNullCollection_Unit_Add_Optimal()
        {
            NonNullCollection<String> target = new NonNullCollection<String>();
            String item = "Test";

            target.Add(item);
            CollectionAssert.Contains(target, item);
        }
Ejemplo n.º 5
0
            /// <summary>
            /// Add new line to the section.
            /// </summary>
            public void Add
            (
                [NotNull] Line line
            )
            {
                Code.NotNull(line, "line");
                CheckKeyName(line.Key);
                if (ContainsKey(line.Key))
                {
                    Log.Error
                    (
                        "IniFile::Add: "
                        + "duplicate key="
                        + line.Key
                    );

                    throw new DuplicateKeyException("key");
                }

                _lines.Add(line);
            }
Ejemplo n.º 6
0
        public void Add_OfAnInstanceInitializedWithReadOnlyList_ThrowsException()
        {
            // Arrange
            var c0 = new NonNullCollection <IUnit>(new IUnit[] {
                MutableUnit.Create("foo"), MutableUnit.Create("bar")
            }.ToList().AsReadOnly());

            // Act
            // Assert
            Assert.That(() => {
                c0.Add(MutableUnit.Create("baz"));
            }, Throws.InstanceOf <NotSupportedException>());
        }
Ejemplo n.º 7
0
        public void Add_OfAnInstanceInitializedWithNormalList_DoesNotThrowException()
        {
            // Arrange
            var c0 = new NonNullCollection <IUnit>(new IUnit[] {
                MutableUnit.Create("foo"), MutableUnit.Create("bar")
            }.ToList());

            // Act
            c0.Add(MutableUnit.Create("baz"));

            // Assert
            Assert.That(c0.Count, Is.EqualTo(3));
        }
Ejemplo n.º 8
0
        public static BinaryReader ReadCollection <T>
        (
            [NotNull] this BinaryReader reader,
            [NotNull] NonNullCollection <T> collection
        )
            where T : class, IHandmadeSerializable, new()
        {
            Sure.NotNull(reader, nameof(reader));
            Sure.NotNull(collection, nameof(collection));

            collection.Clear();

            int count = reader.ReadPackedInt32();

            for (int i = 0; i < count; i++)
            {
                T item = new T();
                item.RestoreFromStream(reader);
                collection.Add(item);
            }

            return(reader);
        }