示例#1
0
        public void ShouldGenerateList()
        {
            var entity = new Entity
            {
                Name = "Book",
                Properties = new List<EntityProperty>
                                                  {
                                                      new EntityProperty{Name =  "Id", Type = "System.Int64"},
                                                      new EntityProperty{Name =  "Name", Type = "System.String"}
                                                  }

            };
            configurationMock.Stub(x => x.TestNameSpace).Return("Blah.Test");
            configurationMock.Stub(x => x.CoreNameSpace).Return("Blah.Core");
            configurationMock.Stub(x => x.WebNameSpace).Return("Blah.Web");

            entityManagerMock.Stub(x => x.ReadEntity("Book")).Return(entity);

            listGenerator.Execute(new List<string>{"Book", "MyBook"});

            VerifyGenerateController();
            VerifyGenerateControllerTests();
            VerifyGenerateViewModel();
            VerifyGenerateView();
            VerifyCreateDirectory();
        }
示例#2
0
        public void ShouldGenerateUi()
        {
            var entity = new Entity
            {
                Name = "Book",
                Properties = new List<EntityProperty>
                                                  {
                                                      new EntityProperty{Name =  "Id", Type = "System.Int64"},
                                                      new EntityProperty{Name =  "Name", Type = "System.String"}
                                                  }

            };
            configurationMock.Stub(x => x.TestNameSpace).Return("Blah.Test");
            configurationMock.Stub(x => x.CoreNameSpace).Return("Blah.Core");
            configurationMock.Stub(x => x.WebNameSpace).Return("Blah.Web");
            entityManagerMock.Stub(x => x.ReadEntity("Book")).Return(entity);

            uiGenerator.Execute(new List<string>{"Book"});

            VerifyGenerateController();
            VerifyGenerateViewModel();
            VerifyCreateViewFolder();
            VerifyGenerateIndexView();
            VerifyGenerateCreateView();
            VerifyGenerateDetailsView();
            VerifyGenerateEditView();
            VerifyGenerateControllerTests();
            VerifyGenerateAutoMapperTests();
            VerifyAddToAutoMapper();
        }
示例#3
0
        private void GenerateDependencyInjection(Entity entity)
        {
            var repositoryInterface = "I" + entity.Name + "Repository";
            var repositoryImplementation = entity.Name + "Repository";
            var namespaces = new[]{configuration.CoreNameSpace + ".Domain.Repositories", configuration.CoreNameSpace + ".Repositories"};

            depencyInjectionManager.AddToCoreDependencyInjection(repositoryInterface, repositoryImplementation, namespaces);
            depencyInjectionManager.AddToDependencyInjectionTest(repositoryInterface, new[] { configuration.CoreNameSpace + ".Domain.Repositories" });
        }
示例#4
0
        private void GenerateRepository(Entity entity)
        {
            var generatedFile = "Repositories\\" + entity.Name + "Repository.cs";
            const string template = "Scaffold.Generator.Repository.Repository.template";

            var templateData = new { Entity = entity, CoreNamespace = configuration.CoreNameSpace };
            templateEngine.GenerateFromTemplate(template, configuration.CoreNameSpace + "\\" + generatedFile, templateData);

            projectFileManager.AddCompileFileToProject(generatedFile, configuration.CoreNameSpace);
        }
示例#5
0
 public void ShouldCreateEntity()
 {
     var entity = new Entity
                      {
                          Name = "Foo",
                          Properties =
                              new List<EntityProperty> {new EntityProperty {Name = "Bar", Type = "System.String"}}
                      };
     Assert.AreEqual("Foo", entity.Name);
     Assert.AreEqual(1, entity.Properties.Count);
 }
        private void GenerateAutoFixtureCustomization(Entity entity)
        {
            var filePath = configuration.TestNameSpace + "\\AutoFixtureCustomization.cs";
            var fileMerger = new FileMerger(fileSystem);

            var codeSnippet = AutoFixtureCustomizationCodeSnippet(entity);

            fileMerger.InsertLineIntoMethod(filePath, codeSnippet, "Customize", "Customize<" + entity.Name + ">");

            string @namespace = "using " + configuration.CoreNameSpace + ".Domain.Model;";
            fileMerger.InsertFirstLine(filePath, @namespace, @namespace);
        }
示例#7
0
 public void ShouldGetReferenceProperties()
 {
     var properties = new List<EntityProperty>
                          {
                              CreateProperty("1", "IList"),
                              CreateProperty("2", "System.Int32"),
                              CreateProperty("3", "Scaffold.Test.Entities.Foo"),
                              CreateProperty("4", "ICollection"),
                              CreateProperty("5", "System.Boolean")
                          };
     var entity = new Entity { Name = "Foo", Properties = properties };
     CollectionAssert.AreEqual(new[] { "3" },
                               entity.ReferenceProperties.Select(x => x.Name).ToList());
 }
 private static string AutoFixtureCustomizationCodeSnippet(Entity entity)
 {
     var codeSnippet = "            fixture.Customize<" + entity.Name + ">(x => x.Without(y => y.Id)";
     foreach (var property in entity.ReferenceProperties)
     {
         codeSnippet += ".Without(y => y." + property.Name + ")";
     }
     foreach (var property in entity.CollectionProperties)
     {
         codeSnippet += ".Without(y => y." + property.Name + ")";
     }
     codeSnippet += ");";
     return codeSnippet;
 }
示例#9
0
        private void GenerateAutoMapperTests(Entity entity, string formName)
        {
            var generatedFile = "Common\\AutoMapper\\" + formName + "AutoMapperTests.cs";
            const string template = "Scaffold.Generator.Form.AutoMapperTests.template";

            var templateData =
                new
                {
                    Entity = entity,
                    FormName = formName,
                    FormVariableName = StringHelper.LowercaseFirst(formName),
                    CoreNamespace = configuration.CoreNameSpace,
                    WebNamespace = configuration.WebNameSpace,
                    TestNamespace = configuration.TestNameSpace
                };
            templateEngine.GenerateFromTemplate(template, configuration.TestNameSpace + "\\" + generatedFile, templateData);

            projectFileManager.AddCompileFileToProject(generatedFile, configuration.TestNameSpace);
        }
        public void ShouldGenerateRepository()
        {
            var entity = new Entity
                             {
                                 Name = "Book",
                                 Properties = new List<EntityProperty>
                                                  {
                                                      new EntityProperty{Name =  "Id", Type = "System.Int64"},
                                                      new EntityProperty{Name =  "Name", Type = "System.String"}
                                                  }

                             };
            configurationMock.Stub(x => x.TestNameSpace).Return("Blah.Test");
            configurationMock.Stub(x => x.CoreNameSpace).Return("Blah.Core");
            entityManagerMock.Stub(x => x.ReadEntity("Book")).Return(entity);

            repositoryGenerator.Execute(new List<string>{"Book"});

            VerifyGenerateRepository();
            VerifyGenerateRepositoryInterface();
            VerifyGenerateRepositoryTests();
        }
示例#11
0
 private void CreateViewFolder(Entity entity)
 {
     fileSystem.CreateDirectory(configuration.WebNameSpace + "\\Views\\" + entity.Name);
 }
示例#12
0
        private void GenerateIndexView(Entity entity, string formName)
        {
            fileSystem.CreateDirectory(configuration.WebNameSpace + "\\Views\\" + formName);

            var generatedFile = "Views\\" + formName + "\\Index.cshtml";
            const string template = "Scaffold.Generator.Form.Index.template";

            var templateData =
                new
                {
                    FormName = formName,
                    Entity = entity,
                    WebNamespace = configuration.WebNameSpace,
                    CoreNamespace = configuration.CoreNameSpace
                };
            templateEngine.GenerateFromTemplate(template, configuration.WebNameSpace + "\\" + generatedFile, templateData);

            projectFileManager.AddContentFileToProject(generatedFile, configuration.WebNameSpace);
        }
示例#13
0
        private void GenerateNHibernateMapping(Entity entity)
        {
            var generatedFile = "Common\\NHibernate\\" + entity.Name + "Map.cs";
            const string template = "Scaffold.Generator.NHibernate.NHibernateMap.template";

            var templateData =
                new
                    {
                        Entity = entity,
                        CoreNamespace = configuration.CoreNameSpace,
                    };
            templateEngine.GenerateFromTemplate(template, configuration.CoreNameSpace + "\\" + generatedFile, templateData);

            projectFileManager.AddCompileFileToProject(generatedFile, configuration.CoreNameSpace);
        }
示例#14
0
        private void GenerateController(Entity entity)
        {
            string controllerName = entity.Name + "Controller";
            var generatedFile = "Controllers\\" + controllerName + ".cs";
            const string template = "Scaffold.Generator.Ui.Controller.template";

            var templateData =
                new
                    {
                        Entity = entity,
                        WebNamespace = configuration.WebNameSpace,
                        CoreNamespace = configuration.CoreNameSpace
                    };
            templateEngine.GenerateFromTemplate(template, configuration.WebNameSpace + "\\" + generatedFile, templateData);

            projectFileManager.AddCompileFileToProject(generatedFile, configuration.WebNameSpace);
            depencyInjectionManager.AddToDependencyInjectionTest(controllerName, new[] { configuration.WebNameSpace + ".Controllers" });
        }
示例#15
0
        private void GenerateController(Entity entity, string formName)
        {
            var generatedFile = "Controllers\\" + formName + "Controller.cs";
            const string template = "Scaffold.Generator.Form.Controller.template";

            var templateData =
                new
                {
                    FormVariableName = StringHelper.LowercaseFirst(formName),
                    FormName = formName,
                    Entity = entity,
                    WebNamespace = configuration.WebNameSpace,
                    CoreNamespace = configuration.CoreNameSpace
                };
            templateEngine.GenerateFromTemplate(template, configuration.WebNameSpace + "\\" + generatedFile, templateData);

            projectFileManager.AddCompileFileToProject(generatedFile, configuration.WebNameSpace);
        }
示例#16
0
        private void GenerateIndexView(Entity entity)
        {
            var generatedFile = "Views\\" + entity.Name + "\\Index.cshtml";
            const string template = "Scaffold.Generator.Ui.Index.template";

            var templateData =
                new
                {
                    Entity = entity,
                    WebNamespace = configuration.WebNameSpace,
                    CoreNamespace = configuration.CoreNameSpace
                };
            templateEngine.GenerateFromTemplate(template, configuration.WebNameSpace + "\\" + generatedFile, templateData);

            projectFileManager.AddContentFileToProject(generatedFile, configuration.WebNameSpace);
        }
        private void StubReadEntity()
        {
            var entity = new Entity
                             {
                                 Name = "Book",
                                 Properties = new List<EntityProperty>
                                                  {
                                                      new EntityProperty {Name = "Id", Type = "System.Int64"},
                                                      new EntityProperty {Name = "Title", Type = "System.String"},
                                                      new EntityProperty {Name = "Author", Type = "System.String"}
                                                  }
                             };

            entityManagerMock.Stub(x => x.ReadEntity("Book")).Return(entity);
        }
示例#18
0
        private void GenerateAutoMapperTest(Entity entity)
        {
            var generatedFile = "Common\\AutoMapper\\" + entity.Name + "AutoMapperTests.cs";
            const string template = "Scaffold.Generator.Ui.AutoMapperTest.template";

            var templateData =
                new
                {
                    Entity = entity,
                    TestNamespace = configuration.TestNameSpace,
                    WebNamespace = configuration.WebNameSpace,
                    CoreNamespace = configuration.CoreNameSpace
                };
            templateEngine.GenerateFromTemplate(template, configuration.TestNameSpace + "\\" + generatedFile, templateData);

            projectFileManager.AddCompileFileToProject(generatedFile, configuration.TestNameSpace);
        }
示例#19
0
 private void GenerateAutoMapperConfiguration(Entity entity)
 {
     autoMapperHelper.AddAutoMapperConfiguration(entity.Name, entity.Name + "ViewModel");
 }
示例#20
0
        private void GenerateViewModel(Entity entity)
        {
            var generatedFile = "Models\\" + entity.Name + "ViewModel.cs";
            const string template = "Scaffold.Generator.Ui.ViewModel.template";

            var templateData =
                new
                {
                    Entity = entity,
                    WebNamespace = configuration.WebNameSpace,
                    CoreNamespace = configuration.CoreNameSpace
                };
            templateEngine.GenerateFromTemplate(template, configuration.WebNameSpace + "\\" + generatedFile, templateData);

            projectFileManager.AddCompileFileToProject(generatedFile, configuration.WebNameSpace);
        }