public void IsBindableObjectImplementation_TrueWithSealedTypeHavingAMixin() { 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()) { Assert.That(BindableObjectProvider.IsBindableObjectImplementation(businessObjectType), Is.True); } }
public void AttributesFromMixinsOnBaseAndClass_InheritedTrue() { using (MixinConfiguration.BuildNew() .ForClass <ClassWithMultiLingualResourcesAttributes>() .AddMixin <MixinAddingMultiLingualResourcesAttributes1>() .ForClass <InheritedClassWithMultiLingualResourcesAttributes>() .AddMixin <MixinAddingMultiLingualResourcesAttributes2>() .EnterScope()) { ResourceManagerSet resourceManager = (ResourceManagerSet)MixedMultiLingualResources.GetResourceManager(typeof(InheritedClassWithMultiLingualResourcesAttributes), true); Assert.That( resourceManager.ResourceManagers.Select(rm => rm.Name), Is.EquivalentTo(new[] { NamedResources.OnInherited, NamedResources.OnMixin1, NamedResources.OnMixin2a, NamedResources.OnMixin2b, NamedResources.OnTarget })); Assert.That(resourceManager.ResourceManagers.Take(2).Select(rm => rm.Name), Is.EquivalentTo(new[] { NamedResources.OnInherited, NamedResources.OnMixin1 })); Assert.That(resourceManager.ResourceManagers.Skip(2).Take(2).Select(rm => rm.Name), Is.EquivalentTo(new[] { NamedResources.OnMixin2a, NamedResources.OnMixin2b })); Assert.That(resourceManager.ResourceManagers.Skip(4).Select(rm => rm.Name), Is.EquivalentTo(new[] { NamedResources.OnTarget })); } }
public void GenerateXml_NoOverriddenMembers() { var mixinConfiguration = MixinConfiguration.BuildNew() .ForClass <TargetClass1>().AddMixin <Mixin1>() .BuildConfiguration(); var type1 = new InvolvedType(typeof(TargetClass1)); type1.ClassContext = new ReflectedObject(mixinConfiguration.ClassContexts.First()); var memberOverrides = GetMemberOverrides(type1, typeof(Mixin1), mixinConfiguration); var reportGenerator = new MemberOverrideReportGenerator(memberOverrides); var output = reportGenerator.GenerateXml(); var expectedOutput = new XElement("MemberOverrides"); Assert.That(output.ToString(), Is.EqualTo(expectedOutput.ToString())); }
public void GenerateXml_MixinWithOverriddenClassMember() { var mixinType = typeof(MixinWithInheritedMethod); var targetType = typeof(ClassOverridingInheritedMixinMethod); var mixin = new InvolvedType(mixinType); var target = new InvolvedType(targetType); var mixinConfiguration = MixinConfiguration.BuildNew().ForClass <ClassOverridingInheritedMixinMethod> ().AddMixin <MixinWithInheritedMethod> ().BuildConfiguration(); var targetClassDefinition = TargetClassDefinitionUtility.GetConfiguration(targetType, mixinConfiguration); mixin.TargetTypes.Add(target, new ReflectedObject(targetClassDefinition.GetMixinByConfiguredType(mixinType))); var reportGenerator = CreateMemberReportGenerator(mixinType, mixin); 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("MixinWithInheritedMethod", new ParameterInfo[0]) ), new XElement( "Member", new XAttribute("id", "1"), new XAttribute("type", MemberTypes.Method), new XAttribute("name", "ProtectedInheritedMethod"), new XAttribute("is-declared-by-this-class", false), _outputFormatter.CreateModifierMarkup("", "protected virtual"), _outputFormatter.CreateMethodMarkup("ProtectedInheritedMethod", typeof(string), new ParameterInfo[0]), GenerateOverrides("Target-Reference", "0", "ClassOverridingInheritedMixinMethod") ) ); XElementComparisonHelper.Compare(output, expectedOutput); }
public void IntroducedAttribute_SuppressedByMixin() { using (MixinConfiguration.BuildNew().ForClass <NullTarget> ().AddMixin <MixinAddingBT1Attribute> ().AddMixin <MixinSuppressingBT1Attribute> ().EnterScope()) { TargetClassDefinition definition = DefinitionObjectMother.GetActiveTargetClassDefinition(typeof(NullTarget)); Assert.That(definition.ReceivedAttributes.ContainsKey(typeof(BT1Attribute)), Is.False); Assert.That(definition.Mixins[typeof(MixinAddingBT1Attribute)].SuppressedAttributeIntroductions.ContainsKey(typeof(BT1Attribute)), Is.True); SuppressedAttributeIntroductionDefinition[] suppressedAttributes = definition.Mixins[typeof(MixinAddingBT1Attribute)].SuppressedAttributeIntroductions[typeof(BT1Attribute)].ToArray(); Assert.That(suppressedAttributes.Length, Is.EqualTo(1)); Assert.That(suppressedAttributes[0].Attribute, Is.SameAs(definition.Mixins[typeof(MixinAddingBT1Attribute)].CustomAttributes.GetFirstItem(typeof(BT1Attribute)))); Assert.That(suppressedAttributes[0].AttributeType, Is.EqualTo(typeof(BT1Attribute))); Assert.That(suppressedAttributes[0].FullName, Is.EqualTo(typeof(BT1Attribute).FullName)); Assert.That(suppressedAttributes[0].Parent, Is.SameAs(definition)); Assert.That(suppressedAttributes[0].Suppressor, Is.SameAs(definition.Mixins[typeof(MixinSuppressingBT1Attribute)].CustomAttributes.GetFirstItem(typeof(SuppressAttributesAttribute)))); Assert.That(suppressedAttributes[0].Target, Is.SameAs(definition)); } }
public void GetOverrides_NoOverrides() { var targetType = typeof(TargetClass1); var mixinConfiguration = MixinConfiguration.BuildNew() .ForClass <TargetClass1> ().AddMixin <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 ("Dispose")[0]; var output = reportGenerator.GenerateXml(); Assert.That(output.XPathSelectElements("Member[@name='Dispose']/Overrides").Any(), Is.False); }
public void AttributesFromMixinOfMixin_InheritedFalse() { using (MixinConfiguration.BuildNew() .ForClass <ClassWithoutMultiLingualResourcesAttributes>() .AddMixin <MixinAddingMultiLingualResourcesAttributes1>() .AddMixin <MixinAddingMultiLingualResourcesAttributes2>() .ForClass <MixinAddingMultiLingualResourcesAttributes1>() .AddMixin <MixinOfMixinWithResources>() .EnterScope()) { ResourceManagerSet resourceManager = (ResourceManagerSet)MixedMultiLingualResources.GetResourceManager(typeof(ClassWithoutMultiLingualResourcesAttributes), false); //Note: MixinOfMixin was previously sorted after the introducing mixin, but there is no know client code that actually used MixinOfMixin with resources. Assert.That( resourceManager.ResourceManagers.Select(rm => rm.Name), Is.EquivalentTo(new[] { NamedResources.MixinOfMixinWithResources, NamedResources.OnMixin1, NamedResources.OnMixin2a, NamedResources.OnMixin2b })); Assert.That(resourceManager.ResourceManagers.Take(2).Select(rm => rm.Name), Is.EqualTo(new[] { NamedResources.MixinOfMixinWithResources, NamedResources.OnMixin1 })); Assert.That(resourceManager.ResourceManagers.Skip(2).Select(rm => rm.Name), Is.EquivalentTo(new[] { NamedResources.OnMixin2a, NamedResources.OnMixin2b })); } }
public void GetResourceManagerTwice_NewMixinConfigurationWithinConfiguration_NotSame() { var typeInformation = TypeAdapter.Create(typeof(ClassWithoutMultiLingualResourcesAttributes)); IResourceManager result1; IResourceManager result2; using (MixinConfiguration.BuildFromActive() .ForClass <ClassWithoutMultiLingualResourcesAttributes>() .AddMixin <MixinAddingMultiLingualResourcesAttributes1>().EnterScope()) { result1 = _globalizationService.GetResourceManager(typeInformation); using (MixinConfiguration.BuildFromActive() .ForClass <ClassWithoutMultiLingualResourcesAttributes>() .AddMixin <MixinAddingMultiLingualResourcesAttributes1>().EnterScope()) { result2 = _globalizationService.GetResourceManager(typeInformation); } } Assert.That(result1, Is.Not.SameAs(result2)); }
public void CopyAttributes_OnMember() { using (MixinConfiguration.BuildFromActive().ForClass <NullTarget> ().Clear().AddMixins(typeof(MixinIndirectlyAddingAttribute)).EnterScope()) { MethodDefinition definition = DefinitionObjectMother.GetActiveTargetClassDefinition(typeof(NullTarget)).Mixins[typeof(MixinIndirectlyAddingAttribute)].Methods[typeof(MixinIndirectlyAddingAttribute).GetMethod("ToString")]; Assert.That(definition.CustomAttributes.ContainsKey(typeof(CopyCustomAttributesAttribute)), Is.False); Assert.That(definition.CustomAttributes.ContainsKey(typeof(AttributeWithParameters)), Is.True); var attributes = new List <AttributeDefinition> (definition.CustomAttributes[typeof(AttributeWithParameters)]); Assert.That(attributes.Count, Is.EqualTo(1)); Assert.That(attributes[0].AttributeType, Is.EqualTo(typeof(AttributeWithParameters))); Assert.That(attributes[0].Data.Constructor, Is.EqualTo(typeof(AttributeWithParameters).GetConstructor(new[] { typeof(int) }))); Assert.That(attributes[0].IsCopyTemplate, Is.True); Assert.That(attributes[0].Data.ConstructorArguments.Count, Is.EqualTo(1)); Assert.That(attributes[0].Data.ConstructorArguments[0], Is.EqualTo(4)); Assert.That(attributes[0].Data.NamedArguments.Count, Is.EqualTo(0)); } }
public void SavesMixedTypes() { AppDomainRunner.Run( delegate { using (MixinConfiguration.BuildNew() .ForClass <BaseType1>().AddMixins(typeof(BT1Mixin1)) .ForClass <Page> ().AddMixin(typeof(NullMixin)) .EnterScope()) { Mixer mixer = Mixer.Create("Assembly", _assemblyOutputDirectory, 1); mixer.PrepareOutputDirectory(); mixer.Execute(MixinConfiguration.ActiveConfiguration); Assembly theAssembly = Assembly.LoadFile(mixer.MixerPipelineFactory.GetModulePaths(_assemblyOutputDirectory).Single()); var types = theAssembly.GetTypes(); var concreteType = types.SingleOrDefault(t => t.BaseType == typeof(BaseType1)); Assert.NotNull(concreteType); Assert.That( MixinTypeUtility.GetClassContextForConcreteType(concreteType), Is.EqualTo(MixinConfiguration.ActiveConfiguration.GetContext(typeof(BaseType1)))); object instance = Activator.CreateInstance(concreteType); Assert.That(Mixin.Get <BT1Mixin1> (instance), Is.Not.Null); var concreteTypeFromSystemAssembly = types.SingleOrDefault(t => t.BaseType == typeof(Page)); Assert.That(concreteTypeFromSystemAssembly, Is.Not.Null); SafeServiceLocator.Current.GetInstance <IPipelineRegistry>().DefaultPipeline.CodeManager.LoadFlushedCode(theAssembly); Type concreteTypeFromFactory = TypeFactory.GetConcreteType(typeof(BaseType1)); Assert.That(concreteTypeFromFactory, Is.SameAs(concreteType)); Assert.That(theAssembly.IsDefined(typeof(NonApplicationAssemblyAttribute), false), Is.True); } }); }
public void MultipleSimilarInterfaces() { using (MixinConfiguration.BuildNew() .ForClass <ClassImplementingSimpleInterface> ().AddMixin(typeof(MixinIntroducingInterfacesImplementingEachOther <>)) .EnterScope()) { TargetClassDefinition definition = DefinitionObjectMother.GetActiveTargetClassDefinition(typeof(ClassImplementingSimpleInterface)); MixinDefinition mixinDefinition = definition.GetMixinByConfiguredType(typeof(MixinIntroducingInterfacesImplementingEachOther <>)); Assert.That(definition.ReceivedInterfaces.ContainsKey(typeof(IList)), Is.True); Assert.That(definition.ReceivedInterfaces[typeof(IList)].Implementer, Is.SameAs(mixinDefinition)); Assert.That(definition.ReceivedInterfaces.ContainsKey(typeof(ICollection <ClassImplementingSimpleInterface>)), Is.True); Assert.That(definition.ReceivedInterfaces[typeof(ICollection <ClassImplementingSimpleInterface>)].Implementer, Is.SameAs(mixinDefinition)); Assert.That(definition.ReceivedInterfaces[typeof(IList)].IntroducedProperties.ContainsKey(typeof(IList).GetProperty("IsReadOnly")), Is.True); Assert.That(definition.ReceivedInterfaces[typeof(ICollection <ClassImplementingSimpleInterface>)].IntroducedProperties.ContainsKey( typeof(ICollection <ClassImplementingSimpleInterface>).GetProperty("IsReadOnly")), Is.True); Assert.That(definition.ReceivedInterfaces[typeof(ICollection <ClassImplementingSimpleInterface>)].IntroducedProperties[ typeof(ICollection <ClassImplementingSimpleInterface>).GetProperty("IsReadOnly")].ImplementingMember, Is.Not.EqualTo(definition.ReceivedInterfaces[typeof(IList)].IntroducedProperties[typeof(IList).GetProperty("IsReadOnly")].ImplementingMember)); } }
public IResourceManager GetResourceManager(ITypeInformation typeInformation) { ArgumentUtility.CheckNotNull("typeInformation", typeInformation); var masterConfiguration = MixinConfiguration.GetMasterConfiguration(); if (masterConfiguration != MixinConfiguration.ActiveConfiguration) { return(GetResourceManagerFromType(typeInformation)); } // During normal operation, the lock-statement is cheap enough as to not matter when accessing the ResourceManager. lock (_mixinConfigurationLockObject) { if (_mixinConfiguration != masterConfiguration) { _resourceManagerCache.Clear(); _mixinConfiguration = masterConfiguration; } } return(_resourceManagerCache.GetOrCreateValue(typeInformation, GetResourceManagerFromType)); }
public void GetResourceManagerTwice_TypeWithMixin_DifferentMixinConfiguration_NotSame() { var typeInformation = TypeAdapter.Create(typeof(ClassWithoutMultiLingualResourcesAttributes)); ResourceManagerSet result1; var mixinConfiguration = MixinConfiguration.BuildFromActive() .ForClass <ClassWithoutMultiLingualResourcesAttributes>() .AddMixin <MixinAddingMultiLingualResourcesAttributes1>(); using (mixinConfiguration.EnterScope()) { result1 = (ResourceManagerSet)_globalizationService.GetResourceManager(typeInformation); } ResourceManagerSet result2; using (mixinConfiguration.EnterScope()) { result2 = (ResourceManagerSet)_globalizationService.GetResourceManager(typeInformation); } Assert.That(result1, Is.Not.SameAs(result2)); }
public void GeneratedTypeImplementsOverriddenMethods2() { using (MixinConfiguration.BuildFromActive().ForClass <BaseType1> ().Clear().AddMixins(typeof(BT1Mixin1)).EnterScope()) { Type t = TypeFactory.GetConcreteType(typeof(BaseType1)); Type proxyType = t.GetNestedType("NextCallProxy"); Assert.That(proxyType.GetMethod("Remotion.Mixins.UnitTests.Core.TestDomain.BaseType1.VirtualMethod", BindingFlags.Public | BindingFlags.Instance), Is.Not.Null); Assert.That(proxyType.GetMethod("Remotion.Mixins.UnitTests.Core.TestDomain.BaseType1.get_VirtualProperty", BindingFlags.Public | BindingFlags.Instance), Is.Null); Assert.That(proxyType.GetMethod("Remotion.Mixins.UnitTests.Core.TestDomain.BaseType1.set_VirtualProperty", BindingFlags.Public | BindingFlags.Instance), Is.Not.Null); Assert.That(proxyType.GetMethod("Remotion.Mixins.UnitTests.Core.TestDomain.BaseType1.add_VirtualEvent", BindingFlags.Public | BindingFlags.Instance), Is.Not.Null); Assert.That(proxyType.GetMethod("Remotion.Mixins.UnitTests.Core.TestDomain.BaseType1.remove_VirtualEvent", BindingFlags.Public | BindingFlags.Instance), Is.Not.Null); } using (MixinConfiguration.BuildFromActive().ForClass <BaseType1> ().Clear().AddMixins(typeof(BT1Mixin2)).EnterScope()) { Type t = TypeFactory.GetConcreteType(typeof(BaseType1)); Type proxyType = t.GetNestedType("NextCallProxy"); Assert.That(proxyType.GetMethod("Remotion.Mixins.UnitTests.Core.TestDomain.BaseType1.get_VirtualProperty", BindingFlags.Public | BindingFlags.Instance), Is.Not.Null); Assert.That(proxyType.GetMethod("Remotion.Mixins.UnitTests.Core.TestDomain.BaseType1.set_VirtualProperty", BindingFlags.Public | BindingFlags.Instance), Is.Null); } }
public void MemberEquals_False() { 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 memberInfo1 = typeof(HiddenMemberTestClass.Target).GetMember("HiddenMethod")[0]; var output = involvedType.TargetClassDefinition.CallMethod("GetAllMembers").SingleOrDefault( mdb => MemberInfoEqualityUtility.MemberEquals(mdb.GetProperty("MemberInfo").To <MemberInfo> (), memberInfo1)); Assert.That(output, Is.Null); }
public void ClassReflector_CreatesBaseClass_CompatibleWithDerivedInstances_WithMixins_WithMixedProperty() { using (MixinConfiguration.BuildNew() .ForClass <BaseBusinessObjectClass> ().AddMixin <MixinAddingProperty> () .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); ((IMixinAddingProperty)derivedBusinessObject).MixedProperty = "p"; var propertyDefinition = bindableObjectClass.GetPropertyDefinition("MixedProperty"); Assert.That(propertyDefinition, Is.Not.Null); var businessObject = (IBusinessObject)derivedBusinessObject; Assert.That(businessObject.GetProperty(propertyDefinition), Is.EqualTo("p")); } }
public void GenerateXml_WithComposedInterface() { var mixinConfiguration = MixinConfiguration.BuildNew() .ForClass <ComposedInterfacesTestClass.MyMixinTarget> () .AddCompleteInterface <ComposedInterfacesTestClass.ICMyMixinTargetMyMixin> () .AddMixin <ComposedInterfacesTestClass.MyMixin> () .BuildConfiguration(); var involvedType = new InvolvedType(typeof(ComposedInterfacesTestClass.MyMixinTarget)); var classContext = mixinConfiguration.ClassContexts.GetWithInheritance(typeof(ComposedInterfacesTestClass.MyMixinTarget)); involvedType.ClassContext = new ReflectedObject(classContext); var reportGenerator = ReportBuilder.CreateInterfaceReportGenerator(_remotionReflector, _outputFormatter, involvedType); var output = reportGenerator.GenerateXml(); var memberReportGenerator = ReportBuilder.CreateMemberReportGenerator(typeof(ComposedInterfacesTestClass.ICMyMixinTargetMyMixin), _outputFormatter); var expectedOutput = new XElement( "Interfaces", new XElement( "Interface", new XAttribute("id", "0"), new XAttribute("assembly-ref", "0"), new XAttribute("namespace", "MixinXRef.UnitTests.TestDomain"), new XAttribute("name", "ComposedInterfacesTestClass+ICMyMixinTargetMyMixin"), new XAttribute("is-composed-interface", true), memberReportGenerator.GenerateXml(), new XElement( "ImplementedBy", new XElement( "InvolvedType-Reference", new XAttribute("ref", "0")) ) )); Assert.That(output.ToString(), Is.EqualTo(expectedOutput.ToString())); }
public void GenerateXml_WithComposedInterface() { var mixinConfiguration = MixinConfiguration.BuildNew() .ForClass <ComposedInterfacesTestClass.MyMixinTarget>() .AddCompleteInterface <ComposedInterfacesTestClass.ICMyMixinTargetMyMixin>() .AddMixin <ComposedInterfacesTestClass.MyMixin>() .BuildConfiguration(); // MyMixinTarget does not implement any interfaces! (but ICMyMixinTargetMyMixin is added to class context as a composed interface) var involvedType = new InvolvedType(typeof(ComposedInterfacesTestClass.MyMixinTarget)); var classContext = mixinConfiguration.ClassContexts.GetWithInheritance(typeof(ComposedInterfacesTestClass.MyMixinTarget)); involvedType.ClassContext = new ReflectedObject(classContext); var reportGenerator = new InterfaceReferenceReportGenerator(involvedType, new IdentifierGenerator <Type>(), Helpers.RemotionReflectorFactory.GetRemotionReflection()); var output = reportGenerator.GenerateXml(); var expectedOutput = new XElement( "ImplementedInterfaces", new XElement("ImplementedInterface", new XAttribute("ref", "0")) ); Assert.That(output.ToString(), Is.EqualTo(expectedOutput.ToString())); }
public void HasAscribableMixinOnMixedTypes() { Assert.That(MixinTypeUtility.HasAscribableMixin(typeof(BaseType1), typeof(BT1Mixin1)), Is.True); Assert.That(MixinTypeUtility.HasAscribableMixin(typeof(BaseType1), typeof(BT1Mixin2)), Is.True); Assert.That(MixinTypeUtility.HasAscribableMixin(typeof(BaseType1), typeof(IBT1Mixin1)), Is.True); Assert.That(MixinTypeUtility.HasAscribableMixin(typeof(GenericTargetClass <>), typeof(NullMixin)), Is.False); using (MixinConfiguration.BuildFromActive() .ForClass <BaseType1> ().Clear().AddMixins(typeof(GenericMixin <>)) .ForClass(typeof(GenericTargetClass <>)).AddMixin(typeof(NullMixin)) .EnterScope()) { Assert.That(MixinTypeUtility.HasAscribableMixin(typeof(BaseType1), typeof(GenericMixin <>)), Is.True); Assert.That(MixinTypeUtility.HasAscribableMixin(typeof(BaseType1), typeof(GenericMixin <int>)), Is.False); Assert.That(MixinTypeUtility.HasAscribableMixin(typeof(BaseType1), typeof(GenericMixin <string>)), Is.False); Assert.That(MixinTypeUtility.HasAscribableMixin(typeof(GenericTargetClass <>), typeof(NullMixin)), Is.True); } using (MixinConfiguration.BuildFromActive().ForClass <BaseType1> ().Clear().AddMixins(typeof(GenericMixin <int>)).EnterScope()) { Assert.That(MixinTypeUtility.HasAscribableMixin(typeof(BaseType1), typeof(GenericMixin <>)), Is.True); Assert.That(MixinTypeUtility.HasAscribableMixin(typeof(BaseType1), typeof(GenericMixin <int>)), Is.True); Assert.That(MixinTypeUtility.HasAscribableMixin(typeof(BaseType1), typeof(GenericMixin <string>)), Is.False); } Assert.That(MixinTypeUtility.HasAscribableMixin(typeof(BaseType1), typeof(object)), Is.True); }
public void EnterScope() { var configuration1 = new MixinConfiguration(); var configuration2 = new MixinConfiguration(); MixinConfiguration.SetActiveConfiguration(null); Assert.That(MixinConfiguration.HasActiveConfiguration, Is.False); using (configuration1.EnterScope()) { Assert.That(MixinConfiguration.ActiveConfiguration, Is.SameAs(configuration1)); using (configuration2.EnterScope()) { Assert.That(MixinConfiguration.ActiveConfiguration, Is.Not.SameAs(configuration1)); Assert.That(MixinConfiguration.ActiveConfiguration, Is.SameAs(configuration2)); } Assert.That(MixinConfiguration.ActiveConfiguration, Is.Not.SameAs(configuration2)); Assert.That(MixinConfiguration.ActiveConfiguration, Is.SameAs(configuration1)); } Assert.That(MixinConfiguration.HasActiveConfiguration, Is.False); }
private void CheckGrandOrdering() { using (MixinConfiguration.BuildFromActive().ForClass <BaseType7> () .EnsureMixin(typeof(BT7Mixin0)).WithDependency <IBT7Mixin7> () .EnsureMixin(typeof(BT7Mixin7)).WithDependency <IBT7Mixin4> () .EnsureMixin(typeof(BT7Mixin4)).WithDependency <IBT7Mixin6> () .EnsureMixin(typeof(BT7Mixin6)).WithDependency <IBT7Mixin2> () .EnsureMixin(typeof(BT7Mixin9)).WithDependency <IBT7Mixin8> () .EnterScope()) { var bt7 = BuildMixedInstanceWithActiveConfiguration <BaseType7>(); Assert.That( bt7.One(7), Is.EqualTo( "BT7Mixin0.One(7)-BT7Mixin4.One(7)-BT7Mixin6.One(7)-BT7Mixin2.One(7)" + "-BT7Mixin3.One(7)-BT7Mixin1.BT7Mixin1Specific" + "-BaseType7.Three" + "-BT7Mixin2.Three-BaseType7.Three" + "-BT7Mixin1.One(7)-BaseType7.One(7)" + "-BT7Mixin3.One(7)-BT7Mixin1.BT7Mixin1Specific" + "-BaseType7.Three" + "-BT7Mixin2.Three-BaseType7.Three" + "-BT7Mixin1.One(7)-BaseType7.One(7)" + "-BaseType7.Two" + "-BT7Mixin2.Two")); Assert.That( bt7.One("bar"), Is.EqualTo( "BT7Mixin0.One(bar)-BT7Mixin4.One(bar)-BT7Mixin6.One(bar)-BT7Mixin2.One(bar)" + "-BT7Mixin3.One(bar)-BT7Mixin1.BT7Mixin1Specific" + "-BaseType7.Three" + "-BT7Mixin2.Three-BaseType7.Three" + "-BT7Mixin1.One(bar)-BaseType7.One(bar)" + "-BT7Mixin3.One(bar)-BT7Mixin1.BT7Mixin1Specific" + "-BaseType7.Three" + "-BT7Mixin2.Three-BaseType7.Three" + "-BT7Mixin1.One(bar)-BaseType7.One(bar)" + "-BaseType7.Two" + "-BT7Mixin2.Two")); Assert.That(bt7.Two(), Is.EqualTo("BT7Mixin2.Two")); Assert.That(bt7.Three(), Is.EqualTo("BT7Mixin2.Three-BaseType7.Three")); Assert.That(bt7.Four(), Is.EqualTo("BT7Mixin2.Four-BaseType7.Four-BT7Mixin9.Five-BT7Mixin8.Five-BaseType7.Five-BaseType7.NotOverridden")); Assert.That(bt7.Five(), Is.EqualTo("BT7Mixin9.Five-BT7Mixin8.Five-BaseType7.Five")); var targetClassDefinition = DefinitionObjectMother.GetActiveTargetClassDefinition(typeof(BaseType7)); Assert.That(targetClassDefinition.Mixins.Count, Is.EqualTo(11)); // This part is fixed, independent of the algorithm: // Group 1 with internal ordering CheckRelativeMixinOrdering( targetClassDefinition, typeof(BT7Mixin0), typeof(BT7Mixin7), typeof(BT7Mixin4), typeof(BT7Mixin6), typeof(BT7Mixin2), typeof(BT7Mixin3), typeof(BT7Mixin1)); // Group 2 with internal ordering CheckRelativeMixinOrdering( targetClassDefinition, typeof(BT7Mixin10), typeof(BT7Mixin9), typeof(BT7Mixin8)); // Group 3 consists of just BT7Mixin5 // This part depends on the algorithm: var expectedBaseType7OrderedMixinTypesGrand = new[] { typeof(BT7Mixin0), typeof(BT7Mixin10), typeof(BT7Mixin5), typeof(BT7Mixin7), typeof(BT7Mixin9), typeof(BT7Mixin4), typeof(BT7Mixin8), typeof(BT7Mixin6), typeof(BT7Mixin2), typeof(BT7Mixin3), typeof(BT7Mixin1) }; Assert.That(targetClassDefinition.Mixins.Select(m => m.Type), Is.EqualTo(expectedBaseType7OrderedMixinTypesGrand)); } }
public void MixinDefinitionsAreSortedCorrectlyGrand() { using (MixinConfiguration .BuildFromActive() .ForClass <BaseType7>() .Clear() .AddMixins( typeof(BT7Mixin0), typeof(BT7Mixin1), typeof(BT7Mixin2), typeof(BT7Mixin3), typeof(BT7Mixin4), typeof(BT7Mixin5), typeof(BT7Mixin6), typeof(BT7Mixin7), typeof(BT7Mixin8), typeof(BT7Mixin9), typeof(BT7Mixin10)) .EnterScope()) { CheckGrandOrdering(); } using (MixinConfiguration .BuildFromActive() .ForClass <BaseType7>() .Clear() .AddMixins( typeof(BT7Mixin10), typeof(BT7Mixin9), typeof(BT7Mixin8), typeof(BT7Mixin7), typeof(BT7Mixin6), typeof(BT7Mixin5), typeof(BT7Mixin4), typeof(BT7Mixin3), typeof(BT7Mixin2), typeof(BT7Mixin1), typeof(BT7Mixin0)) .EnterScope()) { CheckGrandOrdering(); } using (MixinConfiguration .BuildFromActive() .ForClass <BaseType7>() .Clear() .AddMixins( typeof(BT7Mixin5), typeof(BT7Mixin8), typeof(BT7Mixin9), typeof(BT7Mixin2), typeof(BT7Mixin1), typeof(BT7Mixin10), typeof(BT7Mixin4), typeof(BT7Mixin0), typeof(BT7Mixin6), typeof(BT7Mixin3), typeof(BT7Mixin7)) .EnterScope()) { CheckGrandOrdering(); } }
public void Initialization_Empty() { var configuration = new MixinConfiguration(); Assert.That(configuration.ClassContexts, Is.Empty); }
public void TearDown() { MixinConfiguration.SetMasterConfiguration(_oldMasterConfiguration); MixinConfiguration.SetActiveConfiguration(_oldActiveConfiguration); }
public void SetUp() { _oldMasterConfiguration = MixinConfiguration.GetMasterConfiguration(); _oldActiveConfiguration = MixinConfiguration.ActiveConfiguration; }
private void SetTargetClassDefinition(InvolvedType involvedType, MixinConfiguration mixinConfiguration) { involvedType.TargetClassDefinition = new ReflectedObject (TargetClassDefinitionUtility.GetConfiguration (involvedType.Type, mixinConfiguration)); }
/// <summary> /// Builds a configuration object and calls the <see cref="EnterScope"/> method on it, thus activating the configuration for the current /// thread. The previous configuration is restored when the returned object's <see cref="IDisposable.Dispose"/> method is called (e.g. by a /// using statement). /// </summary> /// <returns>An <see cref="IDisposable"/> object for restoring the original configuration.</returns> public virtual IDisposable EnterScope() { MixinConfiguration configuration = BuildConfiguration(); return(configuration.EnterScope()); }
private ReflectedObject GetInterfaceIntroductions(InvolvedType targetType, Type mixinType, MixinConfiguration mixinConfiguration) { var targetClassDefinition = TargetClassDefinitionUtility.GetConfiguration (targetType.Type, mixinConfiguration); return new ReflectedObject (targetClassDefinition.GetMixinByConfiguredType (mixinType).InterfaceIntroductions); }
public void SetUp() { _mixinConfiguration = MixinConfiguration.BuildNew().ForClass<AdditionalDependenciesTest.TargetClass>() .AddMixin<AdditionalDependenciesTest.Mixin1>() .AddMixin<AdditionalDependenciesTest.Mixin2>() .AddMixin<AdditionalDependenciesTest.Mixin3>() .WithDependencies<AdditionalDependenciesTest.Mixin1, AdditionalDependenciesTest.Mixin2>() .BuildConfiguration(); _outputFormatter = new OutputFormatter(); _identifierGenerator = new IdentifierGenerator<Type>(); }
public void TearDown() { MixinConfiguration.SetActiveConfiguration(null); }
public virtual void TearDown() { MixinConfiguration.SetActiveConfiguration(_previousConfiguration); }
public MixinConfigurationBuilder(MixinConfiguration parentConfiguration) { _parentConfiguration = parentConfiguration; }
public virtual void SetUp() { _previousConfiguration = MixinConfiguration.HasActiveConfiguration ? MixinConfiguration.ActiveConfiguration : null; }