public void Return_False_For_End_time_Before_Start_time_Using_Greater_Than()
        {
            var testDict = new Dictionary <string, string>
            {
                { "startTime", "11/7/2018" },
                { "stopTime", "9/7/2018" }
            };

            var formData = new FormData(testDict);

            var settings = new Dictionary <string, string>
            {
                { "FieldToCompareWith", "stopTime" },
                { "CompareOperator", "<" }
            } as IDictionary <string, string>;
            var ctx = new ContextFor <DateTimeComparisonCheck>();

            ctx.Use(settings);
            ctx.Use <Func <FormData> >(() => formData);
            var sut = ctx.BuildSut();

            formData.Values.TryGetValue("stopTime", out var result);
            var res = sut.Validate(result, default(DateTime));

            res.IsValid.Should().BeFalse();
        }
        public void Return_True_For_Start_time_Before_End_time_Using_Greater_Than()
        {
            var testDict = new Dictionary <string, string>
            {
                { "startTime", "8/7/2018" },
                { "stopTime", "9/7/2018" }
            };

            var formData = new FormData(testDict);

            var settings = new Dictionary <string, string>
            {
                { "FieldToCompareWith", "stopTime" },
                { "CompareOperator", "<" },
                { "SpecificDateTimeFormats", "d/M/yyyy" }
            } as IDictionary <string, string>;
            var ctx = new ContextFor <DateTimeComparisonCheck>();

            ctx.Use(settings);
            ctx.Use <Func <FormData> >(() => formData);
            var sut = ctx.BuildSut();

            // we compare 'startTime' as base with 'stopTime' as remove field
            formData.Values.TryGetValue("startTime", out var result);
            var res = sut.Validate(result, default(DateTime));

            res.IsValid.Should().BeTrue();
            res.Exception.Should().BeNull();
        }
        public void Return_True_For_Start_time_Before_End_time_Using_Smaller_Than_With_Specific_Formats()
        {
            var testDict = new Dictionary <string, string>
            {
                { "startTime", "11:00" },
                { "stopTime", "11:30" }
            };

            var formData    = new FormData(testDict);
            var testFormats = new[] { "HHmm", "HHmmss", "HH:mm", "HH:mm:ss" };

            var settings = new Dictionary <string, string>
            {
                { "FieldToCompareWith", "stopTime" },
                { "CompareOperator", "<" },
                { "SpecificDateTimeFormats", string.Join("|", testFormats) }
            } as IDictionary <string, string>;
            var ctx = new ContextFor <DateTimeComparisonCheck>();

            ctx.Use(settings);
            ctx.Use <Func <FormData> >(() => formData);
            var sut = ctx.BuildSut();

            //var dateTimeCheck = new DateTimeComparisonCheck("lorem ipsum", "<", "stopTime", () => formData, tableDataSerializer, specificDateTimeFormats: testFormats);
            formData.Values.TryGetValue("startTime", out var result);
            var res = sut.Validate(result, default(DateTime));

            res.IsValid.Should().BeTrue();
        }
        public void Return_False_Use_TableKey_And_Row_Index_For_InterTable_Comparison()
        {
            var testDict = new Dictionary <string, string>
            {
                { "startTime", "8/7/2018" },
                { "theTable", "foobar" }
            };
            var formData   = new FormData(testDict);
            var serializer = Substitute.For <INZazuTableDataSerializer>();

            serializer.Deserialize("foobar").Returns(new Dictionary <string, string> {
                { "stopTime__0", "10/10/2018" }
            });
            var settings = new Dictionary <string, string>
            {
                { "FieldToCompareWith", "stopTime" },
                { "CompareOperator", ">" },
                { "SpecificDateTimeFormats", "d/M/yyyy" },
                { "TableKey", "theTable" }
            } as IDictionary <string, string>;
            var ctx = new ContextFor <DateTimeComparisonCheck>();

            ctx.Use(settings);
            ctx.Use(serializer);
            ctx.Use <Func <FormData> >(() => formData);
            var sut = ctx.BuildSut();

            formData.Values.TryGetValue("startTime", out var result);
            var res = sut.Validate(result, default(DateTime));

            res.IsValid.Should().BeFalse();
        }
        public void Return_False_If_Cannot_Parse_CompareWith_Date()
        {
            var testDict = new Dictionary <string, string>
            {
                { "startTime", "9/7/2018" },
                { "stopTime", "cannot parse" }
            };
            var formData = new FormData(testDict);
            var settings = new Dictionary <string, string>
            {
                { "FieldToCompareWith", "stopTime" },
                { "CompareOperator", "<" },
                { "SpecificDateTimeFormats", "d/M/yyyy" }
            } as IDictionary <string, string>;
            var ctx = new ContextFor <DateTimeComparisonCheck>();

            ctx.Use(settings);
            ctx.Use <Func <FormData> >(() => formData);
            var sut = ctx.BuildSut();

            formData.Values.TryGetValue("startTime", out var result);
            var res = sut.Validate(result, default(DateTime));

            res.IsValid.Should().BeFalse();
            res.Exception.Message.Should().Be("Cannot parse 'compareWith' value to datetime.");
        }
        public void Use_Compare_Strategy(string start, string end, string compare, bool expected)
        {
            var testDict = new Dictionary <string, string>
            {
                { "startTime", start },
                { "stopTime", end }
            };

            var formData = new FormData(testDict);

            var settings = new Dictionary <string, string>
            {
                { "FieldToCompareWith", "stopTime" },
                { "CompareOperator", compare }
            } as IDictionary <string, string>;
            var ctx = new ContextFor <DateTimeComparisonCheck>();

            ctx.Use(settings);
            ctx.Use <Func <FormData> >(() => formData);
            var sut = ctx.BuildSut();

            formData.Values.TryGetValue("startTime", out var result);
            var res = sut.Validate(result, default(DateTime));

            res.IsValid.Should().Be(expected);
        }
        public void Use_full_volume_and_center_balance_on_sampling()
        {
            var ctx          = new ContextFor <NAudioGetWaveform>();
            var peakProvider = new PeakProvider();

            ctx.Use <IPeakProvider>(peakProvider);
            var sut = ctx.BuildSut();

            var waveFormat = WaveFormat.CreateIeeeFloatWaveFormat(8000, 1);

            using (var buffer = new BufferedWaveStream(waveFormat, TimeSpan.FromSeconds(1)))
                using (var waveStream = new WaveProviderEx(buffer))
                {
                    var source = new Uri("my://source/");
                    ctx.For <IWaveProviderFactory>().Create(source).Returns(waveStream);

                    waveStream.Position = 40;
                    waveStream.Volume   = 0.5f;
                    waveStream.Pan      = -1f;

                    var samples = waveFormat.Generate(buffer.BufferDuration, SignalGeneratorType.Square);
                    buffer.AddSamples(samples, 0, samples.Length);

                    var waveForm = sut.For(source);
                    waveForm.Duration.Should().Be(buffer.BufferDuration);
                    waveForm.Peaks.Should().HaveCount((int)(peakProvider.PeaksPerSecond * buffer.BufferDuration.TotalSeconds));
                    waveForm.Peaks.All(p => p.Max == 1f && p.Min == -1f).Should().BeTrue();

                    waveStream.Position.Should().Be(40, "should be restored after sampling");
                    waveStream.Volume.Should().Be(0.5f);
                    waveStream.Pan.Should().Be(-1f);
                }
        }
Beispiel #8
0
        public void Support_absolute_audio_time()
        {
            var ctx       = new ContextFor <WaveformPlayerViewModel>();
            var formatter = new DateTimeFormatter("yyyy-MM-dd HH:mm:ss");

            ctx.Use <IAbsoluteTimeFormatter>(formatter);
            var sut = ctx.BuildSut();

            sut.StartTime.Should().BeNull("no start time by default");
            sut.HasCurrentTime.Should().BeFalse();
            sut.CurrentTime.Should().BeNullOrWhiteSpace();

            var d = DateTimeOffset.UtcNow;

            sut.StartTime = d;
            sut.HasCurrentTime.Should().BeTrue();
            var expected = formatter.Format(d);

            sut.CurrentTime.Should().Be(expected);

            var position = TimeSpan.FromSeconds(sut.Player.Duration);

            sut.Player.Position = position.TotalSeconds;

            expected = formatter.Format(d + position);
            sut.CurrentTime.Should().Be(expected);
        }
        public void Be_Creatable()
        {
            var settings = new Dictionary <string, string>
            {
                { "FieldToCompareWith", "stopTime" },
                { "CompareOperator", "<" }
            } as IDictionary <string, string>;
            var formData = new FormData();

            var ctx = new ContextFor <DateTimeComparisonCheck>();

            ctx.Use(settings);
            ctx.Use <Func <FormData> >(() => formData);

            var sut = ctx.BuildSut();

            sut.Should().NotBeNull();
            sut.GetType().GetCustomAttribute <DisplayNameAttribute>().DisplayName.Should().Be("datetime");
        }
Beispiel #10
0
        public void Be_Creatable()
        {
            var ctx = new ContextFor <BlackList <string> >();

            ctx.Use(10);
            var sut = ctx.BuildSut();

            sut.Should().NotBeNull();
            sut.Should().BeAssignableTo <IBlackList <string> >();
        }
Beispiel #11
0
        public void Read_JToken_From_Response()
        {
            var ctx = new ContextFor <ElasticSearchSuggestions>();

            ctx.Use(new[] { "author" });
            var sut = ctx.BuildSut();

            var items = sut.GetSuggestions(TestData.Hits, "Tho").ToArray();

            items.Should().Equal("Thomate", "Thomas", "Thomas Smith");
            items.Should().NotContain("Horst");
        }
        public void Return_True_For_Start_time_Before_End_time_Using_Smaller_Than_Within_A_Table_field()
        {
            const string tableData = "\"columnStartRow__1\":\"11:00\",\"columnStopRow__1\":\"12:00\"";
            var          testDict  = new Dictionary <string, string>
            {
                { "tableKey", tableData }
            };

            var formData            = new FormData(testDict);
            var tableDataSerializer = Substitute.For <INZazuTableDataSerializer>();

            tableDataSerializer.Deserialize(tableData)
            .Returns(new Dictionary <string, string>
            {
                { "columnStartRow__1", "11:00" },
                { "columnStopRow__1", "12:00" }
            });

            var testFormats = new[] { "HHmm", "HHmmss", "HH:mm", "HH:mm:ss" };

            var settings = new Dictionary <string, string>
            {
                { "FieldToCompareWith", "stopTime" },
                { "CompareOperator", "<" },
                { "SpecificDateTimeFormats", string.Join("|", testFormats) }
            } as IDictionary <string, string>;
            var ctx = new ContextFor <DateTimeComparisonCheck>();

            ctx.Use(settings);
            ctx.Use <Func <FormData> >(() => formData);
            var sut = ctx.BuildSut();

            //var dateTimeCheck = new DateTimeComparisonCheck(
            //    "lorem ipsum", "<", "columnStopRow", () => formData, tableDataSerializer,
            //    tableKey: "tableKey", specificDateTimeFormats: testFormats, rowIdx: 1);
            var res = sut.Validate("11:00", default(DateTime));

            res.IsValid.Should().BeTrue();
        }
Beispiel #13
0
        public void IsValid_InsideMinMax_passes()
        {
            var settings = new Dictionary <string, string> {
                { "Min", "2" }, { "Max", "42" }
            } as IDictionary <string, string>;
            var ctx = new ContextFor <RangeCheck>();

            ctx.Use(settings);
            var sut = ctx.BuildSut();

            Enumerable.Range(2, 40)
            .ToList().ForEach(x => sut.ShouldPass(x, x.ToString()));
        }
        public void Be_Creatable()
        {
            var settings = new Dictionary <string, string> {
                { "Min", "2" }, { "Max", "6" }
            } as IDictionary <string, string>;
            var ctx = new ContextFor <StringLengthCheck>();

            ctx.Use(settings);
            var sut = ctx.BuildSut();

            sut.Should().NotBeNull();
            sut.GetType().GetCustomAttribute <DisplayNameAttribute>().DisplayName.Should().Be("length");
        }
        public void Ctor_with_min_only_should_set_max_to_int_maxvalue()
        {
            var settings = new Dictionary <string, string> {
                { "Min", "4" }
            } as IDictionary <string, string>;
            var ctx = new ContextFor <StringLengthCheck>();

            ctx.Use(settings);
            var sut = ctx.BuildSut();

            sut.Settings.MinInt.Should().Be(4);
            sut.Settings.MaxInt.Should().Be(int.MaxValue);
        }
        public void IsValid_AboveMax_fails()
        {
            var settings = new Dictionary <string, string> {
                { "Min", "2" }, { "Max", "42" }
            } as IDictionary <string, string>;
            var ctx = new ContextFor <StringLengthCheck>();

            ctx.Use(settings);
            var sut = ctx.BuildSut();

            var candidate = new string('A', 100);

            sut.ShouldFailWith <ArgumentException>(candidate, candidate);
        }
Beispiel #17
0
        public void Be_Creatable()
        {
            var settings =
                new Dictionary <string, string>
            {
                { "Hint", "this is the hint" }, { "RegEx", "false|true" }
            } as IDictionary <string, string>;
            var ctx = new ContextFor <StringRegExCheck>();

            ctx.Use(settings);
            var sut = ctx.BuildSut();

            sut.Should().NotBeNull();
            sut.GetType().GetCustomAttribute <DisplayNameAttribute>().DisplayName.Should().Be("regex");
        }
Beispiel #18
0
        public void Be_Creatable()
        {
            var settings = new Dictionary <string, string>
            {
                { "Hint", "this is the hint" },
                { "LeftFieldName", "leftField" },
                { "RightFieldName", "rightField" }
            } as IDictionary <string, string>;

            var ctx = new ContextFor <GreaterThanFormCheck>();

            ctx.Use(settings);
            var sut = ctx.BuildSut();

            sut.Should().NotBeNull();
        }
Beispiel #19
0
        public void IsValid_null_or_whitespace_should_pass()
        {
            var settings =
                new Dictionary <string, string>
            {
                { "Hint", "Must be true or false" }, { "RegEx", "true|false" }
            } as IDictionary <string, string>;
            var ctx = new ContextFor <StringRegExCheck>();

            ctx.Use(settings);
            var sut = ctx.BuildSut();

            sut.ShouldPass(null, null);
            sut.ShouldPass(string.Empty, string.Empty);
            sut.ShouldPass("\t\r\n", "\t\r\n");
            sut.ShouldPass(" ", " ");
        }
Beispiel #20
0
        public void Clear()
        {
            var ctx = new ContextFor <BlackList <string> >();

            ctx.Use(10);
            var sut = ctx.BuildSut();

            sut.Push("foo");
            sut.Push("bar");

            sut.Clear();
            sut.Count.Should().Be(0);
            sut.ToString().Should().Contain("Cur/Max = 0/10");

            sut.Pop("foo").Should().BeFalse();
            sut.Pop("bar").Should().BeFalse();
            sut.Pop("hugo").Should().BeFalse();
        }
Beispiel #21
0
        public void EmailChecks()
        {
            var settings =
                new Dictionary <string, string>
            {
                { "Hint", "Not a valid e-mail" }, { "RegEx", @"^.+@.+\..+$" }
            } as IDictionary <string, string>;
            var ctx = new ContextFor <StringRegExCheck>();

            ctx.Use(settings);
            var sut = ctx.BuildSut();

            sut.ShouldPass("*****@*****.**", "*****@*****.**");
            sut.ShouldFailWith <ArgumentException>("@domain.com", null);        // missing account prefix
            sut.ShouldFailWith <ArgumentException>("joe.doe_domain.com", null); // missing separator '@'
            sut.ShouldFailWith <ArgumentException>("joe.doe@", null);           // missing domain
            sut.ShouldFailWith <ArgumentException>("joe.doe@domain_de", null);  // missing domain separator '.'
        }
        public void Query_On_For()
        {
            var ctx = new ContextFor <ElasticSearchSuggestions>();

            ctx.Use("http://127.0.0.1:9200", "connectionPrefix");
            ctx.For <IRestClient>()
            .Request(HttpMethod.Post, "_search", Arg.Any <JToken>())
            .Returns(TestData.Hits);
            var sut = ctx.BuildSut();

            var items = sut.For("Tho", "elasticsearch://nzazu/autocomplete|director").ToArray();

            items.Should().Equal("Thomate", "Thomas", "Thomas Smith");
            items.Should().NotContain("Horst");

            items = sut.For("Tho", "elasticsearch://nzazu/autocomplete|director").ToArray();
            items.Should().Equal("Thomate", "Thomas", "Thomas Smith");
            items.Should().NotContain("Horst");
        }
Beispiel #23
0
        public void IpAddressChecks()
        {
            var settings = new Dictionary <string, string>
            {
                { "Hint", "Not a valid ip." }, { "RegEx", @"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$" }
            } as
            IDictionary <string, string>;
            var ctx = new ContextFor <StringRegExCheck>();

            ctx.Use(settings);
            var sut = ctx.BuildSut();

            sut.ShouldPass("1.1.1.1", "1.1.1.1");
            sut.ShouldPass("22.22.22.22", "22.22.22.22");
            sut.ShouldPass("333.333.333.333",
                           "333.333.333.333");                         // actually this is not a valid IP address. However, we check the RegEx here!

            sut.ShouldFailWith <ArgumentException>("1.1.11", 0);       // missing separator
            sut.ShouldFailWith <ArgumentException>("1.22.33.4444", 0); // field with 4 digits
        }
Beispiel #24
0
        public void Push_And_Pop()
        {
            var ctx = new ContextFor <BlackList <string> >();

            ctx.Use(10);
            var sut = ctx.BuildSut();

            sut.Push("foo");
            sut.Push("bar");
            sut.Count.Should().Be(2);

            sut.Push("bar");
            sut.Count.Should().Be(2);

            sut.Pop("foo").Should().BeTrue();
            sut.Count.Should().Be(1);

            sut.Pop("bar").Should().BeTrue();
            sut.Count.Should().Be(0);

            sut.Pop("bar").Should().BeFalse();
            sut.Pop("hugo").Should().BeFalse();
        }