static CommonValueConversion() { ValueConverters.Add(new NonConversionStep()); ValueConverters.Add(new SpecialTypesStep()); ValueConverters.Add(new EnumStep()); ValueConverters.Add(new ConverterStep()); }
public void CanAddConvertFuncByTargetType() { // Register a converter by target type when you want all properties of the // target type to use the same converter. // Call the Add method for each converter that needs to be registered. var first = new ValueConverters(); first.Add(typeof(Bar), value => new Bar(int.Parse(value))); first.Add(typeof(Baz), ParseBaz); // The Add method returns 'this', so you can chain them together: var second = new ValueConverters() .Add(typeof(Bar), value => new Bar(int.Parse(value))) .Add(typeof(Baz), ParseBaz); // List initialization syntax works also. var third = new ValueConverters { { typeof(Bar), value => new Bar(int.Parse(value)) }, { typeof(Baz), ParseBaz } }; // All three instances represent the same thing. Verify that their // contents are the same. // ValueConverters implements IEnumerable<KeyValuePair<string, Type>> var firstList = first.ToList(); var secondList = second.ToList(); var thirdList = third.ToList(); Assert.Equal(firstList.Count, secondList.Count); Assert.Equal(secondList.Count, thirdList.Count); for (int i = 0; i < firstList.Count; i++) { Assert.Equal(firstList[i].Key, secondList[i].Key); Assert.Equal(firstList[i].Value, secondList[i].Value); Assert.Equal(secondList[i].Key, thirdList[i].Key); Assert.Equal(secondList[i].Value, thirdList[i].Value); } }
public void GivenReturnTypeOfFunctionIsNotAssignableToTargetType_ThrowsArgumentException() { var valueConverters = new ValueConverters(); var actual = Assert.Throws <ArgumentException>(() => valueConverters.Add(typeof(Bar), value => new Qux())); #if DEBUG var expected = Exceptions.ReturnTypeOfConvertFuncIsNotAssignableToTargetType(typeof(Bar), typeof(Qux)); Assert.Equal(expected.Message, actual.Message); #endif }
public void GivenNoMatchingMembers_ThrowsArgumentException() { var valueConverters = new ValueConverters(); var actual = Assert.Throws <ArgumentException>(() => valueConverters.Add(typeof(Foo), "qux", value => new Bar(int.Parse(value)))); #if DEBUG var expected = Exceptions.NoMatchingMembers(typeof(Foo), "qux"); Assert.Equal(expected.Message, actual.Message); #endif }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { base.OnConfiguring(optionsBuilder); optionsBuilder.UseSqlServer(ConnectionString); optionsBuilder.UseLoggerFactory(Logger); // Magically make queries faster! optionsBuilder.AddInterceptors(new SpeedInterceptor()); // Always use bigint for TimeSpan columns. ValueConverters.Add(typeof(TimeSpan), new TimeSpanToTicksConverter()); }
public void GivenReturnTypeOfFunctionIsNotAssignableToMemberType_ThrowsArgumentException() { var valueConverters = new ValueConverters(); var actual = Assert.Throws <ArgumentException>(() => valueConverters.Add(typeof(Foo), "bar", value => new Qux())); #if DEBUG var expected = Exceptions.ReturnTypeOfConvertFuncNotAssignableToMembers(typeof(Foo), "bar", typeof(Qux), new List <Member> { new Member("Bar", typeof(Bar), MemberType.Property) }); Assert.Equal(expected.Message, actual.Message); #endif }
public void GivenNullConvertFunc2_ThrowsArgumentNullException() { var valueConverters = new ValueConverters(); Assert.Throws <ArgumentNullException>(() => valueConverters.Add <Bar>(typeof(Bar), null)); }
public void GivenNullTargetType_ThrowsArgumentNullException() { var valueConverters = new ValueConverters(); Assert.Throws <ArgumentNullException>(() => valueConverters.Add(null, value => new Bar(int.Parse(value)))); }
public void GivenNullMemberName_ThrowsArgumentNullException() { var valueConverters = new ValueConverters(); Assert.Throws <ArgumentNullException>(() => valueConverters.Add(typeof(Foo), null, value => new Bar(int.Parse(value)))); }
public SqlDataTableFactory(ISqlTableDefinitionGenerator tableDefinitionGenerator) : base(tableDefinitionGenerator) { ValueConverters.Add(new TimespanToTicksConverter()); }
{ ///<inheritdoc cref="DataSetFactory" /> /// <summary> /// Default implementation of DataSetFactory using IPostgresTableDefinitionGenerator /// </summary> public PostgresDataSetFactory(IPostgresTableDefinitionGenerator tableDefinitionGenerator) : base(tableDefinitionGenerator) { ValueConverters.Add(new TimespanToTicksConverter()); }