public void ExactOk() { var convert = ConvertEx.Converter <int, int>(); Assert.Equal(2, convert(2)); Assert.Equal(0, convert(0)); Assert.Equal(5, convert(5)); var c1 = new Convert1 { A = "2" }; var convertClass = ConvertEx.Converter <Convert1, Convert1>(); Assert.Equal(c1, convertClass(c1)); Assert.True(ReferenceEquals(c1, convertClass(c1))); var c2 = new Convert2 { A = "2" }; Assert.Equal(c2, convertClass(c2)); Assert.True(ReferenceEquals(c2, convertClass(c2))); var convertClass2 = ConvertEx.Converter <Convert2, Convert2>(); Assert.Equal(c2, convertClass(c2)); Assert.True(ReferenceEquals(c2, convertClass(c2))); Assert.Null(convertClass(null)); Assert.Null(convertClass2(null)); }
public void CastOk() { var convert = ConvertEx.Converter <int, object>(); Assert.Equal(2, convert(2)); Assert.Equal(0, convert(0)); Assert.Equal(5, convert(5)); var c2 = new Convert2 { A = "2" }; var convertClass = ConvertEx.Converter <Convert2, Convert1>(); Assert.Equal(c2, convertClass(c2)); Assert.True(ReferenceEquals(c2, convertClass(c2))); Assert.Null(convertClass(null)); }
private static void ConvertOk <TSource, TResult>(TResult expected, TSource value) { Assert.Equal(expected, ConvertEx.Converter <TSource, TResult>()(value)); }