public static void RegisterTypes()
        {
            TypeConversion.Register <SerializedStringView, DirectoryInfo>(view => new DirectoryInfo(view.ToString()));
            TypeConstruction.SetExplicitConstructionMethod(() => { return(new DirectoryInfo(".")); });

            TypeConversion.Register <SerializedStringView, FileInfo>(view => new FileInfo(view.ToString()));
            TypeConstruction.SetExplicitConstructionMethod(() => { return(new FileInfo(".")); });
        }
Beispiel #2
0
        public void CanSetExplicitConstruction()
        {
            Assert.That(TypeConstruction.CanBeConstructed <ParameterConstructorType>(), Is.False);
            TypeConstruction.SetExplicitConstructionMethod(ExplicitConstruction);
            Assert.That(TypeConstruction.CanBeConstructed <ParameterConstructorType>(), Is.True);
            {
                var instance = TypeConstruction.Construct <ParameterConstructorType>();
                Assert.That(instance, Is.Not.Null);
                Assert.That(instance.Value, Is.EqualTo(10.0f));
            }

            TypeConstruction.UnsetExplicitConstructionMethod(ExplicitConstruction);
            Assert.That(TypeConstruction.CanBeConstructed <ParameterConstructorType>(), Is.False);
        }
Beispiel #3
0
        public void SettingAndUnSettingAnExplicitConstructionMethod_ToCreateAnInstance_BehavesProperly()
        {
            Assert.That(TypeConstruction.CanBeConstructed <ParameterConstructorType>(), Is.False);
            Assert.That(TypeConstruction.CanBeConstructed(typeof(ParameterConstructorType)), Is.False);
            TypeConstruction.SetExplicitConstructionMethod(ExplicitConstruction);
            Assert.That(TypeConstruction.CanBeConstructed <ParameterConstructorType>(), Is.True);
            Assert.That(TypeConstruction.CanBeConstructed(typeof(ParameterConstructorType)), Is.True);
            {
                var instance = TypeConstruction.Construct <ParameterConstructorType>();
                Assert.That(instance, Is.Not.Null);
                Assert.That(instance.Value, Is.EqualTo(10.0f));
            }

            TypeConstruction.UnsetExplicitConstructionMethod(ExplicitConstruction);
            Assert.That(TypeConstruction.CanBeConstructed <ParameterConstructorType>(), Is.False);
            Assert.That(TypeConstruction.CanBeConstructed(typeof(ParameterConstructorType)), Is.False);
        }
Beispiel #4
0
 public void SettingAndUnSettingAnExplicitConstructionMethod_WhenNoneAlreadySet_DoesNotThrow()
 {
     Assert.DoesNotThrow(() => TypeConstruction.SetExplicitConstructionMethod(ExplicitConstruction));
     Assert.DoesNotThrow(() => TypeConstruction.UnsetExplicitConstructionMethod(ExplicitConstruction));
 }
Beispiel #5
0
 public void TryingToUnsetAnExplicitConstructionMethod_WithAnotherExplicitConstructionMethodSet_ReturnsFalse()
 {
     TypeConstruction.SetExplicitConstructionMethod(ExplicitConstruction);
     Assert.That(TypeConstruction.TryUnsetExplicitConstructionMethod(OtherExplicitConstruction), Is.False);
     TypeConstruction.UnsetExplicitConstructionMethod(ExplicitConstruction);
 }
Beispiel #6
0
 public void TryingToSetAnExplicitConstructionMethod_WhenAlreadySet_ReturnsFalse()
 {
     TypeConstruction.SetExplicitConstructionMethod(ExplicitConstruction);
     Assert.That(TypeConstruction.TrySetExplicitConstructionMethod(ExplicitConstruction), Is.False);
     TypeConstruction.UnsetExplicitConstructionMethod(ExplicitConstruction);
 }
Beispiel #7
0
 public void UnSettingAnExplicitConstructionMethod_WithAnotherExplicitConstructionMethodSet_Throws()
 {
     TypeConstruction.SetExplicitConstructionMethod(ExplicitConstruction);
     Assert.Throws <InvalidOperationException>(() => TypeConstruction.UnsetExplicitConstructionMethod(OtherExplicitConstruction));
     TypeConstruction.UnsetExplicitConstructionMethod(ExplicitConstruction);
 }
Beispiel #8
0
 public void SettingAnExplicitConstructionMethod_WhenAlreadySet_Throws()
 {
     TypeConstruction.SetExplicitConstructionMethod(ExplicitConstruction);
     Assert.Throws <InvalidOperationException>(() => TypeConstruction.SetExplicitConstructionMethod(ExplicitConstruction));
     TypeConstruction.UnsetExplicitConstructionMethod(ExplicitConstruction);
 }