Example #1
0
        public void NonNullCollection_ToArray_1()
        {
            NonNullCollection <string> collection = new NonNullCollection <string>();

            string[] array = collection.ToArray();
            Assert.AreEqual(0, array.Length);
        }
        public void BinaryReaderUtility_ReadCollectionT_1()
        {
            MemoryStream stream = new MemoryStream();
            BinaryWriter writer = new BinaryWriter(stream);

            NonNullCollection <Dummy> expected = new NonNullCollection <Dummy>
            {
                new Dummy {
                    Value = 123
                },
                new Dummy {
                    Value = 456
                },
                new Dummy {
                    Value = 789
                }
            };

            BinaryWriterUtility.Write(writer, expected);

            byte[] bytes = stream.ToArray();
            stream = new MemoryStream(bytes);
            BinaryReader reader = new BinaryReader(stream);

            NonNullCollection <Dummy> actual = new NonNullCollection <Dummy>();

            BinaryReaderUtility.ReadCollection(reader, actual);
            Assert.AreEqual(expected.Count, actual.Count);
            Assert.AreEqual(expected[0].Value, actual[0].Value);
            Assert.AreEqual(expected[1].Value, actual[1].Value);
            Assert.AreEqual(expected[2].Value, actual[2].Value);
        }
Example #3
0
 /// <summary>
 /// Internal constructor.
 /// </summary>
 internal MenuFile
 (
     NonNullCollection <MenuEntry> entries
 )
 {
     Entries = entries;
 }
Example #4
0
        public void NonNullCollection_Unit_Add_ItemIsNull()
        {
            NonNullCollection<String> target = new NonNullCollection<String>();
            String item = null;

            target.Add(item);
        }
Example #5
0
        public void NonNullCollection_Unit_Add_Optimal()
        {
            NonNullCollection<String> target = new NonNullCollection<String>();
            String item = "Test";

            target.Add(item);
            CollectionAssert.Contains(target, item);
        }
 /// <summary>
 /// Constructor.
 /// </summary>
 public WriteRecordsCommand
 (
     [NotNull] IIrbisConnection connection
 )
     : base(connection)
 {
     References = new NonNullCollection <RecordReference>();
 }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="connection"></param>
 public ReadFileCommand
 (
     [NotNull] IIrbisConnection connection
 )
     : base(connection)
 {
     _files = new NonNullCollection <FileSpecification>();
 }
Example #8
0
 /// <inheritdoc cref="IHandmadeSerializable.RestoreFromStream" />
 public void RestoreFromStream
 (
     BinaryReader reader
 )
 {
     _name  = reader.ReadNullableString();
     _lines = reader.ReadNonNullCollection <Line>();
 }
 /// <summary>
 /// Constructor.
 /// </summary>
 public ListFilesCommand
 (
     [NotNull] IIrbisConnection connection
 )
     : base(connection)
 {
     _specifications = new NonNullCollection <FileSpecification>();
 }
Example #10
0
        public void NonNullCollection_Indexer_1a()
        {
            NonNullCollection <object> collection = new NonNullCollection <object>
            {
                new object()
            };

            collection[0] = null;
        }
Example #11
0
        public void NonNullCollection_ToArray_2()
        {
            NonNullCollection <string> collection = new NonNullCollection <string>();

            collection.Add("hello");
            string[] array = collection.ToArray();
            Assert.AreEqual(1, array.Length);
            Assert.AreEqual("hello", array[0]);
        }
Example #12
0
        public void NonNullCollection_Add_1()
        {
            NonNullCollection <object> collection = new NonNullCollection <object>
            {
                new object()
            };

            Assert.AreEqual(1, collection.Count);
        }
Example #13
0
        public void NonNullCollection_Add_1a()
        {
            NonNullCollection <object> collection = new NonNullCollection <object>
            {
                null
            };

            Assert.AreEqual(0, collection.Count);
        }
Example #14
0
 internal Section
 (
     [NotNull] IniFile owner,
     [CanBeNull] string name
 )
 {
     Owner  = owner;
     _name  = name;
     _lines = new NonNullCollection <Line>();
 }
Example #15
0
        public void NonNullCollection_Indexer_1()
        {
            NonNullCollection <object> collection = new NonNullCollection <object>
            {
                new object()
            };

            collection[0] = 1;
            Assert.AreEqual(1, collection[0]);
        }
Example #16
0
        public void NonNullCollection_EnsureCapacity_1()
        {
            NonNullCollection <object> collection = new NonNullCollection <object>
            {
                new object()
            };

            collection.EnsureCapacity(100);
            Assert.IsTrue(collection.Capacity >= 100);
        }
Example #17
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public GblSettings()
 {
     Actualize     = true;
     Autoin        = false;
     FirstRecord   = 1;
     FormalControl = false;
     MaxMfn        = 0;
     MinMfn        = 0;
     Statements    = new NonNullCollection <GblStatement>();
 }
Example #18
0
        public void NonNullCollection_Clear_1()
        {
            NonNullCollection <object> collection
                = new NonNullCollection <object>
                {
                new object()
                };

            collection.Clear();
            Assert.AreEqual(0, collection.Count);
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        public UniversalTextCommand
        (
            [NotNull] IIrbisConnection connection,
            [NotNull] string commandCode
        )
            : base(connection)
        {
            Sure.NotNull(connection, nameof(connection));
            Sure.NotNullNorEmpty(commandCode, nameof(commandCode));

            CommandCode = commandCode;
            TextLines   = new NonNullCollection <TextWithEncoding>();
        }
Example #20
0
        public void RemoveAt_OfAnInstanceInitializedWithNormalList_DoesNotThrowException()
        {
            // Arrange
            var c0 = new NonNullCollection <IUnit>(new IUnit[] {
                MutableUnit.Create("foo"), MutableUnit.Create("bar")
            }.ToList());

            // Act
            c0.RemoveAt(1);

            // Assert
            Assert.That(c0.Count, Is.EqualTo(1));
        }
Example #21
0
        public void RemoveAt_OfAnInstanceInitializedWithReadOnlyList_ThrowsException()
        {
            // Arrange
            var c0 = new NonNullCollection <IUnit>(new IUnit[] {
                MutableUnit.Create("foo"), MutableUnit.Create("bar")
            }.ToList().AsReadOnly());

            // Act
            // Assert
            Assert.That(() => {
                c0.RemoveAt(1);
            }, Throws.InstanceOf <NotSupportedException>());
        }
        /// <summary>
        /// Write the <see cref="NonNullCollection{T}"/>
        /// to the stream.
        /// </summary>
        public static BinaryWriter Write <T>
        (
            [NotNull] this BinaryWriter writer,
            [NotNull] NonNullCollection <T> collection
        )
            where T : class, IHandmadeSerializable, new()
        {
            Code.NotNull(writer, "writer");

            writer.WriteArray(collection.ToArray());

            return(writer);
        }
        public static NonNullCollection <T> ReadNonNullCollection <T>
        (
            [NotNull] this BinaryReader reader
        )
            where T : class, IHandmadeSerializable, new ()
        {
            Sure.NotNull(reader, nameof(reader));

            T[] array = reader.ReadArray <T>();
            NonNullCollection <T> result = new NonNullCollection <T>();

            result.AddRange(array);

            return(result);
        }
Example #24
0
        public void NonNullCollection_AddRange_4()
        {
            NonNullCollection <object> collection
                = new NonNullCollection <object>();

            collection.AddRange
            (
                new[]
            {
                new object(),
                null,
                new object()
            }
            );
        }
Example #25
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="value"></param>
        public Parameter
        (
            [NotNull] string name,
            [CanBeNull] string value
        )
        {
            Sure.NotNullNorEmpty(name, nameof(name));

            Name   = name;
            Value  = value ?? string.Empty;
            Values = new NonNullCollection <string>
            {
                Value
            };
        }
Example #26
0
        public static MenuFile FromJson
        (
            [NotNull] string text
        )
        {
            Sure.NotNullNorEmpty(text, nameof(text));

            NonNullCollection <MenuEntry> entries = JsonConvert
                                                    .DeserializeObject <NonNullCollection <MenuEntry> >
                                                    (
                text
                                                    );
            MenuFile result = new MenuFile(entries);

            return(result);
        }
Example #27
0
        public void NonNullCollection_AddRange_3()
        {
            NonNullCollection <object> collection
                = new NonNullCollection <object>();

            collection.AddRange
            (
                (IList <object>) new[]
            {
                new object(),
                new object(),
                new object()
            }
            );
            Assert.AreEqual(3, collection.Count);
        }
        public static BinaryWriter WriteCollection <T>
        (
            [NotNull] this BinaryWriter writer,
            [NotNull][ItemNotNull] NonNullCollection <T> collection
        )
            where T : class, IHandmadeSerializable, new()
        {
            Code.NotNull(writer, "writer");
            Code.NotNull(collection, "collection");

            writer.WritePackedInt32(collection.Count);
            for (int i = 0; i < collection.Count; i++)
            {
                T item = collection[i];
                item.SaveToStream(writer);
            }

            return(writer);
        }
Example #29
0
        /// <inheritdoc cref="JsonConverter.ReadJson" />
        public override object ReadJson
        (
            JsonReader reader,
            Type objectType,
            object existingValue,
            JsonSerializer serializer
        )
        {
            MenuFile menu = (MenuFile)existingValue;
            NonNullCollection <MenuEntry> entries = serializer
                                                    .Deserialize <NonNullCollection <MenuEntry> >
                                                    (
                reader
                                                    );

            menu.Entries.AddRange(entries);

            return(menu);
        }
Example #30
0
        /// <inheritdoc cref="IHandmadeSerializable.RestoreFromStream" />
        public void RestoreFromStream
        (
            BinaryReader reader
        )
        {
            Sure.NotNull(reader, nameof(reader));

            Actualize        = reader.ReadBoolean();
            Autoin           = reader.ReadBoolean();
            Database         = reader.ReadNullableString();
            FileName         = reader.ReadNullableString();
            FirstRecord      = reader.ReadPackedInt32();
            FormalControl    = reader.ReadBoolean();
            MaxMfn           = reader.ReadPackedInt32();
            MfnList          = reader.ReadNullableInt32Array();
            MinMfn           = reader.ReadPackedInt32();
            NumberOfRecords  = reader.ReadPackedInt32();
            SearchExpression = reader.ReadNullableString();
            Statements       = reader.ReadNonNullCollection <GblStatement>();
        }
        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);
        }
Example #32
0
        private static void _WriteLevel
        (
            TextWriter writer,
            NonNullCollection <Item> items,
            int level
        )
        {
            foreach (Item item in items)
            {
                for (int i = 0; i < level; i++)
                {
                    writer.Write(Indent);
                }
                writer.WriteLine(item.Value);

                _WriteLevel
                (
                    writer,
                    item.Children,
                    level + 1
                );
            }
        }
Example #33
0
        public void NonNullCollection_Unit_Insert_Optimal()
        {
            NonNullCollection<String> target = new NonNullCollection<String>();
            Int32 index = 0;
            String item = "Test";

            target.Insert(index, item);
            CollectionAssert.Contains(target, item);
        }
Example #34
0
        public void NonNullCollection_Unit_Indexer_ValueIsNull()
        {
            IList<String> list = new List<String>() { "One", "Two", "Three" };
            NonNullCollection<String> target = new NonNullCollection<String>(list);
            String value = null;

            target[0] = value;
        }
Example #35
0
        public void NonNullCollection_Unit_Insert_ItemIsNull()
        {
            NonNullCollection<String> target = new NonNullCollection<String>();
            Int32 index = 0;
            String item = null;

            target.Insert(index, item);
        }
Example #36
0
        public void NonNullCollection_Unit_Indexer_Optimal()
        {
            IList<String> list = new List<String>() { "One", "Two", "Three" };
            NonNullCollection<String> target = new NonNullCollection<String>(list);
            String value = "Test";

            target[0] = value;
            Assert.AreEqual(value, target[0]);
        }