public void IFMethods_CallsOtherMethod_ShouldBeConnected() { var method1 = MockMethod.Method("Method1", MockBlock.GeneralMethodBody().Object); var method2Body = MockBlock.GetMethodBodyThatInvokedInternalMethods(new[] { method1.Name }); var method2 = MockMethod.Method("Method2", method2Body); var lcomGraph = new Lcom4Graph(new[] { method1, method2 }); var actualConnectedComponentsCount = lcomGraph.CountConnectedComponents(); var expectedConnectedComponentCounts = 1; Assert.AreEqual(expectedConnectedComponentCounts, actualConnectedComponentsCount); }
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); }