Skip to content

Instantly share code, notes, and snippets.

@robashton
Created December 3, 2010 14:27
Show Gist options
  • Save robashton/727014 to your computer and use it in GitHub Desktop.
Save robashton/727014 to your computer and use it in GitHub Desktop.
This is the test
[TestFixture]
public class WhenCreatedTypeHasBaseTypes
{
IGenerationSession mSession;
[SetUp]
public void Setup()
{
mSession = AutoPocoContainer.Configure(x =>
{
x.Conventions(c =>
{
c.UseDefaultConventions();
});
x.Include<ISimpleInterface>()
.Setup(c => c.InterfaceValue).Value("Interface")
.Setup(c=>c.OtherInterfaceValue).Value("Interface");
x.Include<SimpleBaseClass>()
.Setup(c => c.BaseProperty).Value("Test")
.Setup(c => c.BaseVirtualProperty).Value("Base");
x.Include<SimpleDerivedClass>()
.Setup(c => c.Name).Value("OtherTest")
.Setup(c => c.BaseVirtualProperty).Value("Derived")
.Setup(c => c.OtherInterfaceValue).Value("Derived")
.Setup(c => c.Name).Use<FirstNameSource>();
})
.CreateSession();
}
[Test]
public void DerivedType_HasInterfaceValue()
{
SimpleDerivedClass derivedClass = mSession.Single<SimpleDerivedClass>().Get();
Assert.AreEqual("Interface", derivedClass.InterfaceValue);
}
[Test]
public void DerivedType_HasOverrideInterfaceValue()
{
SimpleDerivedClass derivedClass = mSession.Single<SimpleDerivedClass>().Get();
Assert.AreEqual("Derived", derivedClass.OtherInterfaceValue);
}
[Test]
public void DerivedType_OverriddenMember_HasDerivedValue()
{
SimpleDerivedClass derivedClass = mSession.Single<SimpleDerivedClass>().Get();
Assert.AreEqual("Derived", derivedClass.BaseVirtualProperty);
}
[Test]
public void DerivedType_ContainsBaseValues()
{
SimpleDerivedClass derivedClass = mSession.Single<SimpleDerivedClass>().Get();
Assert.AreEqual("Test", derivedClass.BaseProperty);
}
}
public static class StandardExtensions
{
/// <summary>
/// Sets the value of a member directly
/// </summary>
public static IEngineConfigurationTypeBuilder<TPoco> Value<TPoco, TMember>(this IEngineConfigurationTypeMemberBuilder<TPoco, TMember> memberConfig,TMember value)
{
return memberConfig.Use<ValueSource<TMember>>(value);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment