예제 #1
0
        public void TryGetByTargetTypeReturnsFalseWhenThereNotIsAMatch()
        {
            var valueConverters = new ValueConverters();

            Assert.False(valueConverters.TryGet(typeof(Bar), out var convertBar));
            Assert.False(valueConverters.TryGet(typeof(Baz), out var convertBaz));
        }
예제 #2
0
        public void TryGetByDeclaringTypeAndMemberNameReturnsFalseWhenThereNotIsAMatch()
        {
            var valueConverters = new ValueConverters();

            Assert.False(valueConverters.TryGet(typeof(Foo), "bar", out var convertBar));
            Assert.False(valueConverters.TryGet(typeof(Foo), "baz", out var convertBaz));
        }
예제 #3
0
        public void TryGetByTargetTypeReturnsTrueWhenThereIsAMatch()
        {
            var valueConverters = new ValueConverters()
                                  .Add(typeof(Bar), value => new Bar(int.Parse(value)))
                                  .Add(typeof(Baz), ParseBaz);

            Assert.True(valueConverters.TryGet(typeof(Bar), out var convertBar));
            Assert.True(valueConverters.TryGet(typeof(Baz), out var convertBaz));
        }
예제 #4
0
        public void TryGetByDeclaringTypeAndMemberNameReturnsTrueWhenThereIsAMatch()
        {
            var valueConverters = new ValueConverters()
                                  .Add(typeof(Foo), "bar", value => new Bar(int.Parse(value)))
                                  .Add(typeof(Foo), "baz", ParseBaz);

            Assert.True(valueConverters.TryGet(typeof(Foo), "bar", out var convertBar));
            Assert.True(valueConverters.TryGet(typeof(Foo), "baz", out var convertBaz));
        }
예제 #5
0
        public void TheConvertFuncReturnedByTryGetCallsTheConvertFuncPassedToTheAddByDeclaringTypeAndMemberNameMethod()
        {
            var invocationCount = 0;
            Func <string, Bar> registeredConvertBar = value =>
            {
                invocationCount++;
                return(new Bar(int.Parse(value)));
            };

            var valueConverters = new ValueConverters()
                                  .Add(typeof(Foo), "bar", registeredConvertBar);

            Assert.True(valueConverters.TryGet(typeof(Foo), "bar", out var retrievedConvertBar));

            Assert.Equal(0, invocationCount);

            var converted = retrievedConvertBar("123");

            Assert.Equal(1, invocationCount);
            Assert.IsType <Bar>(converted);
            Assert.Equal(123, ((Bar)converted).Baz);
        }
예제 #6
0
        public void TheConvertFuncReturnedByTryGetCallsTheConvertFuncPassedToTheAddByTargetTypeMethod()
        {
            var invocationCount = 0;
            Func <string, Baz> registeredConvertBaz = value =>
            {
                invocationCount++;
                return(ParseBaz(value));
            };

            var valueConverters = new ValueConverters()
                                  .Add(typeof(Baz), registeredConvertBaz);

            Assert.True(valueConverters.TryGet(typeof(Baz), out var retrievedConvertBaz));

            Assert.Equal(0, invocationCount);

            var converted = retrievedConvertBaz("123.45,-76.543");

            Assert.Equal(1, invocationCount);
            Assert.IsType <Baz>(converted);
            Assert.Equal(123.45, ((Baz)converted).Latitude);
            Assert.Equal(-76.543, ((Baz)converted).Longitude);
        }