Esempio n. 1
0
        public void map_fubu_solution_to_crane_solution(IFubuSolutionMapper solutionMapper, SolutionBuilderContext context, ISolutionContext solutionContext, Solution result)
        {
            "Given I have a solution mapper"
            ._(() => solutionMapper = ServiceLocator.Resolve <IFubuSolutionMapper>());

            "And I have a solution builder context"
            ._(() => context = ServiceLocator.Resolve <SolutionBuilderContext>());

            "And I have a solution with two projects"
            ._(() => solutionContext = 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 map the fubu solution"
            ._(() => result = solutionMapper.Map(FubuCsProjFile.Solution.LoadFrom(solutionContext.Solution.Path)));

            "It should return a solution"
            ._(() => result.Should().NotBeNull());

            "It should map the solutions name"
            ._(() => result.Name.Should().Be("Sally"));

            "It should map the solutions path"
            ._(() => result.Path.Should().Be(Path.Combine(context.RootDirectory, "Sally.sln")));

            "It should map the solutions projects"
            ._(() => result.Projects.Count().Should().Be(2));

            "It should map the solutions projects that reference their parent solution"
            ._(() => result.Projects.All(item => item.Solution.Equals(result)).Should().BeTrue())
            .Teardown(() => context.TearDown());
        }
        public void map_fubu_project_to_crane_project(IFubuProjectMapper projectMapper, SolutionBuilderContext context, ISolutionContext solutionContext, Project result)
        {
            "Given I have a project mapper"
            ._(() => projectMapper = ServiceLocator.Resolve <IFubuProjectMapper>());

            "And I have a solution builder context"
            ._(() => context = ServiceLocator.Resolve <SolutionBuilderContext>());

            "And I have a solution with a project"
            ._(() => solutionContext = context.CreateBuilder()
                                       .WithSolution(item => item.Path             = Path.Combine(context.RootDirectory, "Sally.sln"))
                                       .WithProject(item => item.Name              = "FrodoFx")
                                       .WithFile <AssemblyInfo>(item => item.Title = "FrodoFx")
                                       .Build());

            "When I map the fubu project using the mapper"
            ._(() => result = projectMapper.Map(FubuCsProjFile.CsProjFile.LoadFrom(solutionContext.Solution.Projects.First().Path)));

            "It should return a project"
            ._(() => result.Should().NotBeNull());

            "It should map the projects name"
            ._(() => result.Name.Should().Be("FrodoFx"));

            "It should map the projects assemblyinfo"
            ._(() => result.AssemblyInfo.Title.Should().Be("FrodoFx", string.Format("File contents of {0} is {1}.", result.AssemblyInfo.Path, File.ReadAllText(result.AssemblyInfo.Path))));

            "It should map the projects path"
            ._(() => result.Path.Should().Be(Path.Combine(context.RootDirectory, "FrodoFx", "FrodoFx.csproj")))
            .Teardown(() => context.TearDown());
        }
        public void build_solution_with_projects_in_sibling_directories(SolutionBuilderContext context, ISolutionContext result, Project project)
        {
            "Given I have a solution builder context"
            ._(() => context = ServiceLocator.Resolve <SolutionBuilderContext>());

            "When I call build"
            ._(() => result = context.CreateBuilder()
                              .WithSolution(item => item.Path = Path.Combine(context.RootDirectory, "Solutions", "MySolution.sln"))
                              .WithProject(item =>
            {
                item.Name = "ServiceStack";
                item.Path = Path.Combine(context.RootDirectory, "ServiceStack", "ServiceStack.csproj");
            }).Build());

            "It should return the build project"
            ._(() =>
            {
                project = result.Solution.Projects.FirstOrDefault();
                project.Should().NotBeNull();
            });

            "And the project file should have the name set correctly"
            ._(() => project.Name.Should().Be("ServiceStack"));

            "And the project file should exist on disk"
            ._(() => File.Exists(Path.Combine(context.RootDirectory, "ServiceStack", "ServiceStack.csproj")).Should().BeTrue());

            "And the solution file should have the correct name"
            ._(() => result.Solution.Name.Should().Be("MySolution"));

            "And it should create a solution file on disk"
            ._(() => File.Exists(Path.Combine(context.RootDirectory, "Solutions", "MySolution.sln")).Should().BeTrue())
            .Teardown(() => context.TearDown());
        }
        public void build_project_with_name(SolutionBuilderContext context, ISolutionContext result, Project project)
        {
            "Given I have a solution builder context"
            ._(() => context = ServiceLocator.Resolve <SolutionBuilderContext>());

            "When I call build"
            ._(() => result = context.CreateBuilder()
                              .WithSolution(item => item.Path = Path.Combine(context.RootDirectory, "Sally.sln"))
                              .WithProject(item => item.Name  = "FrodoFx").Build());

            "It should return the build project"
            ._(() =>
            {
                project = result.Solution.Projects.FirstOrDefault();
                project.Should().NotBeNull();
            });

            "And the project should have a name"
            ._(() => project.Name.Should().Be("FrodoFx"));

            "And the project should have a path"
            ._(() => project.Path.Should().Be(Path.Combine(context.RootDirectory, "FrodoFx", "FrodoFx.csproj")));

            "And the project file should exist on disk"
            ._(() => File.Exists(project.Path).Should().BeTrue());

            "And the solution context path should be the root directory"
            ._(() => result.Path.Should().Be(context.RootDirectory));

            "And it should create a solution file on disk"
            ._(() => File.Exists(Path.Combine(context.RootDirectory, "Sally.sln")).Should().BeTrue())
            .Teardown(() => context.TearDown());
        }
        public void build_project_with_assembly_info_fubu_test(SolutionBuilderContext context, ISolutionContext solutionContext, FubuCsProjFile.CsProjFile project)
        {
            "Given I have a solution builder context"
            ._(() => context = ServiceLocator.Resolve <SolutionBuilderContext>());

            "When I call build with a solution, a project and an assembly info"
            ._(() => solutionContext = context.CreateBuilder()
                                       .WithSolution(item => item.Path = Path.Combine(context.RootDirectory, "Sally.sln"))
                                       .WithProject(item => item.Name  = "FrodoFx")
                                       .WithFile <AssemblyInfo>(item =>
            {
                item.Title                = "FrodoFx";
                item.Description          = "Middle earth web server";
                item.FileVersion          = new Version(0, 0, 1, 2049);
                item.Version              = new Version(0, 0, 1);
                item.InformationalVersion = "release";
            })
                                       .Build());

            "It should return the build project with an assembly info"
            ._(() =>
            {
                project = new CsProjFile(solutionContext.Solution.Projects.FirstOrDefault().Path);
                project.Should().NotBeNull("the project should not be null");

                project.AssemblyInfo.Should().NotBeNull("the assembly info should not be null");
            });

            "And the assembly info title should be set"
            ._(() => project.AssemblyInfo.AssemblyTitle.Should().Be("FrodoFx"))
            .Teardown(() => context.TearDown());
        }
Esempio n. 6
0
        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());
        }
Esempio n. 7
0
        public void Assemble_with_a_folder_name_creates_a_build_when_folder_name_matches_solution_name(
            CraneRunner craneRunner,
            RunResult result,
            CraneTestContext craneTestContext,
            SolutionBuilderContext solutionBuilderContext)
        {
            "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 a project called ServiceStack with no build"
            ._(() =>
            {
                solutionBuilderContext = ServiceLocator.Resolve <SolutionBuilderContext>();
                solutionBuilderContext
                .CreateBuilder()
                .WithSolution(solution => solution.Path = Path.Combine(craneTestContext.BuildOutputDirectory, "ServiceStack", "ServiceStack.sln"))
                .WithFile(file => file.AddSolutionPackagesConfigWithXUnitRunner(Path.Combine(craneTestContext.BuildOutputDirectory, "ServiceStack", ".nuGet", "packages.config")))
                .WithProject(project => project.Name = "ServiceStack.Core")
                .Build();
            });

            "When I run crane assemble ServiceStack"
            ._(() => result = craneRunner.Command(craneTestContext.BuildOutputDirectory, "crane Assemble ServiceStack"));

            "It should say 'Assemble success.'"
            ._(() =>
            {
                result.ErrorOutput.Should().BeEmpty();
                result.StandardOutput.Should().Be("Assemble success.");
            });

            "It should create a build.ps1 in the top level folder"
            ._(
                () => new DirectoryInfo(Path.Combine(craneTestContext.BuildOutputDirectory, "ServiceStack")).GetFiles()
                .Count(f => f.Name.ToLower() == "build.ps1")
                .Should()
                .Be(1)
                );

            "It should be able to be built successfuly with all tests passing"
            ._(() =>
            {
                var buildResult = new BuildScriptRunner().Run(Path.Combine(craneTestContext.BuildOutputDirectory, "ServiceStack"));
                buildResult.Should().BeBuiltSuccessfulyWithAllTestsPassing().And.BeErrorFree();
            });

            "It should create a build for the project with a reference to the solution file"
            ._(() => File.ReadAllText(Path.Combine(craneTestContext.BuildOutputDirectory, "ServiceStack", "build", "default.ps1")).Should().Contain("ServiceStack.sln"))
            .Teardown(() =>
            {
                solutionBuilderContext.TearDown();
                craneTestContext.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 build_project_with_assembly_info(SolutionBuilderContext context, ISolutionContext result, Project project, AssemblyInfo assemblyInfo)
        {
            "Given I have a solution builder context"
            ._(() => context = ServiceLocator.Resolve <SolutionBuilderContext>());

            "When I call build with a solution, a project and an assembly info"
            ._(() => result = context.CreateBuilder()
                              .WithSolution(item => item.Path = Path.Combine(context.RootDirectory, "Sally.sln"))
                              .WithProject(item => item.Name  = "FrodoFx")
                              .WithFile <AssemblyInfo>(item =>
            {
                item.Title                = "FrodoFx";
                item.Description          = "Middle earth web server";
                item.FileVersion          = new Version(0, 0, 1, 2049);
                item.Version              = new Version(0, 0, 1);
                item.InformationalVersion = "release";
            })
                              .Build());

            "It should return the build project with an assembly info"
            ._(() =>
            {
                project = result.Solution.Projects.FirstOrDefault();
                project.Should().NotBeNull("the project should not be null");
                assemblyInfo = project.AssemblyInfo;
                assemblyInfo.Should().NotBeNull("the assembly info should not be null");
            });

            "And the assembly info title should be set"
            ._(() => assemblyInfo.Title.Should().Be("FrodoFx"));

            "And the assembly info version should be set"
            ._(() => assemblyInfo.Version.Should().Be(new Version(0, 0, 1)));

            "And the assembly info file version should be set"
            ._(() => assemblyInfo.FileVersion.Should().Be(new Version(0, 0, 1, 2049)));

            "And the assembly informational attribute should be set"
            ._(() => assemblyInfo.InformationalVersion.Should().Be("release"));

            "And the assembly info file should exist on disk"
            ._(() => File.Exists(assemblyInfo.Path).Should().BeTrue(string.Format("assembly info with path: {0} did not exist on disk", assemblyInfo.Path)));

            "And it should create a solution file on disk"
            ._(() => File.Exists(Path.Combine(context.RootDirectory, "Sally.sln")).Should().BeTrue())
            .Teardown(() => context.TearDown());
        }
Esempio n. 10
0
        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());
        }
Esempio n. 11
0
        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());
        }