Exemplo n.º 1
0
        public void Convert_LessThanEquals_ValueIsGreaterThan_FalseValue()
        {
            var valueAndLimit = new Dictionary <object, object>
            {
                { "", "1" },
                { "a", "b" },
                { -1, 0 }, { 0, 1 }, { 1, 2 },
                { 0U, 1U }, { 1U, 2U },
                { -1.0, -0.99 }, { 0.0, 0.01 }, { 1.0, 1.01 },
                { -1.0M, -0.99M }, { 0.0M, 0.01M }, { 1.0M, 1.01M },
                { new DateTime(), new DateTime().AddMilliseconds(1) },
                { DateTime.Parse("2000-01-01"), DateTime.Parse("2000-01-01 00:00:00.001") },
                { new TimeSpan(), new TimeSpan(0, 0, 0, 0, 1) },
                { TimeSpan.Parse("00:00:01"), TimeSpan.Parse("00:00:01.001") },
                { System.IO.SeekOrigin.Begin, System.IO.SeekOrigin.Current },
                { new Version(0, 0, 800, 130), new Version(1, 0, 15, 0) },
                { new Version(1, 0, 0, 0), new Version(1, 1, 0, 0) }
            };


            var sut = new InRangeConverter
            {
                TrueValue  = true,
                FalseValue = false,
            };

            foreach (var pair in valueAndLimit)
            {
                sut.To = pair.Key;
                var actual = sut.Convert(pair.Value, typeof(object), null, CultureInfo.CurrentCulture);
                Assert.AreEqual(sut.FalseValue, actual);
            }
        }
Exemplo n.º 2
0
        public void Convert_LessThan_ValueIsEquals_FalseValue()
        {
            var valueAndLimit = new Dictionary <object, object>
            {
                { "", "" },
                { "a", "a" },
                { -1, -1 }, { 0, 0 }, { 1, 1 },
                { 0U, 0U }, { 1U, 1U },
                { -1.0, -1.0 }, { 0.0, 0.0 }, { 1.0, 1.0 },
                { -1.0M, -1.0M }, { 0.0M, 0.0M }, { 1.0M, 1.0M },
                { new DateTime(), new DateTime() },
                { DateTime.Parse("2000-01-01"), DateTime.Parse("2000-01-01 00:00:00.000") },
                { new TimeSpan(), new TimeSpan(0, 0, 0, 0, 0) },
                { TimeSpan.Parse("00:00:01"), TimeSpan.Parse("00:00:01.000") },
                { System.IO.SeekOrigin.Begin, System.IO.SeekOrigin.Begin },
                { new Version(1, 0, 15, 0), new Version(1, 0, 15, 0) },
                { new Version(1, 0, 0, 0), new Version(1, 0, 0, 0) }
            };

            var sut = new InRangeConverter
            {
                TrueValue  = true,
                FalseValue = false,
            };

            foreach (var pair in valueAndLimit)
            {
                sut.Before = pair.Key;
                var actual = sut.Convert(pair.Value, typeof(object), null, CultureInfo.CurrentCulture);
                Assert.AreEqual(sut.FalseValue, actual);
            }
        }
Exemplo n.º 3
0
        public void ComparableClassHierarcy()
        {
            var sut = new InRangeConverter
            {
                From = new RegularEmplopyee {
                    WorkStartDate = DateTime.Parse("2016-01-01")
                },
                To = new VP {
                    WorkStartDate = DateTime.Parse("2016-01-01")
                }
            };
            var value = new Manager {
                WorkStartDate = DateTime.Parse("2016-01-01")
            };

            var actual = sut.Convert(value, typeof(object), null, CultureInfo.CurrentCulture);

            Assert.AreEqual(true, actual);
        }
Exemplo n.º 4
0
        public void ConvertNull_NullableSupported_AndCustomNullValue_NullValue()
        {
            var valueAndLimit = new object[][]
            {
                new object[] { null, "1", "2" },
                new object[] { null, "a", "c" },
                new object[] { null, 0, 1 },
                new object[] { null, 1, 2 },
                new object[] { null, 2, 3 },
                new object[] { null, 1U, 2U },
                new object[] { null, 2U, 3U },
                new object[] { null, -0.99, -0.1 },
                new object[] { null, 0.01, 0.1 },
                new object[] { null, 1.01, 1.02 },
                new object[] { null, -0.99M, -0.1M },
                new object[] { null, 0.01M, 0.1M },
                new object[] { null, 1.01M, 1.1M },
                new object[] { null, new DateTime().AddMilliseconds(1), new DateTime().AddMilliseconds(2) },
                new object[] { null, DateTime.Parse("2000-01-01 00:00:00.001"), DateTime.Parse("2000-01-01 00:00:00.002") },
                new object[] { null, new TimeSpan(0, 0, 0, 0, 1), new TimeSpan(0, 0, 0, 0, 2) },
                new object[] { null, TimeSpan.Parse("00:00:01.001"), TimeSpan.Parse("00:00:01.002") },
                new object[] { null, System.IO.SeekOrigin.Current, System.IO.SeekOrigin.End },
                new object[] { null, new Version(1, 0, 15, 0), new Version(2, 0, 0, 0) },
                new object[] { null, new Version(1, 1, 0, 0), new Version(1, 1, 0, 1) }
            };

            object expected = System.IO.SeekOrigin.Current;
            var    sut      = new InRangeConverter
            {
                FalseValue = "False",
                TrueValue  = "True",
                NullValue  = expected
            };

            foreach (var values in valueAndLimit)
            {
                sut.From = values[1];
                sut.To   = values[2];
                var actual = sut.Convert(values[0], typeof(object), null, CultureInfo.CurrentCulture);
                Assert.AreEqual(expected, actual);
            }
        }
Exemplo n.º 5
0
        public void ConvertNotInRange_IsNegative_TrueValue()
        {
            var valueAndLimit = new object[][]
            {
                new object[] { "", "1", "2" },
                new object[] { "a", "b", "c" },
                new object[] { -1, 0, 1 },
                new object[] { 0, 1, 2 },
                new object[] { 1, 2, 3 },
                new object[] { 0U, 1U, 2U },
                new object[] { 1U, 2U, 3U },
                new object[] { -1.0, -0.99, -0.1 },
                new object[] { 0.0, 0.01, 0.1 },
                new object[] { 1.0, 1.01, 1.02 },
                new object[] { -1.0M, -0.99M, -0.1M },
                new object[] { 0.0M, 0.01M, 0.1M },
                new object[] { 1.0M, 1.01M, 1.1M },
                new object[] { new DateTime(), new DateTime().AddMilliseconds(1), new DateTime().AddMilliseconds(2) },
                new object[] { DateTime.Parse("2000-01-01"), DateTime.Parse("2000-01-01 00:00:00.001"), DateTime.Parse("2000-01-01 00:00:00.002") },
                new object[] { new TimeSpan(), new TimeSpan(0, 0, 0, 0, 1), new TimeSpan(0, 0, 0, 0, 2) },
                new object[] { TimeSpan.Parse("00:00:01"), TimeSpan.Parse("00:00:01.001"), TimeSpan.Parse("00:00:01.002") },
                new object[] { System.IO.SeekOrigin.Begin, System.IO.SeekOrigin.Current, System.IO.SeekOrigin.End },
                new object[] { new Version(0, 0, 800, 130), new Version(1, 0, 15, 0), new Version(2, 0, 0, 0) },
                new object[] { new Version(1, 0, 0, 0), new Version(1, 1, 0, 0), new Version(1, 1, 0, 1) }
            };

            var expected = "ConvertNotInRange_IsNegative_TrueValue";
            var sut      = new InRangeConverter
            {
                IsNegative = true,
                TrueValue  = expected,
            };

            foreach (var values in valueAndLimit)
            {
                sut.From = values[1];
                sut.To   = values[2];
                var actual = sut.Convert(values[0], typeof(object), null, CultureInfo.CurrentCulture);
                Assert.AreEqual(expected, actual);
            }
        }