/// <summary> /// Called when the <c>TestProjectBuilder</c> is about to create the code generator. /// </summary> /// <param name="codeNamespace">The code namespace.</param> /// <param name="configuration">The configuration.</param> /// <param name="buildSystem">The build system.</param> /// <returns>An with the parameters initialized code generator.</returns> /// <remarks>Override this method to instantiate others than the standard generators. /// <example>The default implementation is: /// <code><![CDATA[ /// protected virtual ICodeGenerator OnCreateCodeGenerator(CodeNamespace codeNamespace, CodeGeneratorParameters configuration, IBuildSystem buildSystem) /// { /// var codeGenerator = this.createGeneratorCallback(buildSystem, configuration, codeNamespace); /// return codeGenerator; /// } /// ]]></code></example> /// </remarks> protected virtual ICodeGenerator OnCreateCodeGenerator( CodeNamespace codeNamespace, ICodeGeneratorParameters configuration, IBuildSystem buildSystem) { var codeGenerator = this.createGeneratorCallback(buildSystem, configuration, codeNamespace); return(codeGenerator); }
/// <summary> /// Called when the <c>TestProjectBuilder</c> is about to create the code generator. /// </summary> /// <param name="codeNamespace">The code namespace.</param> /// <param name="configuration">The configuration.</param> /// <param name="buildSystem">The build system.</param> /// <returns> /// An with the parameters initialized code generator. /// </returns> protected override ICodeGenerator OnCreateCodeGenerator( CodeNamespace codeNamespace, ICodeGeneratorParameters configuration, IBuildSystem buildSystem) { var codeGenerator = this.createGeneratorCallback(buildSystem, this.properties, configuration, codeNamespace); return(codeGenerator); }
/// <summary> /// Initializes a new instance of the <see cref="CSharpMbUnitRhinoMocksCodeGenerator"/> class /// based the given <see cref="CodeNamespace"/> which will output to the given directory. /// </summary> /// <param name="buildSystem">The build system.</param> /// <param name="codeNamespace">The code namespace.</param> /// <param name="testBuilders">The test builder repository.</param> /// <param name="configuration">The configuration of the generator.</param> /// <exception cref="System.ArgumentNullException"><paramref name="codeNamespace"/> or /// <cref name="ICodeGeneratorParameters.OutputDirectory"/> is <c>null</c>.</exception> /// <exception cref="System.ArgumentException"><cref name="ICodeGeneratorParameters.OutputDirectory"/> is an /// empty string.</exception> /// <exception cref="ApplicationException"><cref name="ICodeGeneratorParameters.OutputDirectory"/> /// cannot be found.</exception> public CSharpMbUnitRhinoMocksCodeGenerator( IBuildSystem buildSystem, CodeNamespace codeNamespace, IMemberBuilderFactory testBuilders, ICodeGeneratorParameters configuration) : base(buildSystem, codeNamespace, testBuilders, configuration) { }
/// <summary> /// Initializes a new instance of the <see cref="CSharpMbUnitCodeGenerator"/> class /// based the given <see cref="CodeNamespace"/> which will output to the given directory. /// </summary> /// <param name="buildSystem">The build system.</param> /// <param name="codeNamespace">The code namespace.</param> /// <param name="testBuilders">The test builder repository.</param> /// <param name="configuration">The configuration of the generator.</param> /// <exception cref="System.ArgumentNullException"><paramref name="codeNamespace"/> or /// <cref name="ICodeGeneratorParameters.OutputDirectory"/> is <c>null</c>.</exception> /// <exception cref="System.ArgumentException"><cref name="ICodeGeneratorParameters.OutputDirectory"/> is an /// empty string.</exception> /// <exception cref="System.ApplicationException"><cref name="ICodeGeneratorParameters.OutputDirectory"/> /// cannot be found.</exception> public CSharpMbUnitCodeGenerator( IBuildSystem buildSystem, CodeNamespace codeNamespace, IMemberBuilderFactory testBuilders, ICodeGeneratorParameters configuration) : base(buildSystem, codeNamespace, testBuilders, configuration) { }
/* * private CodeNamespace CreateNamespace(TestNode treeNode) * { * return null; * } */ /// <summary> /// Writes the test file. /// </summary> /// <param name="calculatedOutputDirectory">The calculated output directory.</param> /// <param name="codeNamespace">The code namespace.</param> private void WriteTestFile( string calculatedOutputDirectory, CodeNamespace codeNamespace) { // Now write the test file // NStubCore nStub = // new NStubCore(codeNamespace, outputDirectory, // new CSharpCodeGenerator(codeNamespace, outputDirectory)); // NStubCore nStub = // new NStubCore(codeNamespace, outputDirectory, // new CSharpMbUnitCodeGenerator(codeNamespace, outputDirectory)); // var nStub = // new NStubCore( // codeNamespace, // outputDirectory, // new CSharpMbUnitRhinoMocksCodeGenerator(codeNamespace, outputDirectory)); // var testBuilders = new TestBuilderFactory(new PropertyBuilder(), new EventBuilder(), new MethodBuilder()); ICodeGeneratorParameters configuration = null; if (this.CustomGeneratorParameters == null) { configuration = new CodeGeneratorParameters(calculatedOutputDirectory); } else { configuration = new CodeGeneratorParameters(this.CustomGeneratorParameters, calculatedOutputDirectory); } // var testBuilders = new TestBuilderFactory(); // var codeGenerator = (ICodeGenerator)Activator.CreateInstance(generatorType, new object[] // { // sbs, codeNamespace, testBuilders, configuration // }); var buildSystem = this.sbs; var codeGenerator = this.OnCreateCodeGenerator(codeNamespace, configuration, buildSystem); // codeNamespace.Dump(3); var nstub = new NStubCore(buildSystem, codeNamespace, calculatedOutputDirectory, codeGenerator); nstub.GenerateCode(); // Add all of our classes to the project foreach (CodeTypeDeclaration codeType in nstub.CodeNamespace.Types) { string fileName = codeType.Name; fileName = fileName.Remove(0, fileName.LastIndexOf(".") + 1); fileName += ".cs"; this.csharpProjectGenerator.ClassFiles.Add(fileName); Thread.Sleep(1); if (this.logger != null) { this.logger("Writing '" + fileName + "'"); } } }
/// <summary> /// Initializes a new instance of the <see cref="CSharpCodeGenerator"/> class /// based the given <see cref="CodeNamespace"/> which will output to the given directory. /// </summary> /// <param name="buildSystem">The build system.</param> /// <param name="codeNamespace">The code namespace.</param> /// <param name="testBuilders">The test builders.</param> /// <param name="configuration">The configuration.</param> /// <exception cref="System.ArgumentNullException"><paramref name="codeNamespace"/> or /// outputDirectory is <see langword="null"/>.</exception> /// <exception cref="System.ArgumentException">outputDirectory is an /// empty string.</exception> /// <exception cref="System.IO.DirectoryNotFoundException">outputDirectory /// cannot be found.</exception> /// <exception cref="ApplicationException"><c>ApplicationException</c> Directory Cannot Be Found.</exception> public CSharpCodeGenerator( IBuildSystem buildSystem, CodeNamespace codeNamespace, IMemberBuilderFactory testBuilders, ICodeGeneratorParameters configuration) { Guard.NotNull(() => buildSystem, buildSystem); this.buildSystem = buildSystem; Guard.NotNull(() => configuration, configuration); // this.configuration = configuration; string outputDirectory = configuration.OutputDirectory; // Null arguments will not be accepted if (codeNamespace == null) { throw new ArgumentNullException( "codeNamespace", Exceptions.ParameterCannotBeNull); } if (outputDirectory == null) { throw new ArgumentNullException( "outputDirectory", Exceptions.ParameterCannotBeNull); } // Ensure that the output directory is not empty if (outputDirectory.Length == 0) { throw new ArgumentException( Exceptions.StringCannotBeEmpty, "outputDirectory"); } // Ensure that the output directory is valid if (!this.buildSystem.DirectoryExists(outputDirectory)) { throw new ApplicationException(Exceptions.DirectoryCannotBeFound); } this.codeNamespace = codeNamespace; this.OutputDirectory = outputDirectory; }
/// <summary> /// Initializes a new instance of the <see cref="CSharpCodeGenerator"/> class /// based the given <see cref="CodeNamespace"/> which will output to the given directory. /// </summary> /// <param name="buildSystem">The build system.</param> /// <param name="codeNamespace">The code namespace.</param> /// <param name="testBuilders">The test builders.</param> /// <param name="configuration">The configuration.</param> /// <exception cref="System.ArgumentNullException"><paramref name="codeNamespace"/> or /// outputDirectory is <see langword="null"/>.</exception> /// <exception cref="System.ArgumentException">outputDirectory is an /// empty string.</exception> /// <exception cref="System.IO.DirectoryNotFoundException">outputDirectory /// cannot be found.</exception> /// <exception cref="ApplicationException"><c>ApplicationException</c> Directory Cannot Be Found.</exception> public CSharpCodeGenerator( IBuildSystem buildSystem, CodeNamespace codeNamespace, IMemberBuilderFactory testBuilders, ICodeGeneratorParameters configuration) { Guard.NotNull(() => buildSystem, buildSystem); this.buildSystem = buildSystem; Guard.NotNull(() => configuration, configuration); // this.configuration = configuration; string outputDirectory = configuration.OutputDirectory; // Null arguments will not be accepted if (codeNamespace == null) { throw new ArgumentNullException( "codeNamespace", Exceptions.ParameterCannotBeNull); } if (outputDirectory == null) { throw new ArgumentNullException( "outputDirectory", Exceptions.ParameterCannotBeNull); } // Ensure that the output directory is not empty if (outputDirectory.Length == 0) { throw new ArgumentException( Exceptions.StringCannotBeEmpty, "outputDirectory"); } // Ensure that the output directory is valid if (!this.buildSystem.DirectoryExists(outputDirectory)) { throw new ApplicationException(Exceptions.DirectoryCannotBeFound); } this.codeNamespace = codeNamespace; this.OutputDirectory = outputDirectory; }
/// <summary> /// Called when the <c>TestProjectBuilder</c> is about to create the code generator. /// </summary> /// <param name="codeNamespace">The code namespace.</param> /// <param name="configuration">The configuration.</param> /// <param name="buildSystem">The build system.</param> /// <returns>An with the parameters initialized code generator.</returns> /// <remarks>Override this method to instantiate others than the standard generators. /// <example>The default implementation is: /// <code><![CDATA[ /// protected virtual ICodeGenerator OnCreateCodeGenerator(CodeNamespace codeNamespace, CodeGeneratorParameters configuration, IBuildSystem buildSystem) /// { /// var codeGenerator = this.createGeneratorCallback(buildSystem, configuration, codeNamespace); /// return codeGenerator; /// } /// ]]></code></example> /// </remarks> protected virtual ICodeGenerator OnCreateCodeGenerator( CodeNamespace codeNamespace, ICodeGeneratorParameters configuration, IBuildSystem buildSystem) { var codeGenerator = this.createGeneratorCallback(buildSystem, configuration, codeNamespace); return codeGenerator; }
private static ICodeGenerator OldOnCreateCodeGenerator( IBuildSystem buildSystem, ICodeGeneratorParameters configuration, CodeNamespace codeNamespace) { return(null); }