Esempio n. 1
0
        public void ClassName_WithPartsThat_ExistInDictionary_IsPronounceable()
        {
            var pronounceableRule = QualityRules.PronounceableName;
            var name = "CustomerValidation";

            var classDef          = MockClass.EmptyClass(name);
            var classNameAnalyzer = new ClassName(TestBootStrapped.GetInstanceOfNamingConvention());

            classNameAnalyzer.Analyze(classDef);
            var analyzeResult = classNameAnalyzer.GetResult();

            var isPronounceable = !analyzeResult.Any(a => a.ViolatedRule.Equals(pronounceableRule));

            Assert.IsTrue(isPronounceable);
        }
Esempio n. 2
0
        public void ClassName_StartsByNoun_HasHasNotPosError()
        {
            var partOfPeachRule = QualityRules.NounForClassName;
            var nounName        = "validation";

            var classDef          = MockClass.EmptyClass(nounName);
            var classNameAnalyzer = new ClassName(TestBootStrapped.GetInstanceOfNamingConvention());

            classNameAnalyzer.Analyze(classDef);
            var analyzeResult = classNameAnalyzer.GetResult();

            var hasRightPartOfPeach = !analyzeResult.Any(a => a.ViolatedRule.Equals(partOfPeachRule));

            Assert.IsTrue(hasRightPartOfPeach);
        }
Esempio n. 3
0
        public void MethodName_StartsByNoun_HasAnalyzerError()
        {
            var partOfPeachRule = QualityRules.VerbForMethodName;
            var nounName        = "validation";

            var method             = MockMethod.EmptyMethod(nounName);
            var methodNameAnalyzer = new MethodName(TestBootStrapped.GetInstanceOfNamingConvention());

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

            var hasRightPartOfPeach = !analyzeResult.Any(a => a.ViolatedRule.Equals(partOfPeachRule));

            Assert.IsFalse(hasRightPartOfPeach);
        }
Esempio n. 4
0
        public void MethodName_WithPartsThat_ExistInDictionary_IsPronounceable()
        {
            var pronounceableRule = QualityRules.PronounceableName;
            var name = "ValidateSomeFieldsWithSmallName";

            var method             = MockMethod.EmptyMethod(name);
            var methodNameAnalyzer = new MethodName(TestBootStrapped.GetInstanceOfNamingConvention());

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

            var isPronounceable = !analyzeResult.Any(a => a.ViolatedRule.Equals(pronounceableRule));

            Assert.IsTrue(isPronounceable);
        }
Esempio n. 5
0
        public void MethodName_StartsByGerunds_HasNotPosError()
        {
            var partOfSpeachRule = QualityRules.VerbForMethodName;
            var verbName         = "validate";

            var method             = MockMethod.EmptyMethod(verbName);
            var methodNameAnalyzer = new MethodName(TestBootStrapped.GetInstanceOfNamingConvention());

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

            var hasRightPartOfSpeech = !analyzeResult.Any(a => a.ViolatedRule.Equals(partOfSpeachRule));

            Assert.IsTrue(hasRightPartOfSpeech);
        }
Esempio n. 6
0
        public void MethodName_HasLenght_BiggerThanLimitSize_ISSearchable()
        {
            var pronounceableRule = QualityRules.PronounceableName;
            var name = "ValidatePKDMN";

            var method             = MockMethod.EmptyMethod(name);
            var methodNameAnalyzer = new MethodName(TestBootStrapped.GetInstanceOfNamingConvention());

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

            var isPronounceable = !analyzeResult.Any(a => a.ViolatedRule.Equals(pronounceableRule));

            Assert.IsFalse(isPronounceable);
        }
Esempio n. 7
0
        public void MethodName_HasAPartThat_NotExistInDictionary_IsNotPronounceable()
        {
            var pronounceableRule = QualityRules.PronounceableName;
            var name = "ValidateKMLS";

            var method             = MockMethod.EmptyMethod(name);
            var methodNameAnalyzer = new MethodName(TestBootStrapped.GetInstanceOfNamingConvention());

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

            var isPronounceable = !analyzeResult.Any(a => a.ViolatedRule.Equals(pronounceableRule));

            Assert.IsFalse(isPronounceable);
        }
Esempio n. 8
0
        public void ClassName_HasLength_BiggerThanLimitSize_IsSearchable()
        {
            var pronounceableRule = QualityRules.PronounceableName;
            var name = "ValidatePKDMN";

            var classDef          = MockClass.EmptyClass(name);
            var classNameAnalyzer = new ClassName(TestBootStrapped.GetInstanceOfNamingConvention());

            classNameAnalyzer.Analyze(classDef);
            var analyzeResult = classNameAnalyzer.GetResult();

            var isPronounceable = !analyzeResult.Any(a => a.ViolatedRule.Equals(pronounceableRule));

            Assert.IsFalse(isPronounceable);
        }
Esempio n. 9
0
        public void ClassName_HasLength_SmallerThanLimitSize_IsNotSearchable()
        {
            var searchableRule = QualityRules.SearchableName;
            var minimLength    = new Metric().MinimumLengthOfName;
            var name           = NameHelper.RandomString(minimLength - 1);

            var classDef          = MockClass.EmptyClass(name);
            var classNameAnalyzer = new ClassName(TestBootStrapped.GetInstanceOfNamingConvention());

            classNameAnalyzer.Analyze(classDef);
            var analyzeResult = classNameAnalyzer.GetResult();

            var isSearchable = !analyzeResult.Any(a => a.ViolatedRule.Equals(searchableRule));

            Assert.IsFalse(isSearchable);
        }
Esempio n. 10
0
        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);
        }
Esempio n. 11
0
        public void MethodName_HasLenght_SmallerThanLimitSize_ISNotSearchable()
        {
            var searchableRule = QualityRules.SearchableName;
            var minimLength    = new Metric().MinimumLengthOfName;
            var name           = NameHelper.RandomString(minimLength - 1);

            var method             = MockMethod.EmptyMethod(name);
            var methodNameAnalyzer = new MethodName(TestBootStrapped.GetInstanceOfNamingConvention());

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

            var isSearchable = !analyzeResult.Any(a => a.ViolatedRule.Equals(searchableRule));

            Assert.IsFalse(isSearchable);
        }
        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);
        }
        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);
        }
Esempio n. 14
0
        public void ClassWithMethods_NotUsingAnyOfClassFields_HasCohesionError()
        {
            var cohesionRule = QualityRules.ClassCohesion;

            var method1     = MockMethod.EmptyMethod("Method1");
            var method2     = MockMethod.EmptyMethod("Method2");
            var classFields = new[] { "field1", "field2" };

            var classDef         = MockClass.GetClass(classFields, new[] { method1, method2 });
            var cohesionAnalyzer = new ClassCohesion(TestBootStrapped.GetInstanceOfICohesion());

            cohesionAnalyzer.Analyze(classDef);
            var analyzeResult = cohesionAnalyzer.GetResult();

            var isCohesive = !analyzeResult.Any(a => a.ViolatedRule.Equals(cohesionRule));

            Assert.IsFalse(isCohesive);
        }
Esempio n. 15
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);
        }
        public void Method_JustModifiedLocalVariable_HasNotAnalyzerError()
        {
            var sideEffectRule = QualityRules.SideEffect;

            var localVariable = "variable1";
            var methodName    = "newMethod";
            var body          = MockBlock.GetMethodBodyThatJustModifiedLocalVariable(localVariable);
            var method        = MockMethod.Method(methodName, 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);
        }
Esempio n. 17
0
        public void MethodWith_LimitParameters_HasNotAnalyzerError()
        {
            var methodParameterRule = QualityRules.MethodParametersCount;
            var maximumParameters   = new Metric().MaximumNumberOfMethodParameters;

            var methodName       = "newMethod";
            var methodParameters = MockParameter.ParameterDeclarations(maximumParameters - 1);
            var method           = MockMethod.Method(methodName, methodParameters);

            var parameterAnalyzer = new ParametersCount(TestBootStrapped.GetInstanceOfIMetric());

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

            var hasAcceptableNumberOfParameters = !analyzeResult.Any(a => a.ViolatedRule.Equals(methodParameterRule));

            Assert.IsTrue(hasAcceptableNumberOfParameters);
        }
Esempio n. 18
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);
        }
Esempio n. 19
0
        public void ClassWithMethods_HaveNotUsedCommonClassFields_HasCohesionError()
        {
            var classFields = new[] { "field1", "field2" };

            var cohesionRule = QualityRules.ClassCohesion;

            var method1 = GetMethodWithAccessingToClassFieldsInBlock("Method1", new[] { classFields[0] });
            var method2 = GetMethodWithAccessingToClassFieldsInBlock("Method2", new[] { classFields[1] });

            var classDef         = MockClass.GetClass(classFields, new[] { method1, method2 });
            var cohesionAnalyzer = new ClassCohesion(TestBootStrapped.GetInstanceOfICohesion());

            cohesionAnalyzer.Analyze(classDef);
            var analyzeResult = cohesionAnalyzer.GetResult();

            var isCohesive = !analyzeResult.Any(a => a.ViolatedRule.Equals(cohesionRule));

            Assert.IsFalse(isCohesive);
        }
Esempio n. 20
0
        public void ClassWithMethods_HaveNotUsedCommonClassFields_ButConnectedByCallingMethods_HasNotCohesionError()
        {
            var classFields = new[] { "field1", "field2" };

            var cohesionRule = QualityRules.ClassCohesion;

            var method1     = MockMethod.Method("Method1", MockBlock.GeneralMethodBody().Object);
            var method2Body = MockBlock.GetMethodBodyThatInvokedInternalMethods(new[] { method1.Name });
            var method2     = MockMethod.Method("Method2", method2Body);


            var classDef         = MockClass.GetClass(classFields, new[] { method1, method2 });
            var cohesionAnalyzer = new ClassCohesion(TestBootStrapped.GetInstanceOfICohesion());

            cohesionAnalyzer.Analyze(classDef);
            var analyzeResult = cohesionAnalyzer.GetResult();

            var isCohesive = !analyzeResult.Any(a => a.ViolatedRule.Equals(cohesionRule));

            Assert.IsTrue(isCohesive);
        }