예제 #1
0
            public void generates_valid_stream()
            {
                var source = new ResourceFileSourceFactory("Tempest.UnitTests.Sourcing.EmbeddedResource.txt",
                                                           typeof(TemplateFileSourceTests).GetTypeInfo().Assembly);
                var context     = new SourcingContext();
                var result      = source.Generate(context);
                var resultValue = result.First().Provider.Provide().ReadAsString();

                Assert.Equal("FOOBAR", resultValue);
            }
예제 #2
0
            public void generates_valid_stream_from_path()
            {
                var source       = new ResourcePathFileSourceFactory("Tempest.UnitTests.Sourcing", GetType().GetAssembly());
                var context      = new SourcingContext();
                var result       = source.Generate(context);
                var resultValue1 = result.First().Provider.Provide().ReadAsString();
                var resultValue2 = result.ElementAt(1).Provider.Provide().ReadAsString();

                Assert.Equal("FOOBAR", resultValue1);
                Assert.Equal("BARFOO", resultValue2);
            }
예제 #3
0
            public void generates_valid_stream()
            {
                var source  = BuildTemplateSourceLocation();
                var context = new SourcingContext()
                {
                    TemplateRoot = new DirectoryInfo(Directory.GetCurrentDirectory())
                };

                var result      = source.Generate(context);
                var resultValue = result.First().Provider.Provide().ReadAsString();

                Assert.Equal("Foobar", resultValue);
            }
예제 #4
0
        public void Scaffold()
        {
            var configuration = _configurationResolver.Resolve();

            var sourcingContext = new SourcingContext()
            {
                TargetRoot   = BuildTargetPath(_generatorContext, configuration),
                TemplateRoot = _generatorContext.TemplateDirectory
            };

            var operations = _operationBuilder.Build(configuration, sourcingContext);

            // Maybe ask user if this is OK?
            _operationExecutor.Execute(operations);
        }
예제 #5
0
        protected virtual IEnumerable <Operation> BuildOperations(OperationStep step, ScaffoldOperationConfiguration configuration, SourcingContext context)
        {
            var source          = step.GetSource(configuration);
            var sourcingResults = source.Generate(context);

            foreach (var result in sourcingResults)
            {
                var destinationFilename = result.FileName;
                var destinationFilepath = result.FilePath;
                var streamTransformers  = new List <IStreamTransformer>();

                foreach (var transformer in configuration.GlobalTransformers.Union(step.GetTransformers()))
                {
                    destinationFilepath = transformer.TransformFilename(destinationFilepath);
                    destinationFilename = transformer.TransformFilename(destinationFilename);
                    streamTransformers.Add(transformer.CreateStreamTransformer());
                }

                var actualTransformer = new CompoundStreamTransformer(streamTransformers);

                var persistenceContext = new PersistenceContext()
                {
                    FilePath        = destinationFilepath,
                    Filename        = destinationFilename,
                    TargetDirectory = context.TargetRoot
                };

                foreach (var emitter in step.GetEmitters())
                {
                    foreach (var actualEmitter in  emitter.CreatePersisters(persistenceContext))
                    {
                        yield return(new Operation(result.Provider, actualTransformer, actualEmitter));
                    }
                }
            }
        }
예제 #6
0
 public IEnumerable <Operation> Build(ScaffoldOperationConfiguration configuration, SourcingContext sourcingContext)
 {
     foreach (var step in configuration.Steps)
     {
         foreach (var operation in BuildOperations(step, configuration, sourcingContext))
         {
             yield return(operation);
         }
     }
 }