Exemplo n.º 1
0
        public void Apply(ModelSpecification viewModelSpecification, File mvvmFile)
        {
            var project = mvvmFile.Project as Project;

            if (!project.HasFolder(Controllers))
            {
                project.AddFolder(factory.NewFolder(Controllers, project));
            }

            var controllersFolder = project.GetSubFolder(Controllers);

            foreach (var viewModel in viewModelSpecification.ViewModels)
            {
                var fileName = string.Format("{0}Controller.cs", viewModel.Name);

                if (!controllersFolder.HasFile(fileName))
                {
                    controllersFolder.NewFile(fileName);

                    var controllerFile = controllersFolder.GetFile(fileName);

                    codeGeneratorService.Generate(mvvmFile, controllerFile, new CodeGeneratorArgs(viewModelSpecification, viewModel, codeGenTemplate));
                }
            }
        }
Exemplo n.º 2
0
        public void Apply(ModelSpecification mvvmDefinition, File mvvmFile)
        {
            var project = mvvmFile.Project;

            if (!project.HasFolder(Views))
            {
                project.AddFolder(factory.NewFolder(Views, project));
            }

            foreach (var viewModel in mvvmDefinition.ViewModels)
            {
                var fileName           = string.Format("{0}.xaml", viewModel.Name);
                var codeBehindFileName = string.Format("{0}.xaml.cs", viewModel.Name);

                var viewsFolder = project.GetSubFolder(Views);
                if (!viewsFolder.HasFile(fileName))
                {
                    var viewFile = factory.NewFile(fileName, viewsFolder);
                    viewsFolder.AddFile(viewFile);
                    codeGeneratorService.Generate(mvvmFile, viewFile,
                                                  new CodeGeneratorArgs(mvvmDefinition, viewModel, viewCodeGenTemplate));

                    var viewCodeBehindFile = viewFile.NewCodeBehindFile(codeBehindFileName);
                    codeGeneratorService.Generate(mvvmFile, viewCodeBehindFile,
                                                  new CodeGeneratorArgs(mvvmDefinition, viewModel, viewCodeBehindCodeGenTemplate));
                }
            }
        }
        public void Test_to_serialize_and_deserialize_ModelSpecification()
        {
            var modelSpec = new ModelSpecification();

            SerializeToString <ModelSpecification>(modelSpec);

            Assert.IsNotNull(DeserializeFromString <ModelSpecification>());
        }
        public void Apply(ModelSpecification viewModelSpecification, File mvvmFile)
        {
            this.mvvmFile = mvvmFile;
            this.viewModelSpecification = viewModelSpecification;

            RemoveDeletedViewModelsFromCodeBehind();

            AddNewViewModelsToCodeBehind();
        }
Exemplo n.º 5
0
        public CodeGeneratorArgs(ModelSpecification modelSpecification, ViewModel viewModel, ITemplate template)
        {
            Guard.Requries <ArgumentException>(modelSpecification != null);
            Guard.Requries <ArgumentException>(viewModel != null);
            Guard.Requries <ArgumentException>(template != null);

            ModelSpecification = modelSpecification;
            ViewModel          = viewModel;
            Template           = template;
        }
            public void Setup()
            {
                Given(VisualStudioSolution_exists);
                And("ViewModel is described", () =>
                {
                    mvvmSpecification = new ModelSpecification();
                    mvvmSpecification.AddViewModel(new ViewModel("Login"));
                });
                And(ControllersConvention_is_created);

                When("apply Convention", () =>
                     convention.Apply(mvvmSpecification, mvvmFile));
            }
Exemplo n.º 7
0
            public void Setup()
            {
                Given(VisualStudio_Solution_exists);
                And(Solution_has_a_UnitTest_Project);
                And("ViewModel is described", () =>
                {
                    mvvmDefinition = new ModelSpecification();
                    mvvmDefinition.AddViewModel(new ViewModel("Login"));
                });
                And(UnitTestConvention_is_created);

                When("apply Convention", () =>
                     convention.Apply(mvvmDefinition, mvvmFile));
            }
Exemplo n.º 8
0
            public void ViewModel_is_described()
            {
                modelSpecification = new ModelSpecification();
                var loginViewModel = new ViewModel("Login");

                loginViewModel.AddProperty(new ViewModelProperty("Username", "string", false));
                loginViewModel.AddProperty(new ViewModelProperty("Password", "string", false));
                loginViewModel.AddCommand(new ViewModelCommand("Login"));
                modelSpecification.AddViewModel(loginViewModel);

                var mainScreenViewModel = new ViewModel("MainScreen");

                mainScreenViewModel.AddProperty(new ViewModelProperty("Title", "string", true));
                modelSpecification.AddViewModel(mainScreenViewModel);
            }
Exemplo n.º 9
0
        public void Apply(ModelSpecification mvvmDefinition, File mvvmFile)
        {
            var viewModelFolder = mvvmFile.Parent;

            foreach (var viewModel in mvvmDefinition.ViewModels)
            {
                var name = string.Format("{0}.cs", viewModel.Name);
                if (!viewModelFolder.HasFile(name))
                {
                    var newFile = viewModelFolder.NewFile(name);

                    codeGeneratorService.Generate(mvvmFile, newFile, new CodeGeneratorArgs(mvvmDefinition, viewModel, codeGeneratorTemplate));
                }
            }
        }
Exemplo n.º 10
0
            public void Setup()
            {
                Given(ViewsConvention_is_created);
                And(Solution_is_created);
                And("ViewModel is described", () =>
                {
                    mvvmDefinition     = new ModelSpecification();
                    var loginViewModel = new ViewModel("Login");
                    loginViewModel.AddProperty(new ViewModelProperty("Username", "String", false));
                    loginViewModel.AddProperty(new ViewModelProperty("Password", "String", false));
                    loginViewModel.AddCommand(new ViewModelCommand("Login"));
                    mvvmDefinition.AddViewModel(loginViewModel);
                });

                When(ApplyConvention);
            }
Exemplo n.º 11
0
        public void Apply(ModelSpecification viewModelSpecification, File mvvmFile)
        {
            var project  = mvvmFile.Project;
            var solution = project.Solution;

            var testProject = solution.Projects.Where(p => p.Name == string.Format("{0}.Tests", project.Name) ||
                                                      p.Name == string.Format("{0}Tests", project.Name)).FirstOrDefault();

            if (testProject != null)
            {
                Folder folderInUnitTestProj = CreateFolderInUnitTestProject(mvvmFile, testProject);

                if (!folderInUnitTestProj.HasFolder("TestScenarios"))
                {
                    folderInUnitTestProj.AddFolder(factory.NewFolder("TestScenarios", folderInUnitTestProj));
                }

                var testScenariosFolder = folderInUnitTestProj.GetSubFolder("TestScenarios");

                foreach (var viewModel in viewModelSpecification.ViewModels)
                {
                    var testScenarioFileName = string.Format("{0}TestScenario.cs", viewModel.Name);
                    var unitTestFileName     = string.Format("{0}Tests.cs", viewModel.Name);

                    if (!testScenariosFolder.HasFile(testScenarioFileName))
                    {
                        var testScenarioFile = factory.NewFile(testScenarioFileName, testScenariosFolder);
                        testScenariosFolder.AddFile(testScenarioFile);
                    }

                    codeGeneratorService.Generate(mvvmFile, testScenariosFolder.GetFile(testScenarioFileName),
                                                  new CodeGeneratorArgs(viewModelSpecification, viewModel, testScenarioCodeGenTemplate));

                    //UnitTests
                    if (!folderInUnitTestProj.HasFile(unitTestFileName))
                    {
                        var unitTestFile = factory.NewFile(unitTestFileName, folderInUnitTestProj);
                        folderInUnitTestProj.AddFile(unitTestFile);

                        codeGeneratorService.Generate(mvvmFile, unitTestFile,
                                                      new CodeGeneratorArgs(viewModelSpecification, viewModel, unitTestCodeGenTemplate));
                    }
                }
            }
        }
Exemplo n.º 12
0
            public void Setup()
            {
                Given(VisualStudio_Solution_exists);
                And(Solution_has_a_UnitTest_Project);
                And("Project has a .mvvm file deep in the tree", () =>
                {
                    mvvmFile = project.NewFolder("Test").NewFolder("SubFolder").NewFolder("ViewModel").NewFile("viewmodel.mvvm");
                });
                And("ViewModel is described", () =>
                {
                    mvvmDefinition = new ModelSpecification();
                    mvvmDefinition.AddViewModel(new ViewModel("EditUserViewModel"));
                });
                And(UnitTestConvention_is_created);

                When("apply Convention", () =>
                     convention.Apply(mvvmDefinition, mvvmFile));
            }
Exemplo n.º 13
0
            public void Setup()
            {
                Given(ViewsConvention_is_created);
                And(Solution_is_created);
                And("Project has 'Views' folder and Views", () =>
                {
                    var viewsFolder = project.NewFolder("Views");

                    viewsFolder.NewFile("Login.xaml");
                });
                And("ViewModel is described", () =>
                {
                    mvvmDefinition     = new ModelSpecification();
                    var loginViewModel = new ViewModel("Login");
                    loginViewModel.AddProperty(new ViewModelProperty("Username", "String", false));
                    loginViewModel.AddProperty(new ViewModelProperty("Password", "String", false));
                    loginViewModel.AddCommand(new ViewModelCommand("Login"));
                    mvvmDefinition.AddViewModel(loginViewModel);
                });

                When(ApplyConvention);
            }
Exemplo n.º 14
0
        public ModelSpecification Parse(ICodeLoader loadingStrategy)
        {
            if (loadingStrategy == null)
            {
                throw new ArgumentNullException();
            }

            loadedCode = loadingStrategy.Load();

            if (loadedCode == null)
            {
                throw new InvalidOperationException("Code must be loaded before it's possible to parse");
            }

            tokensEnumerator = scanner.Scan(loadedCode).GetEnumerator();

            modelSpecification      = new ModelSpecification();
            modelSpecification.Code = loadedCode;

            ParseViewModels();

            return(modelSpecification);
        }