public void DefaultImplementationCanBeResolved() { var context = TomlSerializerContext.Create( TomlSerializerOptions.Default .AddDefaultImplementation <IInterface, DefaultImplementation>()); var implementation = context.GetDefaultImplementation(typeof(IInterface)); Assert.Equal(typeof(DefaultImplementation), implementation); }
public void TheLatterDefaultImplementationTakesPrecedence() { var context = TomlSerializerContext.Create( TomlSerializerOptions.Default .AddDefaultImplementation <IInterface, DefaultImplementation>() .AddDefaultImplementation <IInterface, OtherDefaultImplementation>()); var implementation = context.GetDefaultImplementation(typeof(IInterface)); Assert.Equal(typeof(OtherDefaultImplementation), implementation); }
public void OpenGenericDefaultImplementationCanBeResolved() { var context = TomlSerializerContext.Create( TomlSerializerOptions.Default .AddOpenGenericDefaultImplementation( typeof(IGeneric <>), @params => typeof(GenericImplementation <>).MakeGenericType(@params))); var implementation = context.GetDefaultImplementation(typeof(IGeneric <string>)); Assert.Equal(typeof(GenericImplementation <string>), implementation); }
public void DefaultImplementationCanBeResolvedThroughProvider() { var provider = Mock.Of <IDefaultImplementationProvider>( p => p.HasDefaultImplementation(typeof(string)) == true && p.GetDefaultImplementation(typeof(string)) == typeof(int)); var context = TomlSerializerContext.Create( TomlSerializerOptions.Default.AddDefaultImplementation(provider)); var implementation = context.GetDefaultImplementation(typeof(string)); Assert.Equal(typeof(int), implementation); }
public void NonSupportingDefaultImplementationProviderIsIgnored() { var nonSupportingProvider = Mock.Of <IDefaultImplementationProvider>( p => p.HasDefaultImplementation(It.IsAny <Type>()) == false); var context = TomlSerializerContext.Create( TomlSerializerOptions.Default .AddDefaultImplementation <IInterface, DefaultImplementation>() .AddDefaultImplementation(nonSupportingProvider)); var implementation = context.GetDefaultImplementation(typeof(IInterface)); Assert.Equal(typeof(DefaultImplementation), implementation); }
public void CreatingTheConverterForNewTypeWithNoSuitableConstructorThrows(Type typeToConvert) { var context = TomlSerializerContext.Create(TomlSerializerOptions.Default.AddNewTypeConverter()); Assert.Throws <TomlException>(() => context.GetConverter(typeToConvert)); }