public async Task ProcessAsync(AssemblyData assemblyData, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); _logger.Info($"Processing started for assembly: {assemblyData.AssemblyName} in folder: {assemblyData.Path}"); var stopWatch = new Stopwatch(); stopWatch.Start(); var templateContext = _templateContextProvider.Create(assemblyData); foreach (var templateSet in _templateSetProvider.GetTemplatesByName(assemblyData.TemplateSet)) { templateContext.With(templateSet); _logger.Debug($"Generating code for template {templateSet.Name}"); var generator = _generatorProvider.GetGeneratorByDriverName(templateSet.Driver); if (generator != null) { var templateStopwatch = new Stopwatch(); templateStopwatch.Start(); var model = generator.Generate(templateContext); _logger.Debug($"Generating template data for template {templateSet.Name}"); string outputPath = Path.Combine(assemblyData.Path, templateSet.OutputPath); var codeGenWriterData = new TemplateWriterData { TemplateSet = templateSet, Model = model, OutputPath = outputPath }; _logger.Debug($"Writing template data for path {outputPath}"); await _templateWriter.WriteAsync(codeGenWriterData, cancellationToken) .ConfigureAwait(false); templateStopwatch.Stop(); _logger.Debug( $"Code generation for template {templateSet.Name} completed in {templateStopwatch.Elapsed.ToString()}."); } else { _logger.Debug($"TemplateSet model not found for {templateSet.Name}, skipping."); } } stopWatch.Stop(); _logger.Info($"Processing complete for assembly: {assemblyData.AssemblyName} in {stopWatch.Elapsed.ToString()}."); }
protected override void Arrange() { _assemblyData = new AssemblyData { AssemblyName = "testAssembly", Path = "testFolder", TemplateSet = "standard" }; _templateSet = new TemplateSet { Name = "Entities.mustache", Driver = "Entities", OutputPath = "Models\\Entities\\Entities.generated.cs" }; var templates = new List <TemplateSet> { _templateSet }; var model = new object(); _templateContext = new TemplateContext(); _templateWriter = Stub <ITemplateWriter>(); _codeRepositoryProvider = Stub <ICodeRepositoryProvider>(); _templateSetProvider = Stub <ITemplateSetProvider>(); _templateContextProvider = Stub <ITemplateContextProvider>(); _generator = Stub <IGenerator>(); _generatorProvider = Stub <IGeneratorProvider>(); A.CallTo(() => _codeRepositoryProvider.GetResolvedCodeRepositoryByName(A <string> ._, A <string> ._)) .Returns("testRepo\\testFolder"); A.CallTo(() => _templateSetProvider.GetTemplatesByName(A <string> ._)) .Returns(templates); A.CallTo(() => _templateContextProvider.Create(A <AssemblyData> ._)) .Returns(_templateContext); A.CallTo(() => _generator.Generate(A <TemplateContext> ._)) .Returns(model); A.CallTo(() => _generatorProvider.GetGeneratorByDriverName(A <string> ._)) .Returns(_generator); _templateProcessor = new TemplateProcessor( _generatorProvider, _templateWriter, _templateSetProvider, _templateContextProvider); }
public void Should_call_templateContext_create_once() => A.CallTo(() => _templateContextProvider.Create(_assemblyData)) .MustHaveHappenedOnceExactly();