public void should_update_all_code_assembly_infos(CraneTestContext craneTestContext, PowerShellApiRunner apiRunner, RunResult commandResult, ICraneApi craneApi, string projectDir) { "Given I have my own private copy of the crane console" ._(() => craneTestContext = ServiceLocator.Resolve <CraneTestContext>()); "And I have my powershell api runner" ._(() => apiRunner = new PowerShellApiRunner(craneTestContext, TimeSpan.FromSeconds(15))); "And I have a crane api" ._(() => craneApi = ServiceLocator.Resolve <ICraneApi>()); "And I have initialized a project called ServiceStack" ._(() => { var craneRunner = new CraneRunner(); craneRunner.Command(craneTestContext.BuildOutputDirectory, "crane init ServiceStack"); projectDir = Path.Combine(craneTestContext.BuildOutputDirectory, "ServiceStack"); }); "When I update the solution assembly infos" ._(() => commandResult = apiRunner.Run(@"$context = Get-CraneSolutionContext -Path '{0}'; Update-CraneAllProjectsAssemblyInfos -SolutionContext $context -Version '4.5.6.7'", projectDir)); "Then there should be no error" ._(() => commandResult.Should().BeErrorFree()); "And the assembly info file should be patched for each code project" ._(() => craneApi.GetSolutionContext(projectDir).Solution.Projects.Where(p => !p.TestProject) .All(p => p.AssemblyInfo.Version.ToString() == "4.5.6.7") .Should() .BeTrue() ).Teardown(() => craneTestContext.TearDown()); }
public void Api_returns_null_when_source_control_is_not_being_used(CraneRunner craneRunner, RunResult result, CraneTestContext craneTestContext, ISolutionContext solutionContext, ISourceControlInformation sourceControlInformation, ICraneApi craneApi) { "Given I have my own private copy of the crane console" ._(() => craneTestContext = ServiceLocator.Resolve <CraneTestContext>()); "And I have a run context" ._(() => craneRunner = new CraneRunner()); "And I have run crane init ServiceStack" ._(() => result = craneRunner.Command(craneTestContext.BuildOutputDirectory, "crane init ServiceStack")); "And I have the solution context using the api" ._(() => { craneApi = ServiceLocator.Resolve <ICraneApi>(); solutionContext = craneApi.GetSolutionContext(Path.Combine(craneTestContext.BuildOutputDirectory, "ServiceStack")); }); "When I get the source information using the api" ._(() => sourceControlInformation = craneApi.GetSourceControlInformation(solutionContext)); "It should return null as the source control information" ._(() => sourceControlInformation.Should().BeNull()) .Teardown(() => craneTestContext.TearDown()); }
public void patch_solution_assembly_info(ICraneApi craneApi, SolutionBuilderContext context, ISolutionContext solutionContext, Project project, AssemblyInfo updatedInfo, string updatedRawInfo) { "Given I have a crane api" ._(() => craneApi = ServiceLocator.Resolve <CraneApi>()); "And I have a solution builder context" ._(() => context = ServiceLocator.Resolve <SolutionBuilderContext>()); "And I have a solution with two projects" ._(() => context.CreateBuilder() .WithSolution(item => item.Path = Path.Combine(context.RootDirectory, "Sally.sln")) .WithProject(item => item.Name = "FrodoFx") .WithFile <AssemblyInfo>(item => { item.Title = "Sally"; item.Description = "Next generation web server"; item.Version = new Version(0, 0, 0, 1); item.FileVersion = new Version(0, 0, 0, 2); item.InformationalVersion = "RELEASE"; }) .WithProject(item => item.Name = "BobFx") .WithFile <AssemblyInfo>(item => { item.Title = "Bob"; item.Description = "Old school"; item.Version = new Version(0, 0, 0, 1); item.FileVersion = new Version(0, 0, 0, 2); item.InformationalVersion = "RELEASE"; }).Build()); "And I have got the solution context" ._(() => solutionContext = craneApi.GetSolutionContext(context.RootDirectory)); "When I path the solution assembly info for all projects" ._(() => craneApi.PatchSolutionAssemblyInfo(solutionContext, "1.2.3.4")); "Then file version should be set to 1.2.3.4 in all assembly info files" ._(() => { solutionContext = craneApi.GetSolutionContext(context.RootDirectory); solutionContext.Solution.Projects.All(p => p.AssemblyInfo.FileVersion.ToString() == "1.2.3.4") .Should() .BeTrue(); }); "Then version should be set to 1.2.3.4 in all assembly info files" ._(() => solutionContext.Solution.Projects.All(p => p.AssemblyInfo.Version.ToString() == "1.2.3.4") .Should() .BeTrue()); "Then file informational version should be set to 1.2.3.4" ._(() => solutionContext.Solution.Projects.All(p => p.AssemblyInfo.InformationalVersion.ToString() == "1.2.3.4") .Should() .BeTrue() ).Teardown(() => context.TearDown()); }
public void Get_context_with_root_folder_path_returns_all_projects(ICraneApi craneApi, SolutionBuilderContext context, ISolutionContext result, Project project) { "Given I have a crane api" ._(() => craneApi = ServiceLocator.Resolve <CraneApi>()); "And I have a solution builder context" ._(() => context = ServiceLocator.Resolve <SolutionBuilderContext>()); "And I have a solution with two projects" ._(() => context.CreateBuilder() .WithSolution(item => item.Path = Path.Combine(context.RootDirectory, "Sally.sln")) .WithProject(item => item.Name = "FrodoFx") .WithProject(item => item.Name = "FrodoFx.UnitTests") .Build()); "When I get the solution context via the api" ._(() => { result = craneApi.GetSolutionContext(context.RootDirectory); }); "And it should return a model representation of the solution on disk" ._(() => result.Solution.Should().NotBeNull()); "And it should have the correct solution name" ._(() => result.Solution.Name.Should().Be("Sally")); "And it should have the correct solution path" ._(() => result.Solution.Path.Should().Be(Path.Combine(context.RootDirectory, "Sally.sln"))); "And it should reference its parent context" ._(() => result.Solution.SolutionContext.Should().NotBeNull()); "And it should have two projects" ._(() => result.Solution.Projects.Count().Should().Be(2)); "And the projects should have the correct name" ._(() => { result.Solution.Projects.Any(item => item.Name.Equals("FrodoFx")).Should().BeTrue(); result.Solution.Projects.Any(item => item.Name.Equals("FrodoFx.UnitTests")).Should().BeTrue(); }); "And the projects should have the correct path" ._(() => { result.Solution.Projects.Any(item => item.Path.Equals(Path.Combine(context.RootDirectory, "FrodoFx", "FrodoFx.csproj"))).Should().BeTrue(); result.Solution.Projects.Any(item => item.Path.Equals(Path.Combine(context.RootDirectory, "FrodoFx.UnitTests", "FrodoFx.UnitTests.csproj"))).Should().BeTrue(); }); "And the projects should reference their solution" ._(() => result.Solution.Projects.All(item => item.Solution != null).Should().BeTrue()) .Teardown(() => context.TearDown()); }
public void can_create_a_nuget_package( CraneRunner craneRunner, RunResult result, CraneTestContext craneTestContext, ISolutionContext solutionContext, string projectDir, ICraneApi craneApi, string buildOutputFolder, string nugetOutputFolder, IEnumerable <RunResult> runResults) { "Given I have my own private copy of the crane console" ._(() => craneTestContext = ServiceLocator.Resolve <CraneTestContext>()); "And I have a run context" ._(() => craneRunner = new CraneRunner()); "And I have run crane init ServiceStack" ._(() => result = craneRunner.Command(craneTestContext.BuildOutputDirectory, "crane init ServiceStack")); "And I have build the project" ._(() => { result = new BuildScriptRunner().Run(Path.Combine(craneTestContext.BuildOutputDirectory, "ServiceStack")); result.Should().BeBuiltSuccessfulyWithAllTestsPassing().And.BeErrorFree();; }); "And I have the solution context using the api" ._(() => { projectDir = Path.Combine(craneTestContext.BuildOutputDirectory, "ServiceStack"); craneApi = ServiceLocator.Resolve <ICraneApi>(); solutionContext = craneApi.GetSolutionContext(projectDir); buildOutputFolder = Path.Combine(solutionContext.Path, "build-output"); }); "When I create nuGet packages using the api" ._( () => { nugetOutputFolder = Path.Combine(buildOutputFolder, "nuGet"); runResults = craneApi.NugetPack(solutionContext, buildOutputFolder, nugetOutputFolder, "0.0.0.0"); runResults.ForEach(item => _log.Debug(result)); }); "It should create nuGet packages for all the projects in the built solution" ._(() => File.Exists(Path.Combine(nugetOutputFolder, "ServiceStack.0.0.0.0.nupkg")).Should().BeTrue("could not find nuget file {0}, it should have been created.", Path.Combine(nugetOutputFolder, "ServiceStack.0.0.0.0.nupkg"))) .Teardown(() => craneTestContext.TearDown()); }
public void invoking_command_packages_nuget_spec_file_correctly( CraneRunner craneRunner, RunResult buildResult, RunResult commandResult, CraneTestContext craneTestContext, string projectDir, ICraneApi craneApi, PowerShellApiRunner apiRunner) { "Given I have my own private copy of the crane console" ._(() => craneTestContext = ServiceLocator.Resolve <CraneTestContext>()); "And I have a run context" ._(() => craneRunner = new CraneRunner()); "And I have run crane init ServiceStack" ._(() => buildResult = craneRunner.Command(craneTestContext.BuildOutputDirectory, "crane init ServiceStack")); "And I have build the project" ._(() => { buildResult = new BuildScriptRunner().Run(Path.Combine(craneTestContext.BuildOutputDirectory, "ServiceStack")); buildResult.Should().BeBuiltSuccessfulyWithAllTestsPassing().And.BeErrorFree(); projectDir = Path.Combine(craneTestContext.BuildOutputDirectory, "ServiceStack"); }); "And I have my powershell api runner" ._(() => apiRunner = new PowerShellApiRunner(craneTestContext, TimeSpan.FromSeconds(15))); "When I call invoke all nuget pack" ._(() => commandResult = apiRunner.Run( @"$context = Get-CraneSolutionContext -Path '{0}'; " + "Invoke-CraneNugetPackAllProjects -SolutionContext $context -BuildOutputPath '{1}' -NugetOutputPath '{2}' -Version {3}" + "| % {{ $_.StandardOutput }}", projectDir, Path.Combine(projectDir, "build-output"), Path.Combine(projectDir, "build-output", "nuGet"), "0.0.0.0")); "Then there should be no error" ._(() => commandResult.Should().BeErrorFree()); "And the nuget package should have been created" ._(() => File.Exists(Path.Combine(projectDir, "build-output", "nuGet", "ServiceStack.0.0.0.0.nupkg")).Should().BeTrue()) .Teardown(() => craneTestContext.TearDown()); }
public void Api_can_read_the_latest_git_commit_from_a_solution_in_git(CraneRunner craneRunner, RunResult result, CraneTestContext craneTestContext, ISolutionContext solutionContext, string projectDir, Git git, ISourceControlInformation sourceControlInformation, ICraneApi craneApi) { "Given I have my own private copy of the crane console" ._(() => craneTestContext = ServiceLocator.Resolve <CraneTestContext>()); "And I have a run context" ._(() => craneRunner = new CraneRunner()); "And I have run crane init ServiceStack" ._(() => result = craneRunner.Command(craneTestContext.BuildOutputDirectory, "crane init ServiceStack")); "And I initialize that as a git repository" ._(() => { projectDir = Path.Combine(craneTestContext.BuildOutputDirectory, "ServiceStack"); git = ServiceLocator.Resolve <Git>(); git.Run("init", projectDir).ErrorOutput.Should().BeEmpty(); git.Run("config user.email [email protected]", projectDir).ErrorOutput.Should().BeEmpty(); }); "And I have a previous commit" ._(() => { git.Run("add -A", projectDir).ErrorOutput.Should().BeEmpty(); git.Run("config user.email [email protected]", projectDir).ErrorOutput.Should().BeEmpty(); git.Run("commit -m \"First commit of ServiceStack\"", projectDir).ErrorOutput.Should().BeEmpty(); }); "And I have the solution context using the api" ._(() => { craneApi = ServiceLocator.Resolve <ICraneApi>(); solutionContext = craneApi.GetSolutionContext(projectDir); }); "When I get the source information using the api" ._(() => sourceControlInformation = craneApi.GetSourceControlInformation(solutionContext)); "It should set the provider name to git" ._(() => sourceControlInformation.ProviderName.Should().Be("git")); "It should return the latest commit message as 'First commit of ServiceStack'" ._(() => sourceControlInformation.LastCommitMessage.Should().Contain("First commit of ServiceStack")) .Teardown(() => craneTestContext.TearDown()); }
public void can_publish_build_to_nuget(CraneRunner craneRunner, RunResult result, CraneTestContext craneTestContext, ISolutionContext solutionContext, string projectDir, ICraneApi craneApi, NuGetServerContext nuGetServer) { "Given I have my own private copy of the crane console" ._(() => craneTestContext = ServiceLocator.Resolve <CraneTestContext>()); "And I have a nuGet server running" ._(() => { nuGetServer = new NuGetServerContext(craneTestContext); nuGetServer.PackageCount.Should().BeGreaterThan(-1); }); "And I have a run context" ._(() => craneRunner = new CraneRunner()); "And I have run crane init ServiceStack" ._(() => result = craneRunner.Command(craneTestContext.BuildOutputDirectory, "crane init ServiceStack")); "And I have build the project" ._(() => { result = new BuildScriptRunner().Run(Path.Combine(craneTestContext.BuildOutputDirectory, "ServiceStack")); result.Should().BeBuiltSuccessfulyWithAllTestsPassing().And.BeErrorFree();; }); "And I have the solution context using the api" ._(() => { projectDir = Path.Combine(craneTestContext.BuildOutputDirectory, "ServiceStack"); craneApi = ServiceLocator.Resolve <ICraneApi>(); solutionContext = craneApi.GetSolutionContext(projectDir); }); "And I have packaged the nuget spec" ._(() => { var buildOutputPath = Path.Combine(solutionContext.Path, "build-output"); craneApi.NugetPack(solutionContext, buildOutputPath, Path.Combine(buildOutputPath, "nuGet"), "0.0.0.0").First().Should().BeErrorFree(); }); "When I publish to nuGet using the api" ._( () => craneApi.NugetPublish(solutionContext, Path.Combine(solutionContext.Path, "build-output", "nuGet"), "0.0.0.0", nuGetServer.Source.ToString(), nuGetServer.ApiKey).First().Should().BeErrorFree()); "It should push the package to the nuGet server" ._(() => nuGetServer.PackageExists("ServiceStack", "0.0.0.0").Should().BeTrue()) .Teardown(() => { nuGetServer.TearDown(); craneTestContext.TearDown(); }); }
public void patch_solution_assembly_should_only_patch_non_test_projects(CraneRunner craneRunner, RunResult result, CraneTestContext craneTestContext, ISolutionContext solutionContext, ICraneApi craneApi, AssemblyInfo originalAssemblyInfo) { "Given I have my own private copy of the crane console" ._(() => craneTestContext = ServiceLocator.Resolve <CraneTestContext>()); "And I have a run context" ._(() => craneRunner = new CraneRunner()); "And I have an instance of the crane api" ._(() => craneApi = ServiceLocator.Resolve <ICraneApi>()); "And I have run crane init ServiceStack" ._(() => result = craneRunner.Command(craneTestContext.BuildOutputDirectory, "crane init ServiceStack")); "And I have got the solution context using the api" ._(() => { craneApi = ServiceLocator.Resolve <ICraneApi>(); solutionContext = craneApi.GetSolutionContext(Path.Combine(craneTestContext.BuildOutputDirectory, "ServiceStack")); originalAssemblyInfo = solutionContext.Solution.Projects.First(p => p.Name == "ServiceStack.UnitTests").AssemblyInfo; }); "And I have created one a solution with one code project called ServiceStack" ._(() => solutionContext.Solution.Projects.First(p => p.Name == "ServiceStack").TestProject.Should().BeFalse()); "And I have created one a solution with one test project called ServiceStack.UnitTests" ._(() => solutionContext.Solution.Projects.First(p => p.Name == "ServiceStack.UnitTests").TestProject.Should().BeTrue()); "When I path the solution assembly info for all projects" ._(() => { craneApi.PatchSolutionAssemblyInfo(solutionContext, "1.2.3.4"); solutionContext = craneApi.GetSolutionContext(Path.Combine(craneTestContext.BuildOutputDirectory, "ServiceStack")); }); "It should patch the code project's assemblyinfo version" ._(() => solutionContext.Solution.Projects.First(p => !p.TestProject) .AssemblyInfo.Version.ToString().Should().Be("1.2.3.4")); "It should patch the code project's assemblyinfo file version" ._(() => solutionContext.Solution.Projects.First(p => !p.TestProject) .AssemblyInfo.FileVersion.ToString().Should().Be("1.2.3.4")); "It should patch the code project's assemblyinfo file informational version" ._(() => solutionContext.Solution.Projects.First(p => !p.TestProject) .AssemblyInfo.InformationalVersion.Should().Be("1.2.3.4")); "It should not patch the test project's assemblyinfo version" ._(() => solutionContext.Solution.Projects.First(p => p.TestProject) .AssemblyInfo.Version.Should().Be(originalAssemblyInfo.Version)); "It should not patch the test project's assemblyinfo file version" ._(() => solutionContext.Solution.Projects.First(p => p.TestProject) .AssemblyInfo.FileVersion.Should().Be(originalAssemblyInfo.FileVersion)); "It should not patch the test project's file informational version" ._(() => solutionContext.Solution.Projects.First(p => p.TestProject) .AssemblyInfo.InformationalVersion.Should().Be(originalAssemblyInfo.InformationalVersion)) .Teardown(() => craneTestContext.TearDown()); }
public void patch_assembly_info(ICraneApi craneApi, SolutionBuilderContext context, ISolutionContext solutionContext, Project project, AssemblyInfo updatedInfo, string updatedRawInfo) { "Given I have a crane api" ._(() => craneApi = ServiceLocator.Resolve <CraneApi>()); "And I have a solution builder context" ._(() => context = ServiceLocator.Resolve <SolutionBuilderContext>()); "And I have a solution with a project and an assembly info file" ._(() => solutionContext = context.CreateBuilder() .WithSolution(item => item.Path = Path.Combine(context.RootDirectory, "Sally.sln")) .WithProject(item => item.Name = "FrodoFx") .WithFile <AssemblyInfo>(item => { item.Title = "Sally"; item.Description = "Next generation web server"; item.Version = new Version(0, 0, 0, 1); item.FileVersion = new Version(0, 0, 0, 2); item.InformationalVersion = "RELEASE"; }).Build()); "And I have an updated assembly info with different version, file number and informational attribute" ._(() => { updatedInfo = solutionContext.Solution.Projects.First().AssemblyInfo; updatedInfo.Version = new Version(0, 1, 0, 0); updatedInfo.FileVersion = new Version(0, 1, 20); updatedInfo.InformationalVersion = "DEBUG"; }); "When I patch the assemble info" ._(() => { craneApi.PatchAssemblyInfo(updatedInfo); solutionContext = craneApi.GetSolutionContext(solutionContext.Path); // reload to get updated model project = solutionContext.Solution.Projects.First(); updatedRawInfo = File.ReadAllText(project.AssemblyInfo.Path); }); "Then it should update the assembly file version" ._(() => { updatedRawInfo.Should().Contain("[assembly: AssemblyFileVersionAttribute(\"0.1.20\")]"); project.AssemblyInfo.FileVersion.Should().Be(new Version(0, 1, 20)); }); "Then it should update the informational version attribute" ._(() => { updatedRawInfo.Should().Contain("[assembly: AssemblyInformationalVersionAttribute(\"DEBUG\")]"); project.AssemblyInfo.InformationalVersion.Should().Be("DEBUG"); }); "Then it should update the assembly version" ._(() => { updatedRawInfo.Should().Contain("[assembly: AssemblyVersionAttribute(\"0.1.0.0\")]"); project.AssemblyInfo.Version.Should().Be(new Version(0, 1, 0, 0)); }); "Then it not update the assembly title as it was not changed" ._(() => { updatedRawInfo.Should().Contain("[assembly: AssemblyTitleAttribute(\"Sally\")]"); project.AssemblyInfo.Title.Should().Be("Sally"); }) .Teardown(() => context.TearDown()); }
public void patch_solution_assembly_info_when_project_in_git(ICraneApi craneApi, SolutionBuilderContext context, ISolutionContext solutionContext, Project project, AssemblyInfo updatedInfo, string updatedRawInfo, Git git) { "Given I have a crane api" ._(() => craneApi = ServiceLocator.Resolve <CraneApi>()); "And I have a solution builder context" ._(() => context = ServiceLocator.Resolve <SolutionBuilderContext>()); "And I have a solution with two projects" ._(() => context.CreateBuilder() .WithSolution(item => item.Path = Path.Combine(context.RootDirectory, "Sally.sln")) .WithProject(item => item.Name = "FrodoFx") .WithFile <AssemblyInfo>(item => { item.Title = "Sally"; item.Description = "Next generation web server"; item.Version = new Version(0, 0, 0, 1); item.FileVersion = new Version(0, 0, 0, 2); item.InformationalVersion = "RELEASE"; }) .WithProject(item => item.Name = "BobFx") .WithFile <AssemblyInfo>(item => { item.Title = "Bob"; item.Description = "Old school"; item.Version = new Version(0, 0, 0, 1); item.FileVersion = new Version(0, 0, 0, 2); item.InformationalVersion = "RELEASE"; }).Build()); "And I have got the solution context" ._(() => solutionContext = craneApi.GetSolutionContext(context.RootDirectory)); "And I initialize that as a git repository" ._(() => { git = ServiceLocator.Resolve <Git>(); git.Run("init", context.RootDirectory).ErrorOutput.Should().BeEmpty(); git.Run("config user.email [email protected]", context.RootDirectory).ErrorOutput.Should().BeEmpty(); }); "And I have a previous commit" ._(() => { git.Run("add -A", context.RootDirectory).ErrorOutput.Should().BeEmpty(); git.Run("config user.email [email protected]", context.RootDirectory).ErrorOutput.Should().BeEmpty(); git.Run("commit -m \"My brand new project\"", context.RootDirectory).ErrorOutput.Should().BeEmpty(); }); "When I path the solution assembly info for all projects" ._(() => craneApi.PatchSolutionAssemblyInfo(solutionContext, "1.2.3.4")); "Then file version should be set to 1.2.3.4 in all assembly info files" ._(() => { solutionContext = craneApi.GetSolutionContext(context.RootDirectory); solutionContext.Solution.Projects.All(p => p.AssemblyInfo.FileVersion.ToString() == "1.2.3.4") .Should() .BeTrue(); }); "Then version should be set to 1.2.3.4 in all assembly info files" ._(() => solutionContext.Solution.Projects.All(p => p.AssemblyInfo.Version.ToString() == "1.2.3.4") .Should() .BeTrue()); "Then file informational version should start with 1.2.3.4" ._(() => solutionContext.Solution.Projects.All(p => p.AssemblyInfo.InformationalVersion.ToString().StartsWith("1.2.3.4")) .Should() .BeTrue()) .Teardown(() => context.TearDown()); "Then file informational version should end with the commit message 'My brand new project'" ._(() => solutionContext.Solution.Projects.All(p => p.AssemblyInfo.InformationalVersion.ToString().EndsWith("My brand new project")) .Should() .BeTrue()) .Teardown(() => context.TearDown()); }