public void will_not_blow_up_on_missing_element() { var el = new XElement("test", "foo"); string bar = XMLUtilities.test_element(el, "bar"); Assert.That(bar == ""); }
public List <Record> GetAll() { XMLUtilities <DataStore> xmlUtilities = new XMLUtilities <DataStore>(); var dataStore = xmlUtilities.DeSerialize(FWConstant.DataStoreFile); return(dataStore?.Records); }
public string GetXML(string filePath) { string strXML = string.Empty; try { if (!string.IsNullOrEmpty(filePath)) { DataTable dt = ExcelHelper.GetExcelData(filePath); if (dt != null && dt.Rows.Count > 0) { strXML = XMLUtilities.Serialize(dt); } System.IO.File.Delete(filePath); } } catch (Exception ex) { Logger.LogException(ex); throw new ApplicationException(ErrorConstants.GetExcelError); } return(strXML); }
public IEnumerator CorrectGuid() { CreateFolder($"{Application.dataPath}/Plugins"); CopyScriptToAssetsFolder(Application.dataPath, "SimpleCSharpScript.cs", k_EmptyCSharpScript); CopyScriptToAssetsFolder($"{Application.dataPath}/Plugins", "Plugin.cs", k_EmptyCSharpScript); yield return(new RecompileScripts(true)); m_ProjectGeneration.Sync(); var dir = Directory.GetParent(Application.dataPath).FullName; var scriptProjectFile = Path.Combine(dir, "Assembly-CSharp.csproj"); var scriptPluginProjectFile = Path.Combine(dir, "Assembly-CSharp-firstpass.csproj"); Assert.IsTrue(File.Exists(scriptProjectFile)); Assert.IsTrue(File.Exists(scriptPluginProjectFile)); XmlDocument scriptProject = XMLUtilities.FromFile(scriptProjectFile); XmlDocument scriptPluginProject = XMLUtilities.FromFile(scriptPluginProjectFile); var xmlNamespaces = new XmlNamespaceManager(scriptProject.NameTable); xmlNamespaces.AddNamespace("msb", "http://schemas.microsoft.com/developer/msbuild/2003"); Assert.AreEqual(scriptPluginProject.SelectSingleNode("/msb:Project/msb:PropertyGroup/msb:ProjectGuid", xmlNamespaces).InnerText, scriptProject.SelectSingleNode("/msb:Project/msb:ItemGroup/msb:ProjectReference/msb:Project", xmlNamespaces).InnerText); }
public IEnumerator EditorPluginsReferencePlugin() { CreateFolder($"{Application.dataPath}/Plugins"); CreateFolder($"{Application.dataPath}/Plugins/Editor"); CopyScriptToAssetsFolder($"{Application.dataPath}/Plugins", "Plugin.cs", k_EmptyCSharpScript); CopyScriptToAssetsFolder($"{Application.dataPath}/Plugins/Editor", "EditorPlugin.cs", k_EmptyCSharpScript); var dir = Directory.GetParent(Application.dataPath).FullName; m_CsProjPath = Path.Combine(dir, "Assembly-CSharp-Editor-firstpass.csproj"); yield return(new RecompileScripts(true)); m_ProjectGeneration.Sync(); var projectReferences = new[] { "Assembly-CSharp-firstpass", "Unity.Rider.Editor", "AsmdefResponse" }; var expectedReferencesEditor = new[] { "System", "System.Xml", "System.Core", "UnityEngine", "UnityEditor", "UnityEditor.Graphs" }; var projectXml = XMLUtilities.FromFile(m_CsProjPath); XMLUtilities.AssertReferencesContainAll(projectXml, expectedReferencesEditor); XMLUtilities.AssertProjectReferencesMatchExactly(projectXml, projectReferences); }
public void will_return_value_from_missing_element() { XElement el = XElement.Parse("<fooBar foo=\"bar\" />"); string str = XMLUtilities.test_element(el, "snafu"); Assert.IsNotNull(str); }
public void will_not_blow_up_on_missing_attribute() { var el = new XElement("test", "foo"); string bar = XMLUtilities.test_attribute("bar", el); Assert.That(bar == ""); }
public void will_ignore_null_value() { XElement el = XElement.Parse("<fooBar foo=\"bar\" />"); XMLUtilities.set_attribute("foo", null, el); Assert.That(el.Attribute("foo").Value == "bar"); }
public void can_set_value_for_existing_attribute() { XElement el = XElement.Parse("<fooBar foo=\"bar\" />"); XMLUtilities.set_attribute("foo", "bel", el); Assert.That(el.Attribute("foo").Value == "bel"); }
public DataTable Save(BatchDetail det, CompanyDetail companydet, string filePath, DataTable dtcounties) { Save(det); DataTable dtData = GetData(filePath); if (dtData.Rows.Count > 0) { DataTable dtDTSMapping = null; DataTable dtCaseTypeMapping = null; det.TotalCount = dtData.Rows.Count; det.CreatedDate = DateTime.Now; if (companydet.DTSMapping != null) { dtDTSMapping = (DataTable)XMLUtilities.Deserialize(companydet.DTSMapping, typeof(DataTable)); } if (companydet.CaseTypeMapping != null) { dtCaseTypeMapping = (DataTable)XMLUtilities.Deserialize(companydet.CaseTypeMapping, typeof(DataTable)); } Transform(det, ref dtData, dtDTSMapping, dtCaseTypeMapping, dtcounties); } else { throw new ApplicationException(ErrorConstants.EmptyBatchError); } return(dtData); }
public IEnumerator IncludesScriptsInPlugins() { CreateFolder($"{Application.dataPath}/Test"); CreateFolder($"{Application.dataPath}/Test/Hello"); CopyScriptToAssetsFolder($"{Application.dataPath}/Test", "Test.asmdef", @"{ ""name"" : ""Test"" }"); CopyScriptToAssetsFolder($"{Application.dataPath}/Test", "Script.cs", " "); CopyScriptToAssetsFolder($"{Application.dataPath}/Test", "Doc.txt", " "); CopyScriptToAssetsFolder($"{Application.dataPath}/Test/Hello", "Hello.txt", " "); var dir = Directory.GetParent(Application.dataPath).FullName; m_CsProjPath = Path.Combine(dir, "Test.csproj"); yield return(new RecompileScripts(true)); m_ProjectGeneration.Sync(); var sourceFiles = new[] { "Test/Script.cs" }; var textFiles = new[] { "Test/Test.asmdef", "Test/Doc.txt", "Test/Hello/Hello.txt" }; var projectXml = XMLUtilities.FromFile(m_CsProjPath); XMLUtilities.AssertCompileItemsMatchExactly(projectXml, sourceFiles); XMLUtilities.AssertNonCompileItemsMatchExactly(projectXml, textFiles); }
//エディタの保存ボタンが押下されたのでファイルを上書きする private void EditorSaveClick(object sender, RoutedEventArgs e) { vm.sourceChanged = false; //ソース変化なし orgSource = sourceEditor.Text; //現在のソースを変更前に保存する var enc = XMLUtilities.GetEncodingFormat(targetSource); //対象のソースのエンコードを取得する System.IO.File.WriteAllText(targetSource, orgSource, enc); //ファイルを上書きする }
public void can_set_and_get_element() { var el = new XElement("test", "foo"); XMLUtilities.set_element(el, "bar", "&&"); string bar = XMLUtilities.test_element(el, "bar"); Assert.That(bar == "&&"); }
public void RoslynAnalyzerRulesetFiles_WillBeIncluded() { var roslynAnalyzerRuleSetPath = "Assets/RoslynRuleSet.ruleset"; m_Builder.WithAssemblyData(files: new[] { "file.cs" }, roslynAnalyzerRulesetPath: roslynAnalyzerRuleSetPath).Build().Sync(); var csProjectFileContents = m_Builder.ReadProjectFile(m_Builder.Assembly); XmlDocument csProjectXmlFile = XMLUtilities.FromText(csProjectFileContents); XMLUtilities.AssertAnalyzerRuleSetsMatchExactly(csProjectXmlFile, roslynAnalyzerRuleSetPath); }
protected string test_element(string element_name) { /* * if (this[element_name] == null) return ""; * if (this[element_name].FirstChild == null) return ""; * if (this[element_name].FirstChild.GetType() != Type.GetType("TextNode")) return ""; * return this[element_name].InnerText; * */ return(XMLUtilities.test_element(this, element_name)); }
/// <summary> /// Create record in key value data store /// </summary> /// <param name="key"></param> /// <param name="value"></param> public void Create(string key, string value) { if (FileUtilities.IsFileSizeLessThanOneGB(FWConstant.DataStoreFile)) { XMLUtilities <DataStore> xmlUtilities = new XMLUtilities <DataStore>(); var dataStore = xmlUtilities.DeSerialize(FWConstant.DataStoreFile); if (DataStoreUtilities.IsValidKey(key)) { if (!DataStoreUtilities.IsKeyExists(key, dataStore)) { if (DataStoreUtilities.IsJson(value)) { if (DataStoreUtilities.CheckSize(value)) { if (dataStore.Records != null) { dataStore.Records.Add(new Record { Key = key, Value = value }); } else { dataStore.Records = new List <Record> { new Record { Key = key, Value = value } } }; xmlUtilities.Serialize(dataStore, FWConstant.DataStoreFile); } else { throw new Exception("Size of data exceeds the limit of data store"); } } else { throw new Exception("Invalid json content"); } } else { throw new Exception("Key already Exists"); } } else { throw new Exception("Key size should not exceed 32 characters"); } } else { throw new Exception("Datastore size exceeds 1 GB"); } }
//エディタエリアにファイルを表示する private void SetToSourceEditor(string sourceFile) { fileLabel.Content = "file:" + epubFile; //ファイル名をラベルに書き込む var enc = XMLUtilities.GetEncodingFormat(sourceFile); //エンコードを取得する string str = File.ReadAllText(sourceFile, enc); //ファイルを読み込む orgSource = str; //変更前ソースとして保持する sourceEditor.Text = str; //エディタに表示する targetSource = sourceFile; //変更先として保存する }
public void RoslynAnalyzerDlls_WillBeIncluded() { var roslynAnalyzerDllPath = "Assets\\RoslynAnalyzer.dll"; var synchronizer = m_Builder.WithRoslynAnalyzers(new[] { roslynAnalyzerDllPath }).Build(); synchronizer.Sync(); string projectFile = m_Builder.ReadProjectFile(m_Builder.Assembly); XmlDocument projectFileXml = XMLUtilities.FromText(projectFile); XMLUtilities.AssertAnalyzerItemsMatchExactly(projectFileXml, new[] { MakeAbsolutePath(roslynAnalyzerDllPath).NormalizePath() }); }
public void AbsoluteSourceFilePaths_WillBeMadeRelativeToProjectDirectory() { var absoluteFilePath = MakeAbsolutePath("dimmer.cs"); var synchronizer = m_Builder.WithAssemblyData(files: new[] { absoluteFilePath }).Build(); synchronizer.Sync(); var csprojContent = m_Builder.ReadProjectFile(m_Builder.Assembly); XmlDocument scriptProject = XMLUtilities.FromText(csprojContent); XMLUtilities.AssertCompileItemsMatchExactly(scriptProject, new[] { "dimmer.cs" }); }
public void BuiltinSupportedExtensions_InsideAssemblySourceFiles_WillBeAddedToCompileItems(string fileExtension) { var compileItem = new[] { "file.cs", $"anotherFile.{fileExtension}" }; var synchronizer = m_Builder.WithAssemblyData(files: compileItem).Build(); synchronizer.Sync(); var csprojContent = m_Builder.ReadProjectFile(m_Builder.Assembly); XmlDocument scriptProject = XMLUtilities.FromText(csprojContent); XMLUtilities.AssertCompileItemsMatchExactly(scriptProject, compileItem); }
public void NoExtension_IsNotValid() { var validFile = "dimmer.cs"; var invalidFile = "foo"; var file = new[] { validFile, invalidFile }; var synchronizer = m_Builder.WithAssemblyData(files: file).Build(); synchronizer.Sync(); var csprojContent = m_Builder.ReadProjectFile(m_Builder.Assembly); XmlDocument scriptProject = XMLUtilities.FromText(csprojContent); XMLUtilities.AssertCompileItemsMatchExactly(scriptProject, new[] { validFile }); }
public void UnsupportedExtension_IsOverWrittenBy_UserSupportedExtensions() { var unsupported = new[] { "file.unsupported" }; var synchronizer = m_Builder .WithAssetFiles(unsupported) .AssignFilesToAssembly(unsupported, m_Builder.Assembly) .WithUserSupportedExtensions(new[] { "unsupported" }) .Build(); synchronizer.Sync(); var xmlDocument = XMLUtilities.FromText(m_Builder.ReadProjectFile(m_Builder.Assembly)); XMLUtilities.AssertNonCompileItemsMatchExactly(xmlDocument, unsupported); }
/// <summary> /// Used to read the JSON data from datastore using key /// </summary> /// <param name="key"></param> /// <returns></returns> public string Read(string key) { XMLUtilities <DataStore> xmlUtilities = new XMLUtilities <DataStore>(); var dataStore = xmlUtilities.DeSerialize(FWConstant.DataStoreFile); if (DataStoreUtilities.IsKeyExists(key, dataStore)) { return(dataStore.Records.FirstOrDefault(item => item.Key == key).Value); } else { throw new Exception("Invalid key"); } }
public void FullPathAsset_WillBeConvertedToRelativeFromProjectDirectory() { var assetPath = "Assets/Asset.cs"; var synchronizer = m_Builder .WithAssemblyData(files: new[] { MakeAbsolutePath(assetPath) }) .Build(); synchronizer.Sync(); var csprojectContent = m_Builder.ReadProjectFile(m_Builder.Assembly); var xmlDocument = XMLUtilities.FromText(csprojectContent); XMLUtilities.AssertCompileItemsMatchExactly(xmlDocument, new[] { assetPath }); }
public void MultipleSourceFiles_WillAllBeAdded() { var files = new[] { "fileA.cs", "fileB.cs", "fileC.cs" }; var synchronizer = m_Builder .WithAssemblyData(files: files) .Build(); synchronizer.Sync(); var csprojectContent = m_Builder.ReadProjectFile(m_Builder.Assembly); var xmlDocument = XMLUtilities.FromText(csprojectContent); XMLUtilities.AssertCompileItemsMatchExactly(xmlDocument, files); }
public void InInternalizedPackage_WithoutGenerateAll_WillNotBeAddedToNonInclude() { var nonCompileItem = "packageAsset.shader"; var nonCompileItems = new[] { nonCompileItem }; var synchronizer = m_Builder .WithAssetFiles(nonCompileItems) .AssignFilesToAssembly(nonCompileItems, m_Builder.Assembly) .WithPackageAsset(nonCompileItem, true) .Build(); synchronizer.Sync(); var xmlDocument = XMLUtilities.FromText(m_Builder.ReadProjectFile(m_Builder.Assembly)); XMLUtilities.AssertNonCompileItemsMatchExactly(xmlDocument, new string[0]); }
/// <summary> /// Delete the record from data store using key /// </summary> /// <param name="key"></param> public void Delete(string key) { XMLUtilities <DataStore> xmlUtilities = new XMLUtilities <DataStore>(); var dataStore = xmlUtilities.DeSerialize(FWConstant.DataStoreFile); if (DataStoreUtilities.IsKeyExists(key, dataStore)) { dataStore.Records.Remove(dataStore.Records.FirstOrDefault(item => item.Key == key)); xmlUtilities.Serialize(dataStore, FWConstant.DataStoreFile); } else { throw new Exception("Invalid key"); } }
public void DllInSourceFiles_WillBeAddedAsReference() { var referenceDll = "reference.dll"; var synchronizer = m_Builder .WithAssemblyData(files: new[] { "file.cs", referenceDll }) .Build(); synchronizer.Sync(); var csprojFileContents = m_Builder.ReadProjectFile(m_Builder.Assembly); XmlDocument scriptProject = XMLUtilities.FromText(csprojFileContents); XMLUtilities.AssertCompileItemsMatchExactly(scriptProject, new[] { "file.cs" }); XMLUtilities.AssertNonCompileItemsMatchExactly(scriptProject, new string[0]); Assert.That(csprojFileContents, Does.Match($"<Reference Include=\"reference\">\\W*<HintPath>{Regex.Escape(Path.Combine(SynchronizerBuilder.projectDirectory,referenceDll))}\\W*</HintPath>\\W*</Reference>")); }
public void BuiltinSupportedExtensions_InsideAssetFolder_WillBeAddedToNonCompileItems(string fileExtension) { var nonCompileItem = new[] { $"anotherFile.{fileExtension}" }; var synchronizer = m_Builder .WithAssetFiles(files: nonCompileItem) .AssignFilesToAssembly(nonCompileItem, m_Builder.Assembly) .Build(); synchronizer.Sync(); var csprojContent = m_Builder.ReadProjectFile(m_Builder.Assembly); XmlDocument scriptProject = XMLUtilities.FromText(csprojContent); XMLUtilities.AssertCompileItemsMatchExactly(scriptProject, m_Builder.Assembly.sourceFiles); XMLUtilities.AssertNonCompileItemsMatchExactly(scriptProject, nonCompileItem); }
public void UnsupportedExtensions_WillNotBeAdded() { var unsupported = new[] { "file.unsupported" }; var synchronizer = m_Builder .WithAssetFiles(unsupported) .AssignFilesToAssembly(unsupported, m_Builder.Assembly) .Build(); synchronizer.Sync(); var csprojectContent = m_Builder.ReadProjectFile(m_Builder.Assembly); var xmlDocument = XMLUtilities.FromText(csprojectContent); XMLUtilities.AssertCompileItemsMatchExactly(xmlDocument, m_Builder.Assembly.sourceFiles); XMLUtilities.AssertNonCompileItemsMatchExactly(xmlDocument, new string[0]); }