Ejemplo n.º 1
0
        public void TestClone([ValueSource(nameof(Ranges))] SpecialDateTimeInterval range,
                              [ValueSource(nameof(Modes))] TimeFilterMode mode,
                              [ValueSource(nameof(DateTimes))] DateTime?start,
                              [ValueSource(nameof(DateTimes))] DateTime?end)
        {
            var filter = new TimeFilterSettings
            {
                Mode            = mode,
                SpecialInterval = range,
                Minimum         = start,
                Maximum         = end
            };

            var clone = filter.Clone();

            clone.SpecialInterval.Should().Be(range);
            clone.Minimum.Should().Be(start);
            clone.Maximum.Should().Be(end);
        }
Ejemplo n.º 2
0
        public void TestStoreRestore([ValueSource(nameof(Modes))] TimeFilterMode mode,
                                     [ValueSource(nameof(Ranges))] SpecialDateTimeInterval range,
                                     [ValueSource(nameof(DateTimes))] DateTime?start,
                                     [ValueSource(nameof(DateTimes))] DateTime?end)
        {
            using (var stream = new MemoryStream())
            {
                using (var writer = XmlWriter.Create(stream))
                {
                    writer.WriteStartElement("Test");
                    var settings = new TimeFilterSettings
                    {
                        Mode            = mode,
                        SpecialInterval = range,
                        Minimum         = start,
                        Maximum         = end
                    };
                    settings.Save(writer);
                    writer.WriteEndElement();
                }

                stream.Position = 0;
                //Console.WriteLine(Encoding.UTF8.GetString(stream.ToArray()));

                using (var reader = XmlReader.Create(stream))
                {
                    reader.MoveToContent();

                    var settings = new TimeFilterSettings();
                    settings.Restore(reader);
                    settings.Mode.Should().Be(mode);
                    settings.SpecialInterval.Should().Be(range);
                    settings.Minimum.Should().Be(start);
                    settings.Maximum.Should().Be(end);
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Restores this filter from the given xml reader.
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        public bool Restore(XmlReader reader)
        {
            var count = reader.AttributeCount;

            for (var i = 0; i < count; ++i)
            {
                reader.MoveToAttribute(i);

                switch (reader.Name)
                {
                case "mode":
                    if (Enum.TryParse(reader.Value, ignoreCase: true, result: out TimeFilterMode mode))
                    {
                        Mode = mode;
                    }
                    break;

                case "range":
                    if (Enum.TryParse(reader.Value, ignoreCase: true, result: out SpecialDateTimeInterval range))
                    {
                        SpecialInterval = range;
                    }
                    break;

                case "start":
                    Minimum = reader.ReadContentAsDateTime2();
                    break;

                case "end":
                    Maximum = reader.ReadContentAsDateTime2();
                    break;
                }
            }

            return(true);
        }