public void ExecuteCommandImpl_External_ShouldSaveConfigfile()
        {
            //Arange
            string  externalfileName = "testExternalFileName";
            string  methodName       = "methodName";
            Project selectedProject  = Substitute.For <Project>();

            selectedProject.CodeModel.Language.Returns("C#");

            this.projectManager.MethodName.Returns(methodName);
            this.projectManager.SelectedProject.Returns(selectedProject);
            this.projectManager.ProjectConfigPath.Returns("ProjectConfigPath");
            MethodInfo testMethodInfo = new MethodInfo()
            {
                MethodName = methodName
            };

            IProjectConfiguraiton projectConfiguraiton = Substitute.For <IProjectConfiguraiton>();

            projectConfiguraiton.MethodInfos.Returns(new List <MethodInfo>()
            {
                testMethodInfo
            });

            projectConfigurationManager.CurrentProjectConfiguraiton.Returns(projectConfiguraiton);

            CreateCodeItemViewAdaper createCodeItemViewAdaper = new CreateCodeItemViewAdaper(externalfileName, Aras.Method.Libs.Code.CodeType.External, true);

            this.dialogFactory.GetCreateCodeItemView(Arg.Any <ICodeItemProvider>(), Arg.Any <bool>()).Returns(createCodeItemViewAdaper);

            ICodeProvider codeProvider = Substitute.For <ICodeProvider>();
            CodeInfo      codeItemInfo = new CodeInfo()
            {
                Code = "code",
                Path = @"path\testExternalFileName.cs"
            };

            codeProviderFactory.GetCodeProvider("C#").Returns(codeProvider);
            codeProvider.CreateExternalCodeItemInfo(testMethodInfo, externalfileName, Arg.Any <CodeElementType>(), Arg.Any <bool>(), this.projectManager.ServerMethodFolderPath,
                                                    this.projectManager.SelectedFolderPath,
                                                    this.projectManager.MethodName,
                                                    this.templateLoader,
                                                    this.projectManager.MethodPath)
            .Returns(codeItemInfo);

            //Act
            this.createCodeItemCmd.ExecuteCommandImpl(null, null);

            //Assert
            this.projectConfigurationManager.Received().Save("ProjectConfigPath");
        }
        public override void ExecuteCommandImpl(object sender, EventArgs args)
        {
            string selectedMethodName     = projectManager.MethodName;
            string serverMethodFolderPath = projectManager.ServerMethodFolderPath;
            string selectedFolderPath     = projectManager.SelectedFolderPath;

            MethodInfo methodInformation = projectConfigurationManager.CurrentProjectConfiguraiton.MethodInfos.FirstOrDefault(m => m.MethodName == selectedMethodName);

            if (methodInformation == null)
            {
                throw new Exception(this.messageManager.GetMessage("ConfigurationsForTheMethodNotFound", selectedMethodName));
            }

            var view       = dialogFactory.GetCreateCodeItemView(this.codeProviderFactory.GetCodeItemProvider(projectManager.Language), projectConfigurationManager.CurrentProjectConfiguraiton.UseVSFormatting);
            var viewResult = view.ShowDialog();

            if (viewResult?.DialogOperationResult != true)
            {
                return;
            }

            string packageMethodFolderPath = this.projectConfigurationManager.CurrentProjectConfiguraiton.UseCommonProjectStructure ? methodInformation.Package.MethodFolderPath : string.Empty;
            string methodWorkingFolder     = Path.Combine(serverMethodFolderPath, packageMethodFolderPath, methodInformation.MethodName);

            string codeItemPath = selectedFolderPath.Substring(methodWorkingFolder.Length).TrimStart('\\', '/');

            codeItemPath = Path.Combine(codeItemPath, viewResult.FileName);

            string newFilePath = Path.Combine(methodWorkingFolder, codeItemPath) + GlobalConsts.CSExtension;

            if (File.Exists(newFilePath))
            {
                throw new Exception(this.messageManager.GetMessage("CodeItemAlreadyExists"));
            }

            TemplateLoader templateLoader = new TemplateLoader();

            templateLoader.Load(projectManager.MethodConfigPath);

            ICodeProvider codeProvider = codeProviderFactory.GetCodeProvider(projectManager.Language);
            CodeInfo      codeItemInfo = null;

            if (viewResult.SelectedCodeType == CodeType.Partial)
            {
                codeItemInfo = codeProvider.CreatePartialCodeItemInfo(methodInformation,
                                                                      viewResult.FileName,
                                                                      viewResult.SelectedElementType,
                                                                      viewResult.IsUseVSFormattingCode,
                                                                      methodWorkingFolder,
                                                                      projectManager.SelectedFolderPath,
                                                                      projectManager.MethodName,
                                                                      templateLoader,
                                                                      projectManager.MethodPath);
            }
            else if (viewResult.SelectedCodeType == CodeType.External)
            {
                codeItemInfo = codeProvider.CreateExternalCodeItemInfo(methodInformation,
                                                                       viewResult.FileName,
                                                                       viewResult.SelectedElementType,
                                                                       viewResult.IsUseVSFormattingCode,
                                                                       methodWorkingFolder,
                                                                       projectManager.SelectedFolderPath,
                                                                       projectManager.MethodName,
                                                                       templateLoader,
                                                                       projectManager.MethodPath);
            }

            projectManager.AddItemTemplateToProjectNew(codeItemInfo, packageMethodFolderPath, true, 0);

            projectConfigurationManager.CurrentProjectConfiguraiton.UseVSFormatting = viewResult.IsUseVSFormattingCode;
            projectConfigurationManager.Save(projectManager.ProjectConfigPath);
        }