示例#1
0
        public void should_load_default_templates_from_template_directory(
            ITemplateLoader templateLoader, DirectoryInfo root,
            ICraneContext context, IFileManager fileManager,
            IEnumerable <ITemplate> result)
        {
            "Given I have a project root folder"
            ._(() =>
            {
                context = ServiceLocator.Resolve <ICraneContext>(); fileManager = ServiceLocator.Resolve <IFileManager>();
                context.ProjectRootDirectory = new DirectoryInfo(fileManager.GetTemporaryDirectory());
            });

            "And a template loader"
            ._(() => templateLoader = ServiceLocator.Resolve <ITemplateLoader>());

            "When I call load"
            ._(() => result = templateLoader.Load());

            "It should load the default source template"
            ._(
                () =>
                result.Any(
                    item =>
                    item.Name.Equals(CraneConfiguration.DefaultSourceProviderName) &&
                    item.TemplateType == TemplateType.Source));

            "It should load the default build template"
            ._(
                () =>
                result.Any(
                    item =>
                    item.Name.Equals(CraneConfiguration.DefaultBuildProviderName) &&
                    item.TemplateType == TemplateType.Build));
        }
示例#2
0
 public TemplateInvoker(IFileManager fileManager,
                        ITemplateParser templateParser,
                        IFileAndDirectoryTokenParser fileAndDirectoryTokenParser,
                        ICraneContext context,
                        ITokenDictionaryFactory tokenDictionaryFactory)
 {
     _fileManager    = fileManager;
     _templateParser = templateParser;
     _fileAndDirectoryTokenParser = fileAndDirectoryTokenParser;
     _context = context;
     _tokenDictionaryFactory = tokenDictionaryFactory;
 }
示例#3
0
 public static void Configure(
     ICraneContext context,
     IConfiguration configuration        = null,
     DirectoryInfo projectRootDirectory  = null,
     DirectoryInfo craneInstallDirectory = null,
     DirectoryInfo buildDirectory        = null,
     DirectoryInfo sourceDirectory       = null)
 {
     A.CallTo(() => context.ProjectRootDirectory).Returns(projectRootDirectory ?? new DirectoryInfo(Path.Combine(@"C:\", StringExtensions.RandomString(8))));
     A.CallTo(() => context.BuildDirectory).Returns(buildDirectory ?? new DirectoryInfo(Path.Combine(context.ProjectRootDirectory.FullName, CraneConfiguration.DefaultBuildFolderName)));
     A.CallTo(() => context.CraneInstallDirectory).Returns(craneInstallDirectory ?? new DirectoryInfo(CraneContext.DefaultInstallationDirectory));
     A.CallTo(() => context.SourceDirectory).Returns(sourceDirectory ?? new DirectoryInfo(Path.Combine(context.ProjectRootDirectory.FullName, CraneConfiguration.DefaultSourceFolderName)));
 }
 public ITokenDictionary Create(ICraneContext craneContext, IProjectContext projectContext)
 {
     return(new TokenDictionary(new Dictionary <string, Func <string> >
     {
         { "%context.ProjectName%", () => projectContext.ProjectName },
         { "%context.SolutionPath%", () => projectContext.SolutionPath },
         { "%context.BuildDirectory.FullName%", () => craneContext.BuildDirectory.FullName },
         { "%context.CraneInstallDirectory.FullName%", () => craneContext.CraneInstallDirectory.FullName },
         { "%context.ProjectRootDirectory.FullName%", () => craneContext.ProjectRootDirectory.FullName },
         { "%context.Configuration.BuildFolderName%", () => craneContext.Configuration.BuildFolderName },
         { "%context.Configuration.BuildTemplateProviderName%", () => craneContext.Configuration.BuildTemplateProviderName },
         { "%DateTime.Now.Year%", () => DateTime.Now.Year.ToString() },
         { "%System.Environment.UserName%", () => System.Environment.UserName },
         {
             "%nuget%", () => ".nuget" // cpack doesn't include folder name .nuGet so we just tokenize it
         },
     }));
 }
示例#5
0
 public TemplateLoader(IFileManager fileManager, ICraneContext context, ITemplateFactory templateFactory)
 {
     _fileManager     = fileManager;
     _context         = context;
     _templateFactory = templateFactory;
 }
示例#6
0
        public void creating_a_new_psake_build(DirectoryInfo root, ITemplate template, ICraneContext context, ITemplateInvoker templateInvoker)
        {
            "Given I have a project root folder"
            ._(() =>
            {
                context         = ServiceLocator.Resolve <ICraneContext>();
                var fileManager = ServiceLocator.Resolve <IFileManager>();
                templateInvoker = ServiceLocator.Resolve <ITemplateInvoker>();
                context.ProjectRootDirectory = new DirectoryInfo(fileManager.GetTemporaryDirectory());
            });

            "And I have a psake template builder"
            ._(() => template = ServiceLocator.Resolve <ITemplateResolver>().Resolve(TemplateType.Build));

            "When I call create on the template with service stack as the project name and solution name"
            ._(() => templateInvoker.InvokeTemplate(template, new ProjectContext {
                ProjectName = "ServiceStack", SolutionPath = "../ServiceStack.sln"
            }));

            "It place a build.ps1 in the root project directory"
            ._(() => File.Exists(Path.Combine(context.ProjectRootDirectory.FullName, "build.ps1")).Should().BeTrue("build.ps1 should be in root directory"));

            "It should replace the solution file name in the build script with the project name"
            ._(() => File.ReadAllText(Path.Combine(context.BuildDirectory.FullName, "default.ps1")).Should().Contain("../ServiceStack.sln"))
            .Teardown(() => Directory.Delete(context.ProjectRootDirectory.FullName, recursive: true));
        }
示例#7
0
        public void creating_a_visual_studio_setup_using_the_template(DirectoryInfo root, ITemplate template, ICraneContext context, ITemplateInvoker templateInvoker)
        {
            "Given I have a project root folder"
            ._(() =>
            {
                context = ServiceLocator.Resolve <ICraneContext>(); var fileManager = ServiceLocator.Resolve <IFileManager>();
                context.ProjectRootDirectory = new DirectoryInfo(fileManager.GetTemporaryDirectory());
                templateInvoker = ServiceLocator.Resolve <ITemplateInvoker>();
            });

            "And I have a psake template builder"
            ._(() => template = ServiceLocator.Resolve <TemplateResolver>().Resolve(TemplateType.Source));

            "When I call create on the template with ServiceStack as the project name and solution name"
            ._(() => templateInvoker.InvokeTemplate(template, new ProjectContext {
                ProjectName = "ServiceStack", SolutionPath = "ServiceStack"
            }));

            "It should rename the class library folder name with the current project name"
            ._(() => Directory.Exists(Path.Combine(context.SourceDirectory.FullName, "ServiceStack")).Should().BeTrue());

            "It should rename the test class library folder name with the current project name"
            ._(() => Directory.Exists(Path.Combine(context.SourceDirectory.FullName, "ServiceStack.UnitTests")).Should().BeTrue());

            "It should rename the solution file with the current project name"
            ._(() => File.Exists(Path.Combine(context.SourceDirectory.FullName, "ServiceStack.sln")).Should().BeTrue());

            "It should replace the tokens in the solution file"
            ._(() => File.ReadAllText(Path.Combine(context.SourceDirectory.FullName, "ServiceStack.sln"))
               .Should().NotContain("%GUID-1%").And.NotContain("%GUID-2%"));

            "It should replace the tokens in the project file"
            ._(() => File.ReadAllText(Path.Combine(context.SourceDirectory.FullName, "ServiceStack", string.Format("{0}.csproj", "ServiceStack")))
               .Should().NotContain("%GUID-1%"));

            "It should replace the tokens in the project unit test file"
            ._(() => File.ReadAllText(Path.Combine(context.SourceDirectory.FullName, string.Format("{0}.UnitTests", "ServiceStack"), string.Format("{0}.UnitTests.csproj", "ServiceStack")))
               .Should().NotContain("%GUID-1%"));

            "It should rename the nuGet specification file with the current project name"
            ._(() => File.Exists(Path.Combine(context.SourceDirectory.FullName, "ServiceStack", string.Format("{0}.nuspec", "ServiceStack"))).Should().BeTrue());

            "It should replace the tokens in the nuGet specification file"
            ._(() => File.ReadAllText(Path.Combine(context.SourceDirectory.FullName, "ServiceStack", string.Format("{0}.nuspec", "ServiceStack")))
               .Should().NotContain("%username%")
               .And.NotContain("%context.ProjectName%")
               .And.NotContain("%DateTime.Now.Year%"));

            "It should create a .gitignore file in the project root"
            ._(() =>
               File.Exists(Path.Combine(context.ProjectRootDirectory.FullName, ".gitignore"))
               .Should().Be(true)
               );

            "It should create a .gitattributes file in the project root"
            ._(() =>
               File.Exists(Path.Combine(context.ProjectRootDirectory.FullName, ".gitattributes"))
               .Should().Be(true)
               )
            .Teardown(() => Directory.Delete(context.ProjectRootDirectory.FullName, recursive: true));
        }
示例#8
0
        public void creating_a_new_psake_build(DirectoryInfo root, PsakeBuildTemplate template, ICraneContext context)
        {            
            "Given I have a project root folder"
                ._(() =>
                {
                    context = ioc.Resolve<ICraneContext>();
                    context.ProjectRootDirectory = new DirectoryInfo(FileUtilites.GetTemporaryDirectory());
                });

            "And I have a psake template builder"
                ._(() => template = ioc.Resolve<PsakeBuildTemplate>());

            "And I have been given a project name via init"
                ._(() => context.ProjectName = "ServiceStack");

            "When I call create on the template"
                ._(() => template.Create());

            "It should replace the solution file name in the build script with the project name"
                ._(() => File.ReadAllText(template.BuildScript.FullName).Should().Contain("ServiceStack.sln"))
                .Teardown(() => Directory.Delete(context.ProjectRootDirectory.FullName, recursive: true));            
        }