public void Method_ModifiedStaticFields_HasSideEffect()
        {
            const string classStaticField = "staticFieldOfClass";
            var          body             = MockBlock.GetMethodBodyThatModifiedStaticFields(classStaticField);
            var          method           = MockMethod.DefaultMethodWithBody(body);

            var sideEffectChecker = new ModifiedStateSideEffect();

            sideEffectChecker.CheckForSideEffects(method);
            var hasSideEffect = sideEffectChecker.HasSideEffects();

            Assert.IsTrue(hasSideEffect);
        }
        public void Method_ModifiedParameters_HasSideEffect()
        {
            const string methodParameter = "param1";
            var          body            = MockBlock.GetMethodBodyThatModifiedMethodParameters(methodParameter);
            var          method          = MockMethod.DefaultMethodWithBody(body);

            var sideEffectChecker = new ModifiedStateSideEffect();

            sideEffectChecker.CheckForSideEffects(method);
            var hasSideEffect = sideEffectChecker.HasSideEffects();

            Assert.IsTrue(hasSideEffect);
        }
        public void MethodWith_SmallBlockSize_HasNotAnalyzerError()
        {
            var methodSizeRule = QualityRules.MethodSize;
            var maximumLines   = new Metric().MaximumSizeOfMethod;

            var body               = MockBlock.GeneralMethodBodyWithBlockSize(maximumLines - 1);
            var method             = MockMethod.DefaultMethodWithBody(body.Object);
            var methodSizeAnalyzer = new MethodSize(TestBootStrapped.GetInstanceOfIMetric());

            methodSizeAnalyzer.Analyze(method);
            var analyzeResult = methodSizeAnalyzer.GetResult();

            var hasAcceptableSize = !analyzeResult.Any(a => a.ViolatedRule.Equals(methodSizeRule));

            Assert.IsTrue(hasAcceptableSize);
        }
        public void Method_ModifiedStaticFields_HasAnalyzerError()
        {
            var sideEffectRule = QualityRules.SideEffect;

            var classStaticField = "staticFieldOfClass";
            var body             = MockBlock.GetMethodBodyThatModifiedStaticFields(classStaticField);
            var method           = MockMethod.DefaultMethodWithBody(body);

            var sideEffectAnalyzer = new MethodSideEffects(TestBootStrapped.GetInstanceOfISideEffect());

            sideEffectAnalyzer.Analyze(method);
            var analyzeResult = sideEffectAnalyzer.GetResult();

            var hasSideEffect = analyzeResult.Any(a => a.ViolatedRule.Equals(sideEffectRule));

            Assert.IsTrue(hasSideEffect);
        }
        public void Method_JustModifiedParentClassFields_HasNotAnalyzerError()
        {
            var sideEffectRule = QualityRules.SideEffect;

            var methodParameter = "param1";
            var body            = MockBlock.GetMethodBodyThatJustModifiedClassInstanceFields(methodParameter);
            var method          = MockMethod.DefaultMethodWithBody(body);

            var sideEffectAnalyzer = new MethodSideEffects(TestBootStrapped.GetInstanceOfISideEffect());

            sideEffectAnalyzer.Analyze(method);
            var analyzeResult = sideEffectAnalyzer.GetResult();

            var hasSideEffect = analyzeResult.Any(a => a.ViolatedRule.Equals(sideEffectRule));

            Assert.IsFalse(hasSideEffect);
        }
Beispiel #6
0
        public void EmbeddedStatement_WithBigBlock_HasAnalyzerError()
        {
            var blockSizeRule = QualityRules.EmbeddedStatementsBlockSize;
            var maximumSizeOfEmbeddedBlock = new Metric().MaximumSizeOfEmbeddedBlock;

            var embeddedStatement = MockIEmbeddedStatement.GeneralIEmbeddedStatement(maximumSizeOfEmbeddedBlock + 1);
            var body   = MockBlock.GetMethodBodyWithEmbeddedStatement(new[] { embeddedStatement });
            var method = MockMethod.DefaultMethodWithBody(body);

            var nestedStructureRAnalyzer = new EmbeddedStatementAnalyzer(TestBootStrapped.GetInstanceOfIMetric());

            nestedStructureRAnalyzer.Analyze(method);
            var analyzeResult = nestedStructureRAnalyzer.GetResult();

            var hasError = analyzeResult.Any(a => a.ViolatedRule.Equals(blockSizeRule));

            Assert.IsTrue(hasError);
        }
Beispiel #7
0
        public void DeepNested_EmbeddedStatement_HasAnalyzerError()
        {
            var nestedStructureRules    = QualityRules.NestedStructure;
            var maximumNestedStructures = new Metric().MaximumLevelOfNestedStructure;

            var nestedStructure =
                MockIEmbeddedStatement.MultiLevelNestedIEmbeddedStatements(maximumNestedStructures + 1);
            var body   = MockBlock.GetMethodBodyWithEmbeddedStatement(new[] { nestedStructure });
            var method = MockMethod.DefaultMethodWithBody(body);

            var nestedStructureRAnalyzer = new EmbeddedStatementAnalyzer(TestBootStrapped.GetInstanceOfIMetric());

            nestedStructureRAnalyzer.Analyze(method);
            var analyzeResult = nestedStructureRAnalyzer.GetResult();

            var hasError = analyzeResult.Any(a => a.ViolatedRule.Equals(nestedStructureRules));

            Assert.IsTrue(hasError);
        }