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)); }
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)); }
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)); }
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)); }
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); }
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); }