コード例 #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);
        }
コード例 #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);
                }
            }
        }