public void NotOverriddenAbstractMixinMethodSucceeds()
        {
            TargetClassDefinition bt1    = DefinitionObjectMother.BuildUnvalidatedDefinition(typeof(BaseType1), typeof(MixinWithAbstractMembers));
            MixinDefinition       mixin  = bt1.Mixins[typeof(MixinWithAbstractMembers)];
            MethodDefinition      method = mixin.Methods[typeof(MixinWithAbstractMembers).GetMethod("AbstractMethod", BindingFlags.Instance | BindingFlags.NonPublic)];

            Assert.That(method.Overrides.Count, Is.EqualTo(0));
        }
Example #2
0
        public void WithNonMultipleInheritedAttributesTheTargetClassWins()
        {
            TargetClassDefinition definition = DefinitionObjectMother.BuildUnvalidatedDefinition(
                typeof(BaseType1), typeof(MixinAddingBT1Attribute));

            Assert.That(definition.ReceivedAttributes.GetItemCount(typeof(BT1Attribute)), Is.EqualTo(0));
            Assert.That(definition.CustomAttributes.GetItemCount(typeof(BT1Attribute)), Is.EqualTo(1));
        }
Example #3
0
        public void SucceedsIfDuckNextCallDependency()
        {
            TargetClassDefinition definition = DefinitionObjectMother.BuildUnvalidatedDefinition(typeof(ClassFulfillingAllMemberRequirementsDuck),
                                                                                                 typeof(MixinRequiringAllMembersNextCall));
            var log = Validator.Validate(definition);

            AssertSuccess(log);
        }
Example #4
0
        public void SucceedsIfCrossOverridesNotOnSameMethods()
        {
            TargetClassDefinition definition = DefinitionObjectMother.BuildUnvalidatedDefinition(typeof(ClassOverridingSingleMixinMethod),
                                                                                                 typeof(MixinOverridingClassMethod));
            var log = Validator.Validate(definition);

            AssertSuccess(log);
        }
Example #5
0
        public void FailsIfSealedTargetClass()
        {
            TargetClassDefinition bc = DefinitionObjectMother.BuildUnvalidatedDefinition(typeof(DateTime));
            var log = Validator.Validate(bc);

            Assert.That(HasFailure("Remotion.Mixins.Validation.Rules.DefaultTargetClassRules.TargetClassMustNotBeSealed", log), Is.True);
            Assert.That(log.GetNumberOfWarnings(), Is.EqualTo(0));
        }
Example #6
0
        public void FailsIfNestedTargetClassIsNotPublic()
        {
            TargetClassDefinition definition = DefinitionObjectMother.BuildUnvalidatedDefinition(typeof(PublicNester.InternalNested),
                                                                                                 typeof(NullMixin));
            var log = Validator.Validate(definition);

            Assert.That(HasFailure("Remotion.Mixins.Validation.Rules.DefaultTargetClassRules.TargetClassMustBePublic", log), Is.True);
        }
        public void SucceedsIfEmptyTargetCallDependencyNotFulfilled()
        {
            TargetClassDefinition definition = DefinitionObjectMother.BuildUnvalidatedDefinition(typeof(BaseType3), typeof(MixinWithUnsatisfiedEmptyTargetCallDependency));
            var log = Validator.Validate(
                definition.Mixins[typeof(MixinWithUnsatisfiedEmptyTargetCallDependency)].TargetCallDependencies[typeof(IEmptyInterface)]);

            AssertSuccess(log);
        }
        public void SucceedsIfCircularTargetCallDependency()
        {
            TargetClassDefinition definition = DefinitionObjectMother.BuildUnvalidatedDefinition(typeof(BaseType3), typeof(MixinWithCircularTargetCallDependency1), typeof(MixinWithCircularTargetCallDependency2));
            var log = Validator.Validate(
                definition.Mixins[typeof(MixinWithCircularTargetCallDependency1)]);

            AssertSuccess(log);
        }
        public void GenericMixinsAreSetToConstraintOrBaseType()
        {
            MixinDefinition def = DefinitionObjectMother.BuildUnvalidatedDefinition(typeof(BaseType3), typeof(BT3Mixin3 <,>))
                                  .GetMixinByConfiguredType(typeof(BT3Mixin3 <,>));

            Assert.That(def.Type.GetGenericArguments()[0], Is.EqualTo(typeof(BaseType3)));
            Assert.That(def.Type.GetGenericArguments()[1], Is.EqualTo(typeof(IBaseType33)));
        }
Example #10
0
        public void SucceedsIfNestedTargetClassIsPublic()
        {
            TargetClassDefinition definition = DefinitionObjectMother.BuildUnvalidatedDefinition(typeof(PublicNester.PublicNested),
                                                                                                 typeof(NullMixin));
            var log = Validator.Validate(definition);

            AssertSuccess(log);
        }
Example #11
0
        public void SucceedsIfTargetClassWinsWhenDefiningAttributes()
        {
            TargetClassDefinition definition = DefinitionObjectMother.BuildUnvalidatedDefinition(typeof(BaseType1),
                                                                                                 typeof(MixinAddingBT1Attribute));
            var log = Validator.Validate(definition);

            AssertSuccess(log);
        }
Example #12
0
        public void FailsIfOverriddenMixinMethodNotVirtual()
        {
            TargetClassDefinition definition = DefinitionObjectMother.BuildUnvalidatedDefinition(typeof(ClassOverridingSingleMixinMethod),
                                                                                                 typeof(MixinWithNonVirtualMethodToBeOverridden));
            var log = Validator.Validate(definition);

            Assert.That(HasFailure("Remotion.Mixins.Validation.Rules.DefaultMethodRules.OverriddenMethodMustBeVirtual", log), Is.True);
        }
Example #13
0
        public void FailsIfEmptyNextCallDependencyNotFulfilled()
        {
            TargetClassDefinition definition = DefinitionObjectMother.BuildUnvalidatedDefinition(typeof(BaseType3), typeof(MixinWithUnsatisfiedEmptyNextCallDependency));
            var log = Validator.Validate(
                definition.Mixins[typeof(MixinWithUnsatisfiedEmptyNextCallDependency)].NextCallDependencies[typeof(IEmptyInterface)]);

            Assert.That(HasFailure("Remotion.Mixins.Validation.Rules.DefaultNextCallDependencyRules.DependencyMustBeSatisfied", log), Is.True);
        }
Example #14
0
        public void WithNonMultipleInheritedAttributesOnMemberTheTargetClassWins()
        {
            MethodDefinition definition = DefinitionObjectMother.BuildUnvalidatedDefinition(
                typeof(BaseType1), typeof(MixinAddingBT1AttributeToMember)).Methods[typeof(BaseType1).GetMethod("VirtualMethod", Type.EmptyTypes)];

            Assert.That(definition.ReceivedAttributes.GetItemCount(typeof(BT1Attribute)), Is.EqualTo(0));
            Assert.That(definition.CustomAttributes.GetItemCount(typeof(BT1Attribute)), Is.EqualTo(1));
        }
Example #15
0
        public void MultipleAttributes()
        {
            TargetClassDefinition definition = DefinitionObjectMother.BuildUnvalidatedDefinition(
                typeof(BaseTypeWithAllowMultiple), typeof(MixinAddingAllowMultipleToClassAndMember), typeof(MixinAddingAllowMultipleToClassAndMember2));

            Assert.That(definition.ReceivedAttributes.GetItemCount(typeof(MultiAttribute)), Is.EqualTo(3));
            Assert.That(definition.CustomAttributes.GetItemCount(typeof(MultiAttribute)), Is.EqualTo(1));
        }
Example #16
0
        public void GetConcreteMixinTypeIdentifier_NoOverrides()
        {
            var expectedIdentifier = new ConcreteMixinTypeIdentifier(typeof(NullMixin), new HashSet <MethodInfo>(), new HashSet <MethodInfo> ());

            var definition = DefinitionObjectMother.BuildUnvalidatedDefinition(typeof(NullTarget), typeof(NullMixin)).Mixins[0];

            Assert.That(definition.GetConcreteMixinTypeIdentifier(), Is.EqualTo(expectedIdentifier));
        }
Example #17
0
        public void FailsIfCrossOverridesOnSameMethods()
        {
            TargetClassDefinition definition = DefinitionObjectMother.BuildUnvalidatedDefinition(typeof(ClassOverridingSingleMixinMethod),
                                                                                                 typeof(MixinOverridingSameClassMethod));
            var log = Validator.Validate(definition);

            Assert.That(HasFailure("Remotion.Mixins.Validation.Rules.DefaultMethodRules.NoCircularOverrides", log), Is.True);
        }
        public void SucceedsIfNoPublicOrProtectedDefaultCtorInMixinClassWithoutOverriddenMembers()
        {
            TargetClassDefinition definition = DefinitionObjectMother.BuildUnvalidatedDefinition(typeof(NullTarget),
                                                                                                 typeof(MixinWithPrivateCtorAndVirtualMethod));
            var log = Validator.Validate(definition);

            AssertSuccess(log);
        }
Example #19
0
        public void FailsIfNoPublicOrProtectedCtorInTargetClass()
        {
            TargetClassDefinition definition = DefinitionObjectMother.BuildUnvalidatedDefinition(typeof(ClassWithPrivateCtor),
                                                                                                 typeof(NullMixin));
            var log = Validator.Validate(definition);

            Assert.That(HasFailure("Remotion.Mixins.Validation.Rules.DefaultTargetClassRules.TargetClassMustHavePublicOrProtectedCtor", log), Is.True);
        }
        public void FailsIfNoMixinBaseWith()
        {
            TargetClassDefinition definition = DefinitionObjectMother.BuildUnvalidatedDefinition(typeof(ClassWithVirtualMethod),
                                                                                                 typeof(MixinWithProtectedOverriderWithoutMixinBase));
            var log = Validator.Validate(definition);

            Assert.That(HasFailure("Remotion.Mixins.Validation.Rules.DefaultMixinRules.MixinNeedingDerivedTypeMustBeDerivedFromMixinBase",
                                   log), Is.True);
        }
        public void FailsIfNoPublicOrProtectedDefaultCtorInMixinClassWithOverriddenMembers()
        {
            TargetClassDefinition definition = DefinitionObjectMother.BuildUnvalidatedDefinition(typeof(ClassOverridingSingleMixinMethod),
                                                                                                 typeof(MixinWithPrivateCtorAndVirtualMethod));
            var log = Validator.Validate(definition);

            Assert.That(HasFailure("Remotion.Mixins.Validation.Rules.DefaultMixinRules.MixinWithOverriddenMembersMustHavePublicOrProtectedDefaultCtor",
                                   log), Is.True);
        }
        public void CollectsUnexpectedExceptions()
        {
            TargetClassDefinition bc = DefinitionObjectMother.BuildUnvalidatedDefinition(typeof(DateTime));
            var log = Validator.Validate(bc, new ThrowingRuleSet());

            Assert.That(log.GetNumberOfUnexpectedExceptions() > 0, Is.True);
            var results = new List <ValidationResult> (log.GetResults());

            Assert.That(results[0].Exceptions[0].Exception is InvalidOperationException, Is.True);
        }
Example #23
0
        public void SucceedsIfOverridingMembersAreProtected()
        {
            TargetClassDefinition definition =
                DefinitionObjectMother.BuildUnvalidatedDefinition(typeof(BaseType1), typeof(MixinWithProtectedOverrider));

            Assert.That(definition.Mixins[0].HasProtectedOverriders(), Is.True);
            var log = Validator.Validate(definition);

            AssertSuccess(log);
        }
Example #24
0
        public void FailsTwiceIfDuplicateAttributeAddedByMixinToMember()
        {
            TargetClassDefinition definition = DefinitionObjectMother.BuildUnvalidatedDefinition(typeof(ClassWithVirtualMethod),
                                                                                                 typeof(MixinAddingBT1AttributeToMember), typeof(MixinAddingBT1AttributeToMember2));
            var log = Validator.Validate(definition);

            Assert.That(HasFailure(
                            "Remotion.Mixins.Validation.Rules.DefaultAttributeIntroductionRules.AllowMultipleRequiredIfAttributeIntroducedMultipleTimes", log), Is.True);
            Assert.That(log.GetNumberOfFailures(), Is.EqualTo(2));
        }
        public void Attributes()
        {
            TargetClassDefinition targetClass = DefinitionObjectMother.BuildUnvalidatedDefinition(typeof(ClassWithManyAttributes),
                                                                                                  typeof(ClassWithManyAttributes));
            MixinDefinition mixin = targetClass.Mixins[typeof(ClassWithManyAttributes)];

            CheckAttributes(targetClass);
            CheckAttributes(mixin);

            CheckAttributes(targetClass.Methods[typeof(ClassWithManyAttributes).GetMethod("Foo")]);
            CheckAttributes(mixin.Methods[typeof(ClassWithManyAttributes).GetMethod("Foo")]);
        }
Example #26
0
        public void SucceedsIfPublicIntroducedMethod_HasSameNameButDifferentSignatureFromTargetClassMethod()
        {
            TargetClassDefinition classDefinition =
                DefinitionObjectMother.BuildUnvalidatedDefinition(
                    typeof(TargetClassWithSameNamesDifferentSignaturesAsIntroducedMembers),
                    typeof(MixinIntroducingMembersWithDifferentVisibilities));
            MethodIntroductionDefinition definition = classDefinition.ReceivedInterfaces[typeof(IMixinIntroducingMembersWithDifferentVisibilities)].IntroducedMethods[typeof(IMixinIntroducingMembersWithDifferentVisibilities).GetMethod("MethodWithPublicVisibility")];

            var log = Validator.Validate(definition);

            AssertSuccess(log);
        }
Example #27
0
        public void SucceedsIfPublicIntroducedProperty_DoesNotHaveSameNameAsOther()
        {
            TargetClassDefinition classDefinition =
                DefinitionObjectMother.BuildUnvalidatedDefinition(
                    typeof(NullTarget),
                    typeof(MixinIntroducingMembersWithDifferentVisibilities));
            PropertyIntroductionDefinition definition = classDefinition.ReceivedInterfaces[typeof(IMixinIntroducingMembersWithDifferentVisibilities)].IntroducedProperties[typeof(IMixinIntroducingMembersWithDifferentVisibilities).GetProperty("PropertyWithPublicVisibility")];

            var log = Validator.Validate(definition);

            AssertSuccess(log);
        }
Example #28
0
        public void FailsIfPublicIntroducedProperty_HasSameNameAndSignatureAsTargetClassProperty()
        {
            TargetClassDefinition classDefinition =
                DefinitionObjectMother.BuildUnvalidatedDefinition(
                    typeof(TargetClassWithSameNamesAsIntroducedMembers),
                    typeof(MixinIntroducingMembersWithDifferentVisibilities));
            PropertyIntroductionDefinition definition = classDefinition.ReceivedInterfaces[typeof(IMixinIntroducingMembersWithDifferentVisibilities)].IntroducedProperties[typeof(IMixinIntroducingMembersWithDifferentVisibilities).GetProperty("PropertyWithPublicVisibility")];

            var log = Validator.Validate(definition);

            Assert.That(HasFailure("Remotion.Mixins.Validation.Rules.DefaultPropertyIntroductionRules.PublicPropertyNameMustBeUniqueInTargetClass", log), Is.True);
        }
Example #29
0
        public void SucceedsIfPrivateIntroducedProperty_HasSameNameAsTargetClassProperty()
        {
            TargetClassDefinition classDefinition =
                DefinitionObjectMother.BuildUnvalidatedDefinition(
                    typeof(TargetClassWithSameNamesAsIntroducedMembers),
                    typeof(MixinIntroducingMembersWithDifferentVisibilities));
            PropertyIntroductionDefinition definition = classDefinition.ReceivedInterfaces[typeof(IMixinIntroducingMembersWithDifferentVisibilities)].IntroducedProperties[typeof(IMixinIntroducingMembersWithDifferentVisibilities).GetProperty("PropertyWithDefaultVisibility")];

            var log = Validator.Validate(definition);

            AssertSuccess(log);
        }
Example #30
0
        public void FailsIfPublicIntroducedEvent_HasSameNameButDifferentSignatureFromTargetClassEvent()
        {
            TargetClassDefinition classDefinition =
                DefinitionObjectMother.BuildUnvalidatedDefinition(
                    typeof(TargetClassWithSameNamesDifferentSignaturesAsIntroducedMembers),
                    typeof(MixinIntroducingMembersWithDifferentVisibilities));
            EventIntroductionDefinition definition = classDefinition.ReceivedInterfaces[typeof(IMixinIntroducingMembersWithDifferentVisibilities)].IntroducedEvents[typeof(IMixinIntroducingMembersWithDifferentVisibilities).GetEvent("EventWithPublicVisibility")];

            var log = Validator.Validate(definition);

            Assert.That(HasFailure("Remotion.Mixins.Validation.Rules.DefaultEventIntroductionRules.PublicEventNameMustBeUniqueInTargetClass", log), Is.True);
        }