Exemplo n.º 1
0
        public void LoadMethod_ShouldReturnNull()
        {
            //Arange
            XmlMethodLoader xmlMethodLoader = new XmlMethodLoader();

            //Act
            XmlMethodInfo loadMethodResult = xmlMethodLoader.LoadMethod("");

            //Assert
            Assert.IsNull(loadMethodResult);
        }
Exemplo n.º 2
0
        private ObservableCollection <KeyValuePair <string, XmlMethodInfo> > LoadUserCodeTemplates()
        {
            List <string>        paths          = this.globalConfiguration.GetUserCodeTemplatesPaths();
            List <XmlMethodInfo> xmlMethodInfos = new XmlMethodLoader().LoadMethods(paths).Where(x => x.MethodType == this.codeProvider.Language).ToList();
            ObservableCollection <KeyValuePair <string, XmlMethodInfo> > templates = new ObservableCollection <KeyValuePair <string, XmlMethodInfo> >();

            templates.Add(new KeyValuePair <string, XmlMethodInfo>(None, new XmlMethodInfo()));
            foreach (XmlMethodInfo xmlMethodInfo in xmlMethodInfos)
            {
                templates.Add(new KeyValuePair <string, XmlMethodInfo>(xmlMethodInfo.MethodName, xmlMethodInfo));
            }

            return(templates);
        }
Exemplo n.º 3
0
        private void BrowseCodeTemplateCommandClick()
        {
            var openFileDialogAdapter = this.dialogFactory.GetOpenFileDialog("XML Files (*.xml)|*.xml", "xml");

            OpenFileDialogResult dialogResult = openFileDialogAdapter.ShowDialog();

            if (dialogResult.DialogResult == DialogResult.Cancel)
            {
                return;
            }

            XmlMethodInfo xmlMethodInfo = new XmlMethodLoader().LoadMethod(dialogResult.FileName);

            if (xmlMethodInfo == null)
            {
                var messageWindow = this.dialogFactory.GetMessageBoxWindow();
                var dialogReuslt  = messageWindow.ShowDialog(messageManager.GetMessage("UserCodeTemplateInvalidFormat"),
                                                             messageManager.GetMessage("Warning"),
                                                             MessageButtons.OK,
                                                             MessageIcon.Warning);

                return;
            }

            if (xmlMethodInfo.MethodType != codeProvider.Language)
            {
                var messageWindow = this.dialogFactory.GetMessageBoxWindow();
                var dialogReuslt  = messageWindow.ShowDialog(messageManager.GetMessage("UserCodeTamplateMustBeMethodType", codeProvider.Language),
                                                             messageManager.GetMessage("Warning"),
                                                             MessageButtons.OK,
                                                             MessageIcon.Warning);

                return;
            }

            KeyValuePair <string, XmlMethodInfo> userCodeTemplate = this.UserCodeTemplates.FirstOrDefault(x => x.Key == xmlMethodInfo.MethodName);

            if (userCodeTemplate.Key == default(KeyValuePair <string, XmlMethodInfo>).Key)
            {
                this.globalConfiguration.AddUserCodeTemplatePath(xmlMethodInfo.Path);
                this.globalConfiguration.Save();

                userCodeTemplate = new KeyValuePair <string, XmlMethodInfo>(xmlMethodInfo.MethodName, xmlMethodInfo);
                UserCodeTemplates.Add(userCodeTemplate);
            }

            SelectedUserCodeTemplate = userCodeTemplate;
        }
Exemplo n.º 4
0
        public void LoadMethod_ShouldReturnExpected()
        {
            //Arange
            var             currentPath     = System.AppDomain.CurrentDomain.BaseDirectory;
            var             methodAmlPath   = Path.Combine(currentPath, @"Code\TestData\MethodAml\ReturnNullMethodAml.xml");
            XmlMethodLoader xmlMethodLoader = new XmlMethodLoader();

            //Act
            XmlMethodInfo loadMethodResult = xmlMethodLoader.LoadMethod(methodAmlPath);

            //Assert
            Assert.IsNotNull(loadMethodResult);
            Assert.AreEqual("\r\nreturn null;", loadMethodResult.Code);
            Assert.AreEqual("ReturnNullMethodAml", loadMethodResult.MethodName);
            Assert.AreEqual("C#", loadMethodResult.MethodType);
            Assert.AreEqual(methodAmlPath, loadMethodResult.Path);
        }
Exemplo n.º 5
0
        public void LoadMethods_ShouldReturnExpected()
        {
            //Arange
            var             currentPath     = System.AppDomain.CurrentDomain.BaseDirectory;
            var             methodAmlPath   = Path.Combine(currentPath, @"Code\TestData\MethodAml\ReturnNullMethodAml.xml");
            XmlMethodLoader xmlMethodLoader = new XmlMethodLoader();
            List <string>   methodPaths     = new List <string>()
            {
                methodAmlPath
            };

            //Act
            List <XmlMethodInfo> loadMethodResult = xmlMethodLoader.LoadMethods(methodPaths);

            //Assert
            Assert.IsNotNull(loadMethodResult);
            Assert.AreEqual(1, loadMethodResult.Count);
        }