public void MixinTestChild_IsNotAmbigous_Scope()
 {
     using (MixinConfiguration.BuildNew().ForClass <MixinTestChild> ().AddMixin <StableBindingMixin> ().EnterScope())
     {
         AssertGetCustomMemberFromScript(ObjectFactory.Create <MixinTestChild> (ParamList.Empty), "MixinTestChild_IsNotAmbigous_Scope");
     }
 }
 protected Type CreateGeneratedTypeWithoutMixins(Type targetType)
 {
     using (MixinConfiguration.BuildNew().ForClass(targetType).Clear().EnterScope())
     {
         return(TypeGenerationHelper.ForceTypeGeneration(targetType));
     }
 }
 protected T CreateGeneratedTypeInstanceWithoutMixins <T> ()
 {
     using (MixinConfiguration.BuildNew().ForClass <T>().Clear().EnterScope())
     {
         return(TypeGenerationHelper.ForceTypeGenerationAndCreateInstance <T>());
     }
 }
 private Type CreateMixedType(Type baseType, params Type[] types)
 {
     using (MixinConfiguration.BuildNew().ForClass(baseType).AddMixins(types).EnterScope())
     {
         return(TypeFactory.GetConcreteType(baseType));
     }
 }
Exemplo n.º 5
0
        public void GenerateXml_WithOverriddenMembers()
        {
            var mixinConfiguration = MixinConfiguration.BuildNew()
                                     .ForClass <TargetDoSomething>().AddMixin <MixinDoSomething>()
                                     .BuildConfiguration();

            var type1 = new InvolvedType(typeof(TargetDoSomething));

            type1.ClassContext = new ReflectedObject(mixinConfiguration.ClassContexts.First());

            var memberOverrides = GetMemberOverrides(type1, typeof(MixinDoSomething), mixinConfiguration);

            var reportGenerator = new MemberOverrideReportGenerator(memberOverrides);

            var output = reportGenerator.GenerateXml();

            var expectedOutput = new XElement(
                "MemberOverrides",
                new XElement(
                    "OverriddenMember",
                    new XAttribute("type", "Method"),
                    new XAttribute("name", "DoSomething")
                    ));

            Assert.That(output.ToString(), Is.EqualTo(expectedOutput.ToString()));
        }
 public void ProtectedNonDefaultConstructor_NonMixed_AllowProtected()
 {
     using (MixinConfiguration.BuildNew().EnterScope())
     {
         Assert.That(ObjectFactory.Create <TargetClassWithProtectedCtors> (true, ParamList.Create(1)), Is.Not.Null);
     }
 }
Exemplo n.º 7
0
        public void GetMetadata_ForSealedBusinessObject_WithExistingMixin()
        {
            var mixinTargetType    = typeof(ManualBusinessObject);
            var businessObjectType = typeof(SealedBindableObject);

            Assertion.IsTrue(mixinTargetType.IsAssignableFrom(businessObjectType));

            using (MixinConfiguration.BuildNew()
                   .AddMixinToClass(
                       MixinKind.Extending,
                       mixinTargetType,
                       typeof(MixinStub),
                       MemberVisibility.Public,
                       Enumerable.Empty <Type>(),
                       Enumerable.Empty <Type>())
                   .EnterScope())
            {
                IPropertyInformation propertyInfo = GetPropertyInfo(typeof(ClassWithReferenceType <SealedBindableObject>), "Scalar");

                PropertyReflector propertyReflector = PropertyReflector.Create(propertyInfo, _businessObjectProvider);

                var referenceProperty = (IBusinessObjectReferenceProperty)propertyReflector.GetMetadata();
                Assert.That(() => referenceProperty.SupportsSearchAvailableObjects, Throws.Nothing);
            }
        }
 public void InvalidMixinConfiguration()
 {
     using (MixinConfiguration.BuildNew().ForClass(typeof(ClassWithAllDataTypes)).AddMixins(typeof(MixinWithAccessToDomainObjectProperties <Official>)).EnterScope())
     {
         TypeFactory.GetConcreteType(typeof(ClassWithAllDataTypes));
     }
 }
        public void GenerateXml_InterfaceDynamicallyImplemented()
        {
            var targetType = new InvolvedType(typeof(TargetClass3));

            var mixinConfiguration = MixinConfiguration.BuildNew().ForClass <TargetClass3> ().AddMixin <Mixin4> ().BuildConfiguration();

            targetType.ClassContext          = new ReflectedObject(mixinConfiguration.ClassContexts.First());
            targetType.TargetClassDefinition = new ReflectedObject(TargetClassDefinitionUtility.GetConfiguration(targetType.Type, mixinConfiguration));
            var mixinContext    = targetType.ClassContext.GetProperty("Mixins").First();
            var mixinDefinition = targetType.TargetClassDefinition.CallMethod("GetMixinByConfiguredType", mixinContext.GetProperty("MixinType").To <Type> ());

            var assemblyIdentifierGenerator = new IdentifierGenerator <Assembly> ();

            var output = new TargetCallDependenciesReportGenerator(mixinDefinition, assemblyIdentifierGenerator,
                                                                   _remotionReflector, _outputFormatter).GenerateXml();

            var expectedOutput = new XElement("TargetCallDependencies",
                                              new XElement("Dependency",
                                                           new XAttribute("assembly-ref", "0"),
                                                           new XAttribute("namespace", "System"),
                                                           new XAttribute("name", "IDisposable"),
                                                           new XAttribute("is-interface", true),
                                                           new XAttribute("is-implemented-by-target", false),
                                                           new XAttribute("is-added-by-mixin", false),
                                                           new XAttribute("is-implemented-dynamically", true)));

            XElementComparisonHelper.Compare(output, expectedOutput);
        }
Exemplo n.º 10
0
        public void FindInvolvedTypes_WithTargetClassInheritance()
        {
            var mixinConfiguration = MixinConfiguration.BuildNew()
                                     .ForClass <UselessObject>().AddMixin <Mixin1>()
                                     .BuildConfiguration();
            var involvedTypeFinder = CreateInvolvedTypeFinder(mixinConfiguration, new[] { typeof(Mixin1).Assembly });

            var involvedTypes = involvedTypeFinder.FindInvolvedTypes();

            var expectedType1 = new InvolvedType(typeof(UselessObject));

            expectedType1.ClassContext          = new ReflectedObject(mixinConfiguration.ClassContexts.First());
            expectedType1.TargetClassDefinition = CreateTargetClassDefintion <UselessObject> (mixinConfiguration);

            var expectedType2 = new InvolvedType(typeof(ClassInheritsFromUselessObject));

            expectedType2.ClassContext          = new ReflectedObject(mixinConfiguration.ClassContexts.GetWithInheritance(typeof(ClassInheritsFromUselessObject)));
            expectedType2.TargetClassDefinition = CreateTargetClassDefintion <ClassInheritsFromUselessObject> (mixinConfiguration);

            var expectedType3 = new InvolvedType(typeof(Mixin1));

            expectedType3.TargetTypes.Add(expectedType1, expectedType1.TargetClassDefinition.CallMethod("GetMixinByConfiguredType", typeof(Mixin1)));
            expectedType3.TargetTypes.Add(expectedType2, expectedType2.TargetClassDefinition.CallMethod("GetMixinByConfiguredType", typeof(Mixin1)));


            Assert.That(involvedTypes, Is.EquivalentTo(GetAdditonalAssemblyInvolvedTypes(expectedType1, expectedType2, expectedType3)));
        }
Exemplo n.º 11
0
        public void FindInvolvedTypes_WithMoreTargets()
        {
            var mixinConfiguration = MixinConfiguration.BuildNew()
                                     .ForClass <TargetClass1>().AddMixin <Mixin1>()
                                     .ForClass <TargetClass2>().AddMixin <Mixin2>()
                                     .BuildConfiguration();
            var involvedTypeFinder = CreateInvolvedTypeFinder(mixinConfiguration, new[] { typeof(Mixin1).Assembly });

            var involvedTypes = involvedTypeFinder.FindInvolvedTypes();

            var expectedType1 = new InvolvedType(typeof(TargetClass1));

            expectedType1.ClassContext          = new ReflectedObject(mixinConfiguration.ClassContexts.First());
            expectedType1.TargetClassDefinition = CreateTargetClassDefintion <TargetClass1> (mixinConfiguration);

            var expectedType2 = new InvolvedType(typeof(Mixin1));

            expectedType2.TargetTypes.Add(expectedType1, expectedType1.TargetClassDefinition.CallMethod("GetMixinByConfiguredType", typeof(Mixin1)));

            var expectedType3 = new InvolvedType(typeof(TargetClass2));

            expectedType3.ClassContext          = new ReflectedObject(mixinConfiguration.ClassContexts.Last());
            expectedType3.TargetClassDefinition = CreateTargetClassDefintion <TargetClass2> (mixinConfiguration);

            var expectedType4 = new InvolvedType(typeof(Mixin2));

            expectedType4.TargetTypes.Add(expectedType3, expectedType3.TargetClassDefinition.CallMethod("GetMixinByConfiguredType", typeof(Mixin2)));

            Assert.That(involvedTypes, Is.EquivalentTo(GetAdditonalAssemblyInvolvedTypes(expectedType1, expectedType2, expectedType3, expectedType4)));
        }
Exemplo n.º 12
0
 public void CreateNewObject_ValidatesMixinConfiguration()
 {
     using (MixinConfiguration.BuildNew().EnterScope())
     {
         _domainObjectCreator.CreateNewObject(_targetClassForPersistentMixinInitializationContext, ParamList.Empty, _transaction);
     }
 }
Exemplo n.º 13
0
 public void CreateObjectReference_ValidatesMixinConfiguration()
 {
     using (MixinConfiguration.BuildNew().EnterScope())
     {
         _domainObjectCreator.CreateObjectReference(_targetClassForPersistentMixinInitializationContext, _transaction);
     }
 }
 public void Ctor_ChecksComposedInterfaceAvailable()
 {
     using (MixinConfiguration.BuildNew().EnterScope())
     {
         ObjectFactory.Create <ClassDerivedFromComposedObject> (ParamList.Empty);
     }
 }
        public void GetOverrides_WithOverrides_ForMemberInBaseClass()
        {
            var targetType         = typeof(BaseMemberOverrideTestClass.Target);
            var mixinConfiguration =
                MixinConfiguration.BuildNew()
                .ForClass <BaseMemberOverrideTestClass.Target> ().AddMixin <BaseMemberOverrideTestClass.Mixin1> ()
                .BuildConfiguration();
            var targetClassDefinition = new ReflectedObject(TargetClassDefinitionUtility.GetConfiguration(targetType, mixinConfiguration));
            var involvedType          = new InvolvedType(targetType)
            {
                TargetClassDefinition = targetClassDefinition,
                ClassContext          = new ReflectedObject(mixinConfiguration.ClassContexts.First())
            };

            var reportGenerator = CreateMemberReportGenerator(targetType, involvedType);

            //var memberInfo = targetType.GetMember ("OverriddenMethod")[0];
            var output         = reportGenerator.GenerateXml();
            var expectedOutput =
                new XElement(
                    "Overrides",
                    new XElement(
                        "Mixin-Reference",
                        new XAttribute("ref", 0),
                        new XAttribute("instance-name", "BaseMemberOverrideTestClass+Mixin1")
                        ));

            Assert.That(output.XPathSelectElement("Member[@name='OverriddenMethod']").Element("Overrides").ToString(), Is.EqualTo(expectedOutput.ToString()));
        }
Exemplo n.º 16
0
 protected T BuildMixedInstance <T> (params Type[] mixins)
 {
     using (MixinConfiguration.BuildNew().ForClass <T> ().AddMixins(mixins).EnterScope())
     {
         return(ObjectFactory.Create <T>());
     }
 }
 public void ProtectedNonDefaultConstructor_NonMixed()
 {
     using (MixinConfiguration.BuildNew().EnterScope())
     {
         ObjectFactory.Create <TargetClassWithProtectedCtors> (ParamList.Create(1));
     }
 }
 public void HasMixinsOnMixedTypesWithoutMixins()
 {
     using (MixinConfiguration.BuildNew().ForClass <object>().EnterScope())
     {
         Assert.That(MixinTypeUtility.HasMixins(typeof(object)), Is.False);
     }
 }
        public void GenerateXml_WithIntroducedInterfaces()
        {
            var interfaceIdentifierGenerator = new IdentifierGenerator <Type>();
            var mixinConfiguration           = MixinConfiguration.BuildNew()
                                               .ForClass <TargetClass2>().AddMixin <Mixin3>()
                                               .BuildConfiguration();

            var type1 = new InvolvedType(typeof(TargetClass2));

            type1.ClassContext = new ReflectedObject(mixinConfiguration.ClassContexts.First());

            // TargetClass2 does not implement any interface
            // Mixin3 introduces interface IDisposable
            var interfaceIntroductions = GetInterfaceIntroductions(type1, typeof(Mixin3), mixinConfiguration);
            var reportGenerator        = new InterfaceIntroductionReportGenerator(interfaceIntroductions, interfaceIdentifierGenerator);

            var output = reportGenerator.GenerateXml();

            var expectedOutput = new XElement(
                "InterfaceIntroductions",
                new XElement(
                    "IntroducedInterface",
                    new XAttribute("ref", "0")
                    ));

            Assert.That(output.ToString(), Is.EqualTo(expectedOutput.ToString()));
        }
Exemplo n.º 20
0
 private TTargetType CreateMixedObject <TTargetType> (params Type[] types)
 {
     using (MixinConfiguration.BuildNew().ForClass <TTargetType> ().AddMixins(types).EnterScope())
     {
         return(ObjectFactory.Create <TTargetType> (ParamList.Empty));
     }
 }
        public void CreatePropertyRuleReflectorForConcreteTypeBasedOnDomainObjectAndMixin_AnnotatedPropertiesPartOfAnInterface_DoesNotIncludePropertiesCopeisToConcreteType()
        {
            using (MixinConfiguration
                   .BuildNew()
                   .ForClass <MixinTarget_AnnotatedPropertiesPartOfInterface>()
                   .AddMixin <MixinTypeWithDomainObjectAttributes_AnnotatedPropertiesPartOfInterface>()
                   .EnterScope())
            {
                var result =
                    _provider.GetValidationCollectors(
                        new[]
                {
                    MixinTypeUtility.GetConcreteMixedType(typeof(MixinTarget_AnnotatedPropertiesPartOfInterface)),
                    typeof(MixinTypeWithDomainObjectAttributes_AnnotatedPropertiesPartOfInterface)
                })
                    .SelectMany(c => c)
                    .ToArray();

                var resultForConcreteType = result.SingleOrDefault(r => MixinTypeUtility.IsGeneratedConcreteMixedType(r.Collector.ValidatedType));
                Assert.That(resultForConcreteType, Is.Null);

                var resultForMixin = result.SingleOrDefault(
                    r => r.Collector.ValidatedType == typeof(IMixinTypeWithDomainObjectAttributes_AnnotatedPropertiesPartOfInterface));

                Assert.That(resultForMixin, Is.Not.Null);
                Assert.That(resultForMixin.Collector.AddedPropertyRules.Count, Is.EqualTo(10));
            }
        }
Exemplo n.º 22
0
        public void ClassReflector_CreatesBaseClass_CompatibleWithDerivedInstances_WithMixins_WithOverriddenProperty()
        {
            using (MixinConfiguration.BuildNew()
                   .ForClass <BaseBusinessObjectClass> ().AddMixin <MixinOverridingProperty> ()
                   .ForClass <BaseBusinessObjectClass> ().AddMixin <BindableObjectMixin> ()
                   .EnterScope())
            {
                var classReflector = new ClassReflector(
                    typeof(BaseBusinessObjectClass),
                    _businessObjectProvider,
                    _metadataFactory,
                    _bindableObjectGlobalizationService);
                var bindableObjectClass   = classReflector.GetMetadata();
                var derivedBusinessObject = ObjectFactory.Create <DerivedBusinessObjectClass> (ParamList.Empty);

                derivedBusinessObject.Public = "p";
                Mixin.Get <MixinOverridingProperty> (derivedBusinessObject).Public += "q";

                var propertyDefinition = bindableObjectClass.GetPropertyDefinition("Public");
                Assert.That(propertyDefinition, Is.Not.Null);

                var businessObject = (IBusinessObject)derivedBusinessObject;
                Assert.That(businessObject.GetProperty(propertyDefinition), Is.EqualTo("pq"));
            }
        }
        public void GenerateXml_WithIntroducedAttributes()
        {
            var attributeIdentifierGenerator = new IdentifierGenerator <Type>();
            var mixinConfiguration           = MixinConfiguration.BuildNew()
                                               .ForClass <UselessObject>().AddMixin <ObjectWithInheritableAttribute>()
                                               .BuildConfiguration();

            var type1 = new InvolvedType(typeof(UselessObject));

            type1.ClassContext = new ReflectedObject(mixinConfiguration.ClassContexts.First());

            var attributeIntroductions = GetAttributeIntroductions(type1, typeof(ObjectWithInheritableAttribute), mixinConfiguration);
            var reportGenerator        = new AttributeIntroductionReportGenerator(
                attributeIntroductions, attributeIdentifierGenerator, Helpers.RemotionReflectorFactory.GetRemotionReflection());

            var output = reportGenerator.GenerateXml();

            var expectedOutput = new XElement(
                "AttributeIntroductions",
                new XElement(
                    "IntroducedAttribute",
                    new XAttribute("ref", "0")
                    ));

            Assert.That(output.ToString(), Is.EqualTo(expectedOutput.ToString()));
        }
Exemplo n.º 24
0
        public void GetMetadata_ForSealedBusinessObject_WithExistingMixin()
        {
            var mixinTargetType    = typeof(ManualBusinessObject);
            var businessObjectType = typeof(SealedBindableObject);

            Assertion.IsTrue(mixinTargetType.IsAssignableFrom(businessObjectType));

            using (MixinConfiguration.BuildNew()
                   .AddMixinToClass(
                       MixinKind.Extending,
                       mixinTargetType,
                       typeof(MixinStub),
                       MemberVisibility.Public,
                       Enumerable.Empty <Type>(),
                       Enumerable.Empty <Type>())
                   .EnterScope())
            {
                var classReflector = new ClassReflector(
                    businessObjectType,
                    _businessObjectProvider,
                    _metadataFactory,
                    _bindableObjectGlobalizationService);
                var bindableObjectClass = classReflector.GetMetadata();

                Assert.That(bindableObjectClass, Is.InstanceOf(typeof(IBusinessObjectClass)));
                Assert.That(bindableObjectClass.TargetType, Is.SameAs(businessObjectType));
                Assert.That(bindableObjectClass.ConcreteType, Is.SameAs(bindableObjectClass.TargetType));
            }
        }
        public void GetTypes_WithTypeDiscoveryService_IgnoresActiveMixinConfiguration()
        {
            using (MixinConfiguration.BuildNew().EnterScope())
            {
                Expect.Call(_serviceProvider.GetService(typeof(ITypeDiscoveryService))).Return(_typeDiscoveryService);
                Expect.Call(_typeDiscoveryService.GetTypes(typeof(object), true))
                .Return(
                    new object[]
                {
                    typeof(ClassWithAllDataTypes),
                    typeof(SimpleValueType),
                    typeof(SimpleReferenceType),
                    typeof(ManualBusinessObject),
                    typeof(ClassDerivedFromBindableObjectBase),
                    typeof(ClassDerivedFromBindableObjectWithIdentityBase),
                });

                _mockRepository.ReplayAll();

                var         finder = new BindableObjectTypeFinder(_serviceProvider);
                List <Type> types  = finder.GetTypes(false);

                Assert.That(types,
                            Is.EquivalentTo(new[]
                {
                    typeof(ClassWithAllDataTypes),
                    typeof(ClassDerivedFromBindableObjectBase),
                    typeof(ClassDerivedFromBindableObjectWithIdentityBase),
                }));

                _mockRepository.VerifyAll();
            }
        }
        public void GenerateXml_TargetClassWithOverriddenBaseClassMember()
        {
            var type = typeof(InheritatedTargetClass);
            var mixinConfiguration =
                MixinConfiguration.BuildNew().ForClass <InheritatedTargetClass> ().AddMixin <MixinOverridesTargetClassMember> ().BuildConfiguration();
            var targetClassDefinition = new ReflectedObject(TargetClassDefinitionUtility.GetConfiguration(type, mixinConfiguration));

            var involvedType = new InvolvedType(type)
            {
                TargetClassDefinition = targetClassDefinition
            };

            var reportGenerator = CreateMemberReportGenerator(type, involvedType);
            var output          = reportGenerator.GenerateXml();

            var expectedOutput = new XElement(
                "Members",
                new XElement(
                    "Member",
                    new XAttribute("id", "0"),
                    new XAttribute("type", MemberTypes.Constructor),
                    new XAttribute("name", ".ctor"),
                    new XAttribute("is-declared-by-this-class", true),
                    _outputFormatter.CreateModifierMarkup("", "public"),
                    _outputFormatter.CreateConstructorMarkup("InheritatedTargetClass", new ParameterInfo[0])
                    ),
                new XElement(
                    "Member",
                    new XAttribute("id", "1"),
                    new XAttribute("type", MemberTypes.Method),
                    new XAttribute("name", "MyBaseClassMethod"),
                    new XAttribute("is-declared-by-this-class", false),
                    _outputFormatter.CreateModifierMarkup("", "public virtual"),
                    _outputFormatter.CreateMethodMarkup("MyBaseClassMethod", typeof(void), new ParameterInfo[0]),
                    GenerateOverrides("Mixin-Reference", "0", "MixinOverridesTargetClassMember")
                    ),
                new XElement(
                    "Member",
                    new XAttribute("id", "2"),
                    new XAttribute("type", MemberTypes.Method),
                    new XAttribute("name", "MyNewMethod"),
                    new XAttribute("is-declared-by-this-class", true),
                    _outputFormatter.CreateModifierMarkup("", "public virtual"),
                    _outputFormatter.CreateMethodMarkup("MyNewMethod", typeof(void), new ParameterInfo[0])
                    ),
                new XElement(
                    "Member",
                    new XAttribute("id", "3"),
                    new XAttribute("type", MemberTypes.Method),
                    new XAttribute("name", "MyNonRelevantBaseClassMethod"),
                    new XAttribute("is-declared-by-this-class", true),
                    _outputFormatter.CreateModifierMarkup("", "public override"),
                    _outputFormatter.CreateMethodMarkup("MyNonRelevantBaseClassMethod", typeof(void), new ParameterInfo[0]),
                    GenerateOverrides("Mixin-Reference", "0", "MixinOverridesTargetClassMember")
                    )
                );

            XElementComparisonHelper.Compare(output, expectedOutput);
        }
Exemplo n.º 27
0
 public void GetProvider_WithMixin()
 {
     using (MixinConfiguration.BuildNew().ForClass(typeof(StubBusinessObjectProvider)).AddMixin <MixinStub>().EnterScope())
     {
         IBusinessObjectProvider provider = BusinessObjectProvider.GetProvider(typeof(StubBusinessObjectProviderAttribute));
         Assert.That(provider, Is.InstanceOf(typeof(IMixinTarget)));
     }
 }
Exemplo n.º 28
0
 public void AttributesFromMixin_InheritedFalse()
 {
     using (MixinConfiguration.BuildNew()
            .ForClass <ClassWithoutMultiLingualResourcesAttributes> ().AddMixin <MixinAddingMultiLingualResourcesAttributes1> ().EnterScope())
     {
         Assert.That(MixedMultiLingualResources.ExistsResource(typeof(ClassWithoutMultiLingualResourcesAttributes)), Is.True);
     }
 }
 public void CreatePersistenceStrategy_CanBeMixed()
 {
     using (MixinConfiguration.BuildNew().ForClass <RootPersistenceStrategy> ().AddMixin <NullMixin> ().EnterScope())
     {
         var result = _factory.CreatePersistenceStrategy(_fakeConstructedTransaction);
         Assert.That(Mixin.Get <NullMixin> (result), Is.Not.Null);
     }
 }
Exemplo n.º 30
0
 public void OverridingShadowedMethod_WithTargetSpecification_ShouldOverrideSpecified()
 {
     using (MixinConfiguration.BuildNew().ForClass <C>().AddMixin <MixinWithTargetSpecification>().EnterScope())
     {
         var instance = ObjectFactory.Create <D> ();
         Assert.That(instance.M(), Is.EqualTo("TheMixin.M -> C.M"));
     }
 }