public void ValidationException()
        {
            TargetClassDefinition definition = DefinitionObjectMother.BuildUnvalidatedDefinition(
                typeof(ClassOverridingSingleMixinMethod), typeof(AbstractMixinWithoutBase));

            var log     = new DefaultValidationLog();
            var visitor = new ValidatingVisitor(log);

            new DefaultMethodRules().Install(visitor);
            definition.Accept(visitor);

            var validationLogData = log.GetData();
            var exception         = new ValidationException(validationLogData);

            Assert.That(
                exception.Message,
                Is.EqualTo(
                    "Some parts of the mixin configuration could not be validated."
                    + Environment.NewLine
                    + "MethodDefinition 'Remotion.Mixins.UnitTests.Core.Validation.ValidationTestDomain.AbstractMixinWithoutBase.AbstractMethod', 6 rules "
                    + "executed"
                    + Environment.NewLine
                    + "Context: Remotion.Mixins.UnitTests.Core.Validation.ValidationTestDomain.AbstractMixinWithoutBase -> "
                    + "Remotion.Mixins.UnitTests.Core.TestDomain.ClassOverridingSingleMixinMethod"
                    + Environment.NewLine
                    + "  failures - 1"
                    + Environment.NewLine
                    + "    A target class overrides a method from one of its mixins, but the mixin is not derived from one of the Mixin<...> base classes. "
                    + "(Remotion.Mixins.Validation.Rules.DefaultMethodRules.OverridingMixinMethodsOnlyPossibleWhenMixinDerivedFromMixinBase)"
                    + Environment.NewLine
                    ));
        }
        public void Serialization()
        {
            var log  = new DefaultValidationLog();
            var rule = new DelegateValidationRule <TargetClassDefinition> (DummyRule);

            var definition = DefinitionObjectMother.CreateTargetClassDefinition(typeof(object));

            log.ValidationStartsFor(definition);
            log.Succeed(rule);
            log.ValidationEndsFor(definition);

            var exception = new ValidationException(log.GetData());

            var deserializedException = Serializer.SerializeAndDeserialize(exception);

            Assert.That(deserializedException.Message, Is.EqualTo(exception.Message));
            Assert.That(deserializedException.ValidationLogData, Is.Not.Null);
        }
        public void Ctor_CopiesPropertiesFromValidationLogData()
        {
            var log        = new DefaultValidationLog();
            var rule       = new DelegateValidationRule <TargetClassDefinition> (DummyRule);
            var definition = DefinitionObjectMother.CreateTargetClassDefinition(typeof(object));

            log.ValidationStartsFor(definition);
            log.Succeed(rule);
            log.ValidationEndsFor(definition);

            var expected = log.GetData();
            var actual   = expected.MakeSerializable();

            Assert.That(actual.NumberOfFailures, Is.EqualTo(expected.GetNumberOfFailures()));
            Assert.That(actual.NumberOfRulesExecuted, Is.EqualTo(expected.GetNumberOfRulesExecuted()));
            Assert.That(actual.NumberOfSuccesses, Is.EqualTo(expected.GetNumberOfSuccesses()));
            Assert.That(actual.NumberOfUnexpectedExceptions, Is.EqualTo(expected.GetNumberOfUnexpectedExceptions()));
            Assert.That(actual.NumberOfWarnings, Is.EqualTo(expected.GetNumberOfWarnings()));
        }
        public void Serializable()
        {
            var log        = new DefaultValidationLog();
            var rule       = new DelegateValidationRule <TargetClassDefinition> (DummyRule);
            var definition = DefinitionObjectMother.CreateTargetClassDefinition(typeof(object));

            log.ValidationStartsFor(definition);
            log.Succeed(rule);
            log.ValidationEndsFor(definition);

            var serializableValidationLogData = log.GetData().MakeSerializable();

            var deserialized = Serializer.SerializeAndDeserialize(serializableValidationLogData);

            Assert.That(deserialized.NumberOfFailures, Is.EqualTo(serializableValidationLogData.NumberOfFailures));
            Assert.That(deserialized.NumberOfRulesExecuted, Is.EqualTo(serializableValidationLogData.NumberOfRulesExecuted));
            Assert.That(deserialized.NumberOfSuccesses, Is.EqualTo(serializableValidationLogData.NumberOfSuccesses));
            Assert.That(deserialized.NumberOfUnexpectedExceptions, Is.EqualTo(serializableValidationLogData.NumberOfUnexpectedExceptions));
            Assert.That(deserialized.NumberOfWarnings, Is.EqualTo(serializableValidationLogData.NumberOfWarnings));
        }
        public void Merge()
        {
            IValidationLog sourceLog = new DefaultValidationLog();
            var            exception = new Exception();

            TargetClassDefinition bt1 = DefinitionObjectMother.GetActiveTargetClassDefinition(typeof(BaseType1));
            TargetClassDefinition bt2 = DefinitionObjectMother.GetActiveTargetClassDefinition_Force(typeof(BaseType2));
            TargetClassDefinition bt3 = DefinitionObjectMother.GetActiveTargetClassDefinition(typeof(BaseType3));
            TargetClassDefinition bt4 = DefinitionObjectMother.GetActiveTargetClassDefinition_Force(typeof(BaseType4));

            sourceLog.ValidationStartsFor(bt1);
            sourceLog.Succeed(new DelegateValidationRule <TargetClassDefinition> (delegate { }, "Success", "Success"));
            sourceLog.Warn(new DelegateValidationRule <TargetClassDefinition> (delegate { }, "Warn", "Warn"));
            sourceLog.Fail(new DelegateValidationRule <TargetClassDefinition> (delegate { }, "Fail", "Fail"));
            sourceLog.UnexpectedException(new DelegateValidationRule <TargetClassDefinition> (delegate { }, "Except", "Except"), exception);
            sourceLog.ValidationEndsFor(bt1);

            sourceLog.ValidationStartsFor(bt4);
            sourceLog.Succeed(new DelegateValidationRule <TargetClassDefinition> (delegate { }, "Success2", "Success2"));
            sourceLog.Warn(new DelegateValidationRule <TargetClassDefinition> (delegate { }, "Warn2", "Warn2"));
            sourceLog.Fail(new DelegateValidationRule <TargetClassDefinition> (delegate { }, "Fail2", "Fail2"));
            sourceLog.UnexpectedException(new DelegateValidationRule <TargetClassDefinition> (delegate { }, "Except2", "Except2"), exception);
            sourceLog.ValidationEndsFor(bt4);

            IValidationLog resultLog = new DefaultValidationLog();

            resultLog.ValidationStartsFor(bt2);
            resultLog.Succeed(new DelegateValidationRule <TargetClassDefinition> (delegate { }, "0", "0"));
            resultLog.Warn(new DelegateValidationRule <TargetClassDefinition> (delegate { }, "1", "1"));
            resultLog.Fail(new DelegateValidationRule <TargetClassDefinition> (delegate { }, "2", "2"));
            resultLog.UnexpectedException(new DelegateValidationRule <TargetClassDefinition> (delegate { }, "3", "3"), exception);
            resultLog.ValidationEndsFor(bt2);

            resultLog.ValidationStartsFor(bt1);
            resultLog.Succeed(new DelegateValidationRule <TargetClassDefinition> (delegate { }, "4", "4"));
            resultLog.Warn(new DelegateValidationRule <TargetClassDefinition> (delegate { }, "5", "5"));
            resultLog.Fail(new DelegateValidationRule <TargetClassDefinition> (delegate { }, "6", "6"));
            resultLog.UnexpectedException(new DelegateValidationRule <TargetClassDefinition> (delegate { }, "7", "7"), exception);
            resultLog.ValidationEndsFor(bt1);

            resultLog.ValidationStartsFor(bt3);
            resultLog.Succeed(new DelegateValidationRule <TargetClassDefinition> (delegate { }, "8", "8"));
            resultLog.Warn(new DelegateValidationRule <TargetClassDefinition> (delegate { }, "9", "9"));
            resultLog.Fail(new DelegateValidationRule <TargetClassDefinition> (delegate { }, "10", "10"));
            resultLog.UnexpectedException(new DelegateValidationRule <TargetClassDefinition> (delegate { }, "11", "11"), exception);
            resultLog.ValidationEndsFor(bt3);

            var logData = resultLog.GetData();

            logData.Add(sourceLog.GetData());
            Assert.That(logData.GetNumberOfSuccesses(), Is.EqualTo(5));
            Assert.That(logData.GetNumberOfWarnings(), Is.EqualTo(5));
            Assert.That(logData.GetNumberOfFailures(), Is.EqualTo(5));
            Assert.That(logData.GetNumberOfUnexpectedExceptions(), Is.EqualTo(5));

            var results = new List <ValidationResult> (logData.GetResults());

            Assert.That(results.Count, Is.EqualTo(4));

            Assert.That(results[0].ValidatedDefinition, Is.EqualTo(bt2));
            Assert.That(results[0].Successes.Count, Is.EqualTo(1));
            Assert.That(results[0].Failures.Count, Is.EqualTo(1));
            Assert.That(results[0].Warnings.Count, Is.EqualTo(1));
            Assert.That(results[0].Exceptions.Count, Is.EqualTo(1));

            Assert.That(results[1].ValidatedDefinition, Is.EqualTo(bt1));

            Assert.That(results[1].Successes.Count, Is.EqualTo(2));
            Assert.That(results[1].Successes[0].Message, Is.EqualTo("4"));
            Assert.That(results[1].Successes[1].Message, Is.EqualTo("Success"));

            Assert.That(results[1].Warnings.Count, Is.EqualTo(2));
            Assert.That(results[1].Warnings[0].Message, Is.EqualTo("5"));
            Assert.That(results[1].Warnings[1].Message, Is.EqualTo("Warn"));

            Assert.That(results[1].Failures.Count, Is.EqualTo(2));
            Assert.That(results[1].Failures[0].Message, Is.EqualTo("6"));
            Assert.That(results[1].Failures[1].Message, Is.EqualTo("Fail"));

            Assert.That(results[1].Exceptions.Count, Is.EqualTo(2));
            Assert.That(results[1].Exceptions[0].Exception, Is.EqualTo(exception));
            Assert.That(results[1].Exceptions[1].Exception, Is.EqualTo(exception));

            Assert.That(results[2].ValidatedDefinition, Is.EqualTo(bt3));
            Assert.That(results[2].Successes.Count, Is.EqualTo(1));
            Assert.That(results[2].Failures.Count, Is.EqualTo(1));
            Assert.That(results[2].Warnings.Count, Is.EqualTo(1));
            Assert.That(results[2].Exceptions.Count, Is.EqualTo(1));

            Assert.That(results[3].ValidatedDefinition, Is.EqualTo(bt4));

            Assert.That(results[3].Successes.Count, Is.EqualTo(1));
            Assert.That(results[3].Successes[0].Message, Is.EqualTo("Success2"));

            Assert.That(results[3].Warnings.Count, Is.EqualTo(1));
            Assert.That(results[3].Warnings[0].Message, Is.EqualTo("Warn2"));

            Assert.That(results[3].Failures.Count, Is.EqualTo(1));
            Assert.That(results[3].Failures[0].Message, Is.EqualTo("Fail2"));

            Assert.That(results[3].Exceptions.Count, Is.EqualTo(1));
            Assert.That(results[3].Exceptions[0].Exception, Is.EqualTo(exception));
        }