Exemplo n.º 1
0
        protected override void BuildActSourceCode(ConstructorSourceCodeGenerationRequest request)
        {
            var createInstanceExpr = CreateCtorExpression(request.Constructor, request.ParameterDestinedAsNull, request.NullArgumentNeedsExplicitCast);

            Append(expressionBuilder.ExpressionToString(createInstanceExpr));
            AppendLine(";");
        }
        /// <summary>
        /// Builds the method name.
        /// </summary>
        /// <param name="request">The object containing information about invoked constructor.</param>
        /// <returns>The generated string containing name of method.</returns>
        public override string BuildMethodName(ConstructorSourceCodeGenerationRequest request)
        {
            Check.NotNull(request, "request");

            string ctorName = BuildConstructorName(request);
            return "Constructor_" + ctorName + request.ParameterDestinedAsNull.Name.Capitalize() + "NullValueGiven_ShouldThrowArgumentNullException";
        }
 public void TestInitialize()
 {
     var type = typeof(ClassContructor);
     var ctor = type.GetConstructors().First();
     request = new ConstructorSourceCodeGenerationRequest(ctor, false, false, ctor.GetParameters().First());
     expressionBuilder = MockRepository.GenerateMock<IExpressionBuilder>();
     testee = new NullArgumentConstructorTestMethodSourceCodeGenerator(expressionBuilder);
 }
Exemplo n.º 4
0
        /// <summary>
        /// Builds the method name.
        /// </summary>
        /// <param name="request">The object containing information about invoked constructor.</param>
        /// <returns>The generated string containing name of method.</returns>
        public override string BuildMethodName(ConstructorSourceCodeGenerationRequest request)
        {
            Check.NotNull(request, "request");

            string ctorName = BuildConstructorName(request);

            return("Constructor_" + ctorName + request.ParameterDestinedAsNull.Name.Capitalize() + "NullValueGiven_ShouldThrowArgumentNullException");
        }
Exemplo n.º 5
0
        public void TestInitialize()
        {
            var type = typeof(ClassContructor);
            var ctor = type.GetConstructors().First();

            request           = new ConstructorSourceCodeGenerationRequest(ctor, false, false, ctor.GetParameters().First());
            expressionBuilder = MockRepository.GenerateMock <IExpressionBuilder>();
            testee            = new NullArgumentConstructorTestMethodSourceCodeGenerator(expressionBuilder);
        }
Exemplo n.º 6
0
        protected override void BuildActSourceCode(ConstructorSourceCodeGenerationRequest request)
        {
            var createInstanceExpr = CreateCtorExpression(request.Constructor, request.ParameterDestinedAsNull, request.NullArgumentNeedsExplicitCast);

            Append("((Action)(() => ");
            Append(ExpressionStringBuilder.ExpressionToString(createInstanceExpr));
            AppendLine("))");
            Append("\t");
            AppendFormat(@".ShouldThrowExactly<ArgumentNullException>().Where(x => x.ParamName == ""{0}"")", request.ParameterDestinedAsNull.Name);
            AppendLine(";");
        }
        protected override void BuildActSourceCode(ConstructorSourceCodeGenerationRequest request)
        {
            var createInstanceExpr = CreateCtorExpression(request.Constructor, request.ParameterDestinedAsNull, request.NullArgumentNeedsExplicitCast);

            Append("((Action)(() => ");
            Append(ExpressionStringBuilder.ExpressionToString(createInstanceExpr));
            AppendLine("))");
            Append("\t");
            AppendFormat(@".ShouldThrowExactly<ArgumentNullException>().Where(x => x.ParamName == ""{0}"")", request.ParameterDestinedAsNull.Name);
            AppendLine(";");
        }
        protected override IEnumerable<TestMethod> GenerateTestMethodsFor(ConstructorMetadata metadata)
        {
            if (IsDefaultConstructor(metadata.Constructor))
            {
                return Enumerable.Empty<TestMethod>();
            }

            var methods = new List<TestMethod>();
            foreach (var nullParameter in metadata.Constructor.GetParameters().Where(x => ParameterSatisfied(x)))
            {
                var request = new ConstructorSourceCodeGenerationRequest(metadata.Constructor,
                    metadata.NullArgumentNeedsExplicitCast,
                    metadata.HasMultipleConstructors,
                    nullParameter);
                var sourceCode = sourceCodeGenerator.BuildSourceCode(request);
                var method = new TestMethod(metadata.Constructor, sourceCodeGenerator.BuildMethodName(request), sourceCode, typeof(ArgumentNullException));
                methods.Add(method);
            }
            return methods;
        }
Exemplo n.º 9
0
        protected override IEnumerable <TestMethod> GenerateTestMethodsFor(ConstructorMetadata metadata)
        {
            if (IsDefaultConstructor(metadata.Constructor))
            {
                return(Enumerable.Empty <TestMethod>());
            }

            var methods = new List <TestMethod>();

            foreach (var nullParameter in metadata.Constructor.GetParameters().Where(x => ParameterSatisfied(x)))
            {
                var request = new ConstructorSourceCodeGenerationRequest(metadata.Constructor,
                                                                         metadata.NullArgumentNeedsExplicitCast,
                                                                         metadata.HasMultipleConstructors,
                                                                         nullParameter);
                var sourceCode = sourceCodeGenerator.BuildSourceCode(request);
                var method     = new TestMethod(metadata.Constructor, sourceCodeGenerator.BuildMethodName(request), sourceCode, typeof(ArgumentNullException));
                methods.Add(method);
            }
            return(methods);
        }
Exemplo n.º 10
0
 protected override void BuildAssertSourceCode(ConstructorSourceCodeGenerationRequest request)
 {
 }
 protected override void BuildAssertSourceCode(ConstructorSourceCodeGenerationRequest request)
 {
 }
 protected override void BuildActSourceCode(ConstructorSourceCodeGenerationRequest request)
 {
     var createInstanceExpr = CreateCtorExpression(request.Constructor, request.ParameterDestinedAsNull, request.NullArgumentNeedsExplicitCast);
     Append(expressionBuilder.ExpressionToString(createInstanceExpr));
     AppendLine(";");
 }