protected override void BuildActSourceCode(MethodSourceCodeGenerationRequest request) { AppendLine("//TODO: Act"); Append("//"); Append("TODO: call "); AppendLine(request.Method.Name); }
public void BuildMethodName_GenericArgumentMethodWithOverloadGiven_ShouldProduceEquivalentName() { EnumerableArgumentMethodSignature enumerableArgumentMethod = new TestAssembly.OverloadedMethods("").OverloadedMethod; var enumerableArgumentMethodRequest = new MethodSourceCodeGenerationRequest(enumerableArgumentMethod.Method, false, enumerableArgumentMethod.Method.GetParameters().First(), true); var methodName = testee.BuildMethodName(enumerableArgumentMethodRequest); methodName.Should().Be("OverloadedMethod_IEnumerableString_StringsNullValueGiven_ShouldThrowArgumentNullException"); }
public void TestInitialize() { FooBarSignature instanceMethod = new TestAssembly.PublicClass().FooBar; expressionBuilder = MockRepository.GenerateMock<IExpressionBuilder>(); instanceMethodRequest = new MethodSourceCodeGenerationRequest(instanceMethod.Method, false, instanceMethod.Method.GetParameters().First()); var testMethodValueProvider = MockRepository.GenerateMock<ITestMethodValueProvider>(); testee = new NullArgumentMethodTestMethodSourceCodeGenerator(expressionBuilder, testMethodValueProvider); }
//protected override Expression BuildCallExpression(MethodSourceCodeGenerationRequest request) //{ // var method = request.Method; // var callExpression = base.BuildCallExpression(request); // var lambda = Expression.Lambda(typeof(Action<>).MakeGenericType(method.ReflectedType), callExpression, paramExpression); // var invokeGenericMethod = ((MethodCallExpression)invokingActionMethod.Body).Method.GetGenericMethodDefinition().MakeGenericMethod(method.ReflectedType); // var invokeExpr = Expression.Call(null, invokeGenericMethod, InstanceExpression, lambda); //} protected override void BuildActSourceCode(MethodSourceCodeGenerationRequest request) { var method = request.Method; var arguments = expressionBuilder.CreateArgumentExpressions(method.GetParameters(), request.NullArgumentNeedsExplicitCast, request.ParameterDestinedAsNull); MethodCallExpression invokeExpr = expressionBuilder.BuildFluentAssertionMethodInvokingExpression(method, InstanceExpression, arguments); Append(expressionBuilder.ExpressionToString(invokeExpr)); AppendLine(";"); }
public void TestInitialize() { FooBarSignature instanceMethod = new TestAssembly.PublicClass().FooBar; expressionBuilder = MockRepository.GenerateMock <IExpressionBuilder>(); instanceMethodRequest = new MethodSourceCodeGenerationRequest(instanceMethod.Method, false, instanceMethod.Method.GetParameters().First()); var testMethodValueProvider = MockRepository.GenerateMock <ITestMethodValueProvider>(); testee = new NullArgumentMethodTestMethodSourceCodeGenerator(expressionBuilder, testMethodValueProvider); }
public IEnumerable <TestMethod> GenerateTestMethods(TypeContext typeContext) { foreach (var method in GetMethods(typeContext)) { var request = new MethodSourceCodeGenerationRequest(method, true, method.GetParameters().First()); var methodName = sourceCodeGenerator.BuildMethodName(request); var sourceCode = sourceCodeGenerator.BuildSourceCode(request); yield return(new TestMethod(method, methodName, sourceCode)); } }
public void BuildSourceCode_StaticMethodGiven_ShouldCallMethodWithoutInstance() { const string expressionString = "expr1"; StubExpressionBuilder(expressionString); FooBarSignature staticMethod = PublicClass.StaticMethod; var staticMethodRequest = new MethodSourceCodeGenerationRequest(staticMethod.Method, false, staticMethod.Method.GetParameters().First()); var sourceCode = testee.BuildSourceCode(staticMethodRequest); sourceCode.Should().Be($@"{expressionString};{Environment.NewLine}"); }
public void BuildSourceCode2() { const string expr = "expr1"; var sampleInstance = new TestAssembly.OverloadedMethods(""); TestMethod methodDelegate = sampleInstance.OverloadedMethod; var expressionBuilder = MockRepository.GenerateMock <IFluentAssertionExpressionBuilder>(); expressionBuilder.Stub(m => m.ExpressionToString(null)) .IgnoreArguments() .Return(expr); var testee = new FluentAssertionNullArgumentMethodTestMethodSourceCodeGenerator(expressionBuilder, MockRepository.GenerateMock <ITestMethodValueProvider>()); var request = new MethodSourceCodeGenerationRequest(methodDelegate.Method); var result = testee.BuildSourceCode(request); result.Should().Be($@"var {expr};{Environment.NewLine}{expr};{Environment.NewLine}"); }
protected override IEnumerable <TestMethod> GenerateTestMethodsFor(MethodMetadata metadata) { var tests = new List <TestMethod>(); var parameters = metadata.Method.GetParameters(); foreach (var nullParameter in parameters.Where(x => ParameterSatisfied(x))) { var request = new MethodSourceCodeGenerationRequest(metadata.Method, metadata.NullArgumentNeedsExplicitCast, nullParameter, metadata.ConflictingMethodParameterName); var sourceCode = sourceCodeGenerator.BuildSourceCode(request); string methodName = sourceCodeGenerator.BuildMethodName(request); var testMethod = new TestMethod(metadata.Method, methodName, sourceCode, typeof(ArgumentNullException)); tests.Add(testMethod); } return(tests); }
public override string BuildMethodName(MethodSourceCodeGenerationRequest request) { return(request.Method.Name + Guid.NewGuid().ToString().Substring(0, 8)); }
public override string BuildMethodName(MethodSourceCodeGenerationRequest request) { return(request.Method.Name); }
protected override void BuildAssertSourceCode(MethodSourceCodeGenerationRequest request) { AppendLine("//TODO: Assert"); }