public void create_solution_add_project_save_and_reload_2()
        {
            // Yeah, this is a big bang test.  Just go with it.

            var solution = Solution.CreateNew("TestSolution", "Lib1.TestSolution");

            var reference = solution.AddProject("TestProject");

            reference.ProjectGuid.ShouldNotEqual(Guid.Empty);
            reference.ProjectName.ShouldEqual("TestProject");
            reference.RelativePath.ShouldEqual("TestProject".AppendPath("TestProject.csproj"));

            var plan = new ProjectPlan(reference.ProjectName);

            CodeFileTemplate.Class("Foo").Alter(reference.Project, plan);
            CodeFileTemplate.Class("Bar").Alter(reference.Project, plan);

            solution.Save();

            File.Exists("TestSolution".AppendPath("Lib1.TestSolution.sln")).ShouldBeTrue();
            File.Exists("TestSolution".AppendPath("TestProject", "TestProject.csproj")).ShouldBeTrue();

            var solution2  = Solution.LoadFrom("TestSolution".AppendPath("Lib1.TestSolution.sln"));
            var reference2 = solution2.FindProject("TestProject");

            reference2.ShouldNotBeNull();

            var project2 = reference2.Project;

            project2.ShouldNotBeNull();

            project2.All <CodeFile>().OrderBy(x => x.Include)
            .Select(x => x.Include)
            .ShouldHaveTheSameElementsAs("Bar.cs", "Foo.cs");
        }
Ejemplo n.º 2
0
 public ProjectPlanner()
 {
     base.ShallowMatch(Substitutions.ConfigFile).Do = delegate(TextFile file, TemplatePlan plan)
     {
         plan.CurrentProject.Substitutions.ReadFrom(file.Path);
     };
     base.ShallowMatch(Input.File).Do = delegate(TextFile file, TemplatePlan plan)
     {
         IEnumerable <Input> inputs = Input.ReadFromFile(file.Path);
         plan.CurrentProject.Substitutions.ReadInputs(inputs, new Action <string>(plan.MissingInputs.Add));
     };
     base.Matching(FileSet.Shallow(ProjectPlan.TemplateFile, null)).Do = delegate(TextFile file, TemplatePlan plan)
     {
         plan.CurrentProject.ProjectTemplateFile = file.Path;
     };
     base.Matching(FileSet.Shallow(ProjectPlanner.NugetFile, null)).Do = delegate(TextFile file, TemplatePlan plan)
     {
         GenericEnumerableExtensions.Each <string>(from x in file.ReadLines()
                                                   where FubuCore.StringExtensions.IsNotEmpty(x)
                                                   select x, delegate(string line)
         {
             plan.CurrentProject.NugetDeclarations.Add(line.Trim());
         });
     };
     base.Matching(FileSet.Shallow("assembly-info.txt", null)).Do = delegate(TextFile file, TemplatePlan plan)
     {
         string[] additions = (from x in file.ReadLines()
                               where FubuCore.StringExtensions.IsNotEmpty(x)
                               select x).ToArray <string>();
         plan.CurrentProject.Add(new AssemblyInfoAlteration(additions));
     };
     base.Matching(FileSet.Shallow("references.txt", null)).Do = delegate(TextFile file, TemplatePlan plan)
     {
         GenericEnumerableExtensions.Each <string>(from x in file.ReadLines()
                                                   where FubuCore.StringExtensions.IsNotEmpty(x)
                                                   select x, delegate(string assem)
         {
             plan.CurrentProject.Add(new SystemReference(assem));
         });
     };
     base.Matching(FileSet.Deep("*.cs", null)).Do = delegate(TextFile file, TemplatePlan plan)
     {
         CodeFileTemplate template = new CodeFileTemplate(file.RelativePath, file.ReadAll());
         plan.CurrentProject.Add(template);
     };
     base.ShallowMatch(TemplatePlan.InstructionsFile).Do = delegate(TextFile file, TemplatePlan plan)
     {
         string instructions = file.ReadAll();
         plan.AddInstructions(plan.ApplySubstitutions(instructions));
     };
 }
Ejemplo n.º 3
0
        public ProjectPlanner()
        {
            ShallowMatch(Substitutions.ConfigFile).Do = (file, plan) => {
                plan.CurrentProject.Substitutions.ReadFrom(file.Path);
            };

            ShallowMatch(Input.File).Do = (file, plan) => {
                var inputs = Input.ReadFromFile(file.Path);
                plan.CurrentProject.Substitutions.ReadInputs(inputs, plan.MissingInputs.Add);
            };

            Matching(FileSet.Shallow(ProjectPlan.TemplateFile)).Do = (file, plan) => {
                plan.CurrentProject.ProjectTemplateFile = file.Path;
            };

            Matching(FileSet.Shallow(NugetFile)).Do = (file, plan) => {
                file.ReadLines()
                .Where(x => FubuCore.StringExtensions.IsNotEmpty(x))
                .Each(line => plan.CurrentProject.NugetDeclarations.Add(line.Trim()));
            };

            Matching(FileSet.Shallow(AssemblyInfoAlteration.SourceFile)).Do = (file, plan) => {
                var additions = file.ReadLines().Where(x => x.IsNotEmpty()).ToArray();
                plan.CurrentProject.Add(new AssemblyInfoAlteration(additions));
            };

            Matching(FileSet.Shallow(SystemReference.SourceFile)).Do = (file, plan) => {
                file.ReadLines()
                .Where(x => x.IsNotEmpty())
                .Each(assem => plan.CurrentProject.Add(new SystemReference(assem)));
            };

            Matching(FileSet.Deep("*.cs")).Do = (file, plan) => {
                var template = new CodeFileTemplate(file.RelativePath, file.ReadAll());
                plan.CurrentProject.Add(template);
            };

            ShallowMatch(TemplatePlan.InstructionsFile).Do = (file, plan) =>
            {
                var instructions = file.ReadAll();
                plan.AddInstructions(plan.ApplySubstitutions(instructions));
            };
        }
Ejemplo n.º 4
0
        public void add_deeper_class_to_root_of_project()
        {
            CodeFileTemplate.Class(Path.Combine("Bar", "Doer")).Alter(theProject, thePlan);

            var file = "Templated".AppendPath("TemplatedProject", "Bar", "Doer.cs");

            File.Exists(file).ShouldBeTrue();

            new FileSystem().ReadStringFromFile(file).ShouldEqualWithLineEndings(@"
namespace TemplatedProject.Bar
{
    public class Doer
    {

    }
}
".Trim());

            theProject.All <CodeFile>().Any(x => x.Include == "Bar\\Doer.cs")
            .ShouldBeTrue();
        }
Ejemplo n.º 5
0
        public void add_simple_class_to_root_of_project()
        {
            CodeFileTemplate.Class("Foo").Alter(theProject, thePlan);

            var file = "Templated".AppendPath("TemplatedProject", "Foo.cs");

            File.Exists(file).ShouldBeTrue();

            new FileSystem().ReadStringFromFile(file).ShouldEqualWithLineEndings(@"
namespace TemplatedProject
{
    public class Foo
    {

    }
}
".Trim());

            theProject.All <CodeFile>().Any(x => x.Include == "Foo.cs")
            .ShouldBeTrue();
        }
Ejemplo n.º 6
0
        public void add_simple_class_that_has_substitutions_on_its_name()
        {
            thePlan.Substitutions.Set("%SHORT_NAME%", "MyFoo");

            CodeFileTemplate.Class("%SHORT_NAME%Registry").Alter(theProject, thePlan);

            var file = "Templated".AppendPath("TemplatedProject", "MyFooRegistry.cs");

            File.Exists(file).ShouldBeTrue();

            new FileSystem().ReadStringFromFile(file).ShouldEqualWithLineEndings(@"
namespace TemplatedProject
{
    public class MyFooRegistry
    {

    }
}
".Trim());

            theProject.All <CodeFile>().Any(x => x.Include == "MyFooRegistry.cs")
            .ShouldBeTrue();
        }