public void InternalAttributesAreIgnored()
        {
            var context    = ClassContextObjectMother.Create(typeof(ClassWithInternalAttribute));
            var definition = TargetClassDefinitionFactory.CreateAndValidate(context);

            Assert.That(definition.CustomAttributes.ContainsKey(typeof(InternalStuffAttribute)), Is.False);
        }
Example #2
0
        public void Build_AddsAttributes()
        {
            var classContext          = ClassContextObjectMother.Create(typeof(BaseType1));
            var targetClassDefinition = _builder.Build(classContext);

            Assert.That(targetClassDefinition.CustomAttributes, Is.Not.Empty);
        }
Example #3
0
        public void GetClassContextsToInheritFrom()
        {
            var fakeClassContext = ClassContextObjectMother.Create(typeof(object));
            var result           = _policy.GetClassContextsToInheritFrom(typeof(BaseType1), t => fakeClassContext);

            Assert.That(result.ToArray(), Is.EqualTo(new[] { fakeClassContext }));
        }
Example #4
0
        public void Build_AnalyzesSuppressorsOnClass()
        {
            var classContext          = ClassContextObjectMother.Create(typeof(ClassWithSuppressAttribute), typeof(MixinAddingBT1Attribute));
            var targetClassDefinition = _builder.Build(classContext);

            Assert.That(targetClassDefinition.ReceivedAttributes.Select(a => a.AttributeType).ToArray(), Is.Empty);
        }
        public void Equals_True()
        {
            var c1 =
                new ClassContext(
                    typeof(BaseType1),
                    new[] { CreateBT1Mixin1Context(), CreateBT2Mixin2Context() },
                    new[] { typeof(IBT5MixinC1), typeof(IBT5MixinC2) });
            var c2 =
                new ClassContext(
                    typeof(BaseType1),
                    new[] { CreateBT1Mixin1Context(), CreateBT2Mixin2Context() },
                    new[] { typeof(IBT5MixinC1), typeof(IBT5MixinC2) });
            var c3 =
                new ClassContext(
                    typeof(BaseType1),
                    new[] { CreateBT2Mixin2Context(), CreateBT1Mixin1Context() },
                    new[] { typeof(IBT5MixinC1), typeof(IBT5MixinC2) });
            var c4 =
                new ClassContext(
                    typeof(BaseType1),
                    new[] { CreateBT1Mixin1Context(), CreateBT2Mixin2Context() },
                    new[] { typeof(IBT5MixinC2), typeof(IBT5MixinC1) });

            Assert.That(c1, Is.EqualTo(c1));
            Assert.That(c2, Is.EqualTo(c1));
            Assert.That(c3, Is.EqualTo(c1));
            Assert.That(c4, Is.EqualTo(c1));

            var c5 = ClassContextObjectMother.Create(typeof(BaseType1));
            var c6 = ClassContextObjectMother.Create(typeof(BaseType1));

            Assert.That(c6, Is.EqualTo(c5));
        }
Example #6
0
        public void Build_AddsMixins()
        {
            var classContext          = ClassContextObjectMother.Create(typeof(BaseType1), typeof(BT1Mixin1));
            var targetClassDefinition = _builder.Build(classContext);

            Assert.That(targetClassDefinition.Mixins.Select(m => m.Type).ToArray(), Has.Member(typeof(BT1Mixin1)));
        }
        public void SetUp()
        {
            _classContextBuilderWithParent = new ClassContextBuilder(typeof(NullTarget));
            _classContextBuilderWithParent.AddMixin(typeof(NullMixin2));
            _parentContextWithBuilder = ClassContextObjectMother.Create(typeof(NullTarget), typeof(NullMixin));

            _classContextBuilderWithIndirectParent = new ClassContextBuilder(typeof(DerivedNullTarget));

            _classContextBuilderWithoutParent = new ClassContextBuilder(typeof(BaseType4));
            _classContextBuilderWithParent.AddMixin(typeof(BT4Mixin1));

            _buildersWithParentContexts = new Dictionary <Type, Tuple <ClassContextBuilder, ClassContext> > ();
            _buildersWithParentContexts.Add(_classContextBuilderWithParent.TargetType, Tuple.Create(_classContextBuilderWithParent, _parentContextWithBuilder));
            _buildersWithParentContexts.Add(_classContextBuilderWithoutParent.TargetType, Tuple.Create(_classContextBuilderWithoutParent, (ClassContext)null));

            _parentContextWithoutBuilder = ClassContextObjectMother.Create(typeof(BaseType1));
            _parentContexts = new ClassContextCollection(_parentContextWithoutBuilder, _parentContextWithBuilder);

            _inheritancePolicyMock = MockRepository.GenerateMock <IMixinInheritancePolicy> ();
            _inheritedContext      = ClassContextObjectMother.Create(typeof(object), typeof(NullMixin));

            var classContextBuilders = new[] { _classContextBuilderWithoutParent, _classContextBuilderWithIndirectParent, _classContextBuilderWithParent };

            _builder = new InheritanceResolvingClassContextBuilder(classContextBuilders, _parentContexts, _inheritancePolicyMock);
        }
Example #8
0
        public void Build_AnalyzesSuppressorsOnMixins()
        {
            var classContext          = ClassContextObjectMother.Create(typeof(NullTarget), typeof(MixinAddingBT1Attribute), typeof(MixinSuppressingBT1Attribute));
            var targetClassDefinition = _builder.Build(classContext);

            Assert.That(targetClassDefinition.ReceivedAttributes.Select(a => a.AttributeType).ToArray(), Has.No.Member(typeof(BT1Attribute)));
        }
        public void GetHashCode_Equal()
        {
            var c1 =
                new ClassContext(
                    typeof(BaseType1),
                    new[] { CreateBT1Mixin1Context(), CreateBT2Mixin2Context() },
                    new[] { typeof(IBT5MixinC1), typeof(IBT5MixinC2) });
            var c2 =
                new ClassContext(
                    typeof(BaseType1),
                    new[] { CreateBT1Mixin1Context(), CreateBT2Mixin2Context() },
                    new[] { typeof(IBT5MixinC1), typeof(IBT5MixinC2) });
            var c3 =
                new ClassContext(
                    typeof(BaseType1),
                    new[] { CreateBT2Mixin2Context(), CreateBT1Mixin1Context() },
                    new[] { typeof(IBT5MixinC1), typeof(IBT5MixinC2) });
            var c4 =
                new ClassContext(
                    typeof(BaseType1),
                    new[] { CreateBT1Mixin1Context(), CreateBT2Mixin2Context() },
                    new[] { typeof(IBT5MixinC2), typeof(IBT5MixinC1) });

            Assert.That(c2.GetHashCode(), Is.EqualTo(c1.GetHashCode()));
            Assert.That(c3.GetHashCode(), Is.EqualTo(c1.GetHashCode()));
            Assert.That(c4.GetHashCode(), Is.EqualTo(c1.GetHashCode()));

            var c5 = ClassContextObjectMother.Create(typeof(BaseType1));
            var c6 = ClassContextObjectMother.Create(typeof(BaseType1));

            Assert.That(c6.GetHashCode(), Is.EqualTo(c5.GetHashCode()));
        }
        public void Equals_False_ClassType()
        {
            var c1 = ClassContextObjectMother.Create(typeof(BaseType1));
            var c2 = ClassContextObjectMother.Create(typeof(BaseType2));

            Assert.That(c2, Is.Not.EqualTo(c1));
        }
Example #11
0
        public void MixinContext()
        {
            ClassContext baseContext = new ClassContextBuilder(typeof(string)).AddMixin <DateTime>().WithDependency <int>().BuildClassContext();
            ClassContext inheritor   = ClassContextObjectMother.Create(typeof(double)).InheritFrom(new[] { baseContext });

            Assert.That(inheritor.Mixins[typeof(DateTime)], Is.EqualTo(baseContext.Mixins[typeof(DateTime)]));
        }
Example #12
0
        public void Build_SetsContext()
        {
            var classContext = ClassContextObjectMother.Create(typeof(BaseType1));

            var targetClassDefinition = _builder.Build(classContext);

            Assert.That(targetClassDefinition.ConfigurationContext, Is.SameAs(classContext));
        }
Example #13
0
        public void ContainsComposedInterface()
        {
            var baseContext = new ClassContext(typeof(string), new MixinContext[0], new[] { typeof(object) });

            ClassContext inheritor = ClassContextObjectMother.Create(typeof(double)).InheritFrom(new[] { baseContext });

            Assert.That(inheritor.ComposedInterfaces, Has.Member(typeof(object)));
        }
        public void CreateTargetClassDefinition_ReturnsValidClassDefinition()
        {
            var context = ClassContextObjectMother.Create(typeof(BaseType1));
            var def     = TargetClassDefinitionFactory.CreateAndValidate(context);

            Assert.That(def, Is.Not.Null);
            Assert.That(def.ConfigurationContext, Is.SameAs(context));
        }
Example #15
0
        public void InheritFrom_Mixins()
        {
            var baseContext = ClassContextObjectMother.Create(typeof(string), typeof(DateTime), typeof(int), typeof(DerivedNullTarget));
            var inheritor   = ClassContextObjectMother.Create(typeof(double)).InheritFrom(new[] { baseContext });

            Assert.That(inheritor.Mixins.Count, Is.EqualTo(3));
            Assert.That(inheritor.Mixins, Is.EquivalentTo(baseContext.Mixins));
        }
Example #16
0
        public void GetClassContextSimple()
        {
            var simpleContext = ClassContextObjectMother.Create(typeof(object), typeof(string));
            ConcreteMixedTypeAttribute attribute = CreateAttribute(simpleContext);
            ClassContext regeneratedContext      = attribute.GetClassContext();

            Assert.That(simpleContext, Is.EqualTo(regeneratedContext));
            Assert.That(simpleContext, Is.Not.SameAs(regeneratedContext));
        }
Example #17
0
        public void Build_AppliesRequiredBaseTypeMethods()
        {
            var classContext = ClassContextObjectMother.Create(typeof(BaseType3), typeof(BT3Mixin1));

            var targetClassDefinition = _builder.Build(classContext);

            Assert.That(targetClassDefinition.RequiredNextCallTypes[typeof(IBaseType31)].Methods.Select(r => r.InterfaceMethod).ToArray(),
                        Has.Member(typeof(IBaseType31).GetMethod("IfcMethod")));
        }
Example #18
0
        public void FromClassContextSimple()
        {
            var simpleContext = ClassContextObjectMother.Create(typeof(object), typeof(string));
            ConcreteMixedTypeAttribute attribute = CreateAttribute(simpleContext);

            var deserializer = new AttributeClassContextDeserializer(attribute.ClassContextData);

            Assert.That(ClassContext.Deserialize(deserializer), Is.EqualTo(simpleContext));
        }
        public void ConstructorWithMixinParameters()
        {
            var context = ClassContextObjectMother.Create(typeof(BaseType1), typeof(BT1Mixin1), typeof(BT1Mixin2));

            Assert.That(context.Mixins.Count, Is.EqualTo(2));
            Assert.That(context.Mixins.ContainsKey(typeof(BT1Mixin1)), Is.True);
            Assert.That(context.Mixins.ContainsKey(typeof(BT1Mixin2)), Is.True);
            Assert.That(context.Mixins.ContainsKey(typeof(BT2Mixin1)), Is.False);
        }
Example #20
0
        public void BaseAndDerivedMixin_CanBeInherited_DifferentOrder()
        {
            ClassContext baseContext = new ClassContextBuilder(typeof(string)).AddMixin <DerivedNullMixin> ().AddMixin <NullMixin> ().BuildClassContext();
            ClassContext inheritor   = ClassContextObjectMother.Create(typeof(double)).InheritFrom(new[] { baseContext });

            Assert.That(inheritor.Mixins.Count, Is.EqualTo(2));
            Assert.That(inheritor.Mixins.ContainsKey(typeof(NullMixin)), Is.True);
            Assert.That(inheritor.Mixins.ContainsKey(typeof(DerivedNullMixin)), Is.True);
        }
        public void Equals_False_Mixins()
        {
            var c1 = ClassContextObjectMother.Create(typeof(BaseType1), typeof(BT1Mixin1));
            var c3 = ClassContextObjectMother.Create(typeof(BaseType1), typeof(BT1Mixin2));
            var c4 = ClassContextObjectMother.Create(typeof(BaseType1), typeof(BT1Mixin1), typeof(BT1Mixin2));

            Assert.That(c3, Is.Not.EqualTo(c1));
            Assert.That(c4, Is.Not.EqualTo(c1));
            Assert.That(c4, Is.Not.EqualTo(c3));
        }
Example #22
0
        public void Build_AnalyzesAttributeIntroductionsOnMembers()
        {
            var classContext          = ClassContextObjectMother.Create(typeof(GenericTargetClass <string>), typeof(MixinAddingBT1AttributeToMember));
            var targetClassDefinition = _builder.Build(classContext);

            var methodInfo = typeof(GenericTargetClass <string>).GetMethod("VirtualMethod");

            Assert.That(targetClassDefinition.Methods[methodInfo].ReceivedAttributes.Select(a => a.AttributeType).ToArray(),
                        Has.Member(typeof(BT1Attribute)));
        }
        public void Contains()
        {
            var cc3 = ClassContextObjectMother.Create(typeof(int));
            var cc4 = ClassContextObjectMother.Create(typeof(object), typeof(NullMixin));

            Assert.That(_collectionWithObjectAndString.Contains(_ccObjectWithMixin), Is.True);
            Assert.That(_collectionWithObjectAndString.Contains(_ccString), Is.True);
            Assert.That(_collectionWithObjectAndString.Contains(cc3), Is.False);
            Assert.That(_collectionWithObjectAndString.Contains(cc4), Is.False);
        }
Example #24
0
        public void Build_AddsProtectedInternalMembers()
        {
            var classContext = ClassContextObjectMother.Create(typeof(ClassWithDifferentMemberVisibilities));

            var targetClassDefinition = _builder.Build(classContext);

            Assert.That(targetClassDefinition.Methods.Where(m => m.Name == "ProtectedInternalMethod").ToArray(), Is.Not.Empty);
            Assert.That(targetClassDefinition.Properties.Where(p => p.Name == "ProtectedInternalProperty").ToArray(), Is.Not.Empty);
            Assert.That(targetClassDefinition.Events.Where(e => e.Name == "ProtectedInternalEvent").ToArray(), Is.Not.Empty);
        }
Example #25
0
        public void AttributeWithGenericType()
        {
            ClassContext context = ClassContextObjectMother.Create(typeof(List <>)).SpecializeWithTypeArguments(new[] { typeof(int) });

            Assert.That(context.Type, Is.EqualTo(typeof(List <int>)));
            ConcreteMixedTypeAttribute attribute = CreateAttribute(context);

            ClassContext regeneratedContext = attribute.GetClassContext();

            Assert.That(regeneratedContext.Type, Is.EqualTo(typeof(List <int>)));
        }
        public void Build_WithoutCachedContext_NoBuilder_WithoutInherited()
        {
            _inheritancePolicyMock
            .Expect(mock => mock.GetClassContextsToInheritFrom(Arg <Type> .Is.Anything, Arg <Func <Type, ClassContext> > .Is.Anything))
            .Return(new ClassContext[0]);
            _inheritancePolicyMock.Replay();

            var result = _builder.Build(typeof(BaseType2));

            Assert.That(result, Is.EqualTo(ClassContextObjectMother.Create(typeof(BaseType2))));
        }
        public void SetUp()
        {
            _ccObjectWithMixin             = ClassContextObjectMother.Create(typeof(object), typeof(NullMixin2));
            _ccString                      = ClassContextObjectMother.Create(typeof(string));
            _collectionWithObjectAndString = new ClassContextCollection(_ccObjectWithMixin, _ccString);

            _ccListOfT      = ClassContextObjectMother.Create(typeof(List <>));
            _ccListOfString = ClassContextObjectMother.Create(typeof(List <string>));

            _emptyCollection = new ClassContextCollection();
        }
        public void ApplyMixinDependencies_NotFound()
        {
            var originalMixinContext1 = MixinContextObjectMother.Create(mixinType: typeof(object), explicitDependencies: new[] { typeof(int) });
            var originalClassContext  = ClassContextObjectMother.Create(typeof(NullTarget), originalMixinContext1);
            var dependencies          = new[] { new MixinDependencySpecification(typeof(string), new[] { typeof(float) }) };

            Assert.That(
                () => originalClassContext.ApplyMixinDependencies(dependencies),
                Throws.InvalidOperationException.With.Message.EqualTo(
                    "The mixin 'System.String' is not configured for class 'Remotion.Mixins.UnitTests.Core.TestDomain.NullTarget'."));
        }
        public void BuildContext_MixinDependencies_AppliedWithInheritance()
        {
            _classBuilder.AddMixinDependency <BT1Mixin1, BT1Mixin2> ();
            _classBuilder.AddMixinDependency <BT1Mixin2, BT2Mixin1> ();

            var inheritedContext1 = ClassContextObjectMother.Create(typeof(NullTarget), typeof(BT1Mixin1));
            var inheritedContext2 = ClassContextObjectMother.Create(typeof(NullTarget), typeof(BT1Mixin2));
            var builtContext      = _classBuilder.BuildClassContext(new[] { inheritedContext1, inheritedContext2 });

            Assert.That(builtContext.Mixins[typeof(BT1Mixin1)].ExplicitDependencies, Has.Member(typeof(BT1Mixin2)));
            Assert.That(builtContext.Mixins[typeof(BT1Mixin2)].ExplicitDependencies, Has.Member(typeof(BT2Mixin1)));
        }
Example #30
0
        public void Build_AddsComposedInterfaces()
        {
            var classContext          = ClassContextObjectMother.Create(typeof(BaseType6), new[] { typeof(BT6Mixin1) }, new[] { typeof(ICBT6Mixin1) });
            var targetClassDefinition = _builder.Build(classContext);

            Assert.That(targetClassDefinition.ComposedInterfaceDependencies[typeof(ICBT6Mixin1)], Is.Not.Null);

            var requirement = targetClassDefinition.ComposedInterfaceDependencies[typeof(ICBT6Mixin1)].RequiredType;

            Assert.That(requirement, Is.Not.Null);
            Assert.That(targetClassDefinition.RequiredTargetCallTypes, Has.Member(requirement));
        }