예제 #1
0
        public void GenerateFromInterface_BaseInterfaceOnlyHasAGetter_ShouldYieldAWorkingType()
        {
            var concrete = (NoSetter)ConcreteTypeGenerator.GetInstanceOf(typeof(NoSetter));

            concrete.X.Should().Be(0);
            concrete.GetType().GetProperties()[0].SetValue(concrete, 123, new object[0]);
            concrete.X.Should().Be(123);
        }
예제 #2
0
        public void GenerateFromInterface_BaseInterfaceHasAGetterAndSetter_ShouldYieldAWorkingType()
        {
            var concrete = (GetterAndSetter)ConcreteTypeGenerator.GetInstanceOf(typeof(GetterAndSetter));

            concrete.X = 123;
            concrete.X.Should().Be(123);

            concrete.X = 456;
            concrete.X.Should().Be(456);
        }
예제 #3
0
        public void GetTypeBuilder_WhenConcreteTypeIsCreated_ShouldCreateReasonableClassName()
        {
            var builder = ConcreteTypeGenerator.GetTypeBuilder(typeof(SomeBindableInterface));

            builder.FullName.Should().Be("SimpleConfig.Dynamic.InterfaceImplementations._SimpleConfig.Tests.TestTypes.SomeBindableInterface_Impl");
        }
예제 #4
0
        public void GetTypeBuilder_WhenConcreteTypeIsCreated_ShouldCreateAReasonableAssemblyName()
        {
            var builder = ConcreteTypeGenerator.GetTypeBuilder(typeof(SomeBindableInterface));

            builder.Assembly.FullName.Should().StartWith("SimpleConfig.Dynamic.InterfaceImplementations");
        }
예제 #5
0
 public void ValidateRequestedType_WhenTargetInterfaceContainsAWritableNoProperty_ShouldNotThrow()
 {
     ConcreteTypeGenerator.ValidateRequestedType(typeof(NoSetter));
 }
예제 #6
0
        public void ValidateRequestedType_WhenTargetInterfaceContainsANonReadableProperty_ShouldThrow()
        {
            Action x = () => ConcreteTypeGenerator.ValidateRequestedType(typeof(NoGetter));

            x.Should().Throw <ConfigMappingException>().WithMessage("write-only properties are not supported");
        }
예제 #7
0
        public void ValidateRequestedType_WhenTargetInterfaceContainsAMethod_ShouldThrow()
        {
            Action x = () => ConcreteTypeGenerator.ValidateRequestedType(typeof(WithMethod));

            x.Should().Throw <ConfigMappingException>().WithMessage("requested type may not have methods");
        }
예제 #8
0
        public void ValidateRequestedType_WhenTargetIsNotAnInterface_ShouldThrow()
        {
            Action x = () => ConcreteTypeGenerator.ValidateRequestedType(typeof(object));

            x.Should().Throw <ConfigMappingException>().WithMessage("requested type is not an interface");
        }
예제 #9
0
        public void TestConcreteTypeGeneratorClass()
        {
            DerivedClass c = ConcreteTypeGenerator.Get <DerivedClass>();

            Assert.NotNull(c);
        }