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); }
private async Task <RestResponse> SendInternalAsync(string method, string endpoint, HttpRequestMessage message, CancellationToken token) { foreach (var header in _headers) { message.Headers.Add(header.Key, header.Value); } message.Method = new HttpMethod(method); message.RequestUri = new Uri(_baseUri, endpoint); MockMethod mock = _methods.FirstOrDefault(m => m.EndpointAttribute.Endpoint == endpoint && m.EndpointAttribute.Method == method) ?? throw new InvalidOperationException(); HttpResponseMessage response = await mock.Method(message); return(new RestResponse(response.StatusCode, response.Headers.ToDictionary(h => h.Key, h => h.Value.FirstOrDefault()), response.Content, message.Method, message.RequestUri)); }
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); }
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); }
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); }
private IMethodBase GetMethodWithModifiedClassFieldsInBlock(string methodName, string[] fieldsIdentifiers) { var methodBody = MockBlock.GetMethodBodyThatModifiedClassFields(fieldsIdentifiers); return(MockMethod.Method(methodName, methodBody)); }