/// <summary> /// This function generates Script as per Selected Language and Writes to File /// </summary> /// <param name="conversionList"></param> /// <param name="exportItem"></param> /// <param name="namespaceName"></param> /// <param name="fileName"></param> /// <returns>Returns bool</returns> public bool GenerateScriptAsPerSelectedLanguage(List<PocoObjectListForExport> conversionList, PocoObjectListForExport exportItem, string namespaceName, string fileName) { LanguageSelector.GetLanguageType(out _isVb, out _isJava, out _isCSharp, out _isRuby); try { using (var sw = new StreamWriter(fileName)) { _pocoScript = _isVb ? _vbWriter.Writer(conversionList, exportItem, namespaceName) : _csharpWriter.Writer(conversionList, exportItem, namespaceName); sw.WriteLine(_pocoScript); _isSaved = true; } } catch (IOException ) { _isSaved = false; return _isSaved; } return _isSaved; }
public void Generate_List_For_CreateColumnFamilyMetdata_UnitTest() { const string parents = "test"; var child=new ColumnFamilyName {Columnfamilyname = "account", Ischecked = true}; var metadata = new ColumnFamilyMetadata { ColumnName = "id", Columnfamilyname = "user", Type = null, Validator = "utf8type" }; child.ChildMetadata.Add(metadata); var exportList = new List<PocoObjectListForExport>(); var parent = new PocoObjectListForExport {NamespaceName = "test", ClassName = "account"}; var firstChild = new PocoListofObjects {Type = "string", ColumnFamilyName = "id"}; parent.PocoListObjects.Add(firstChild); exportList.Add(parent); var expected = exportList; var actual = Reader.GenerateListForColumnFamilyMetdata(parents, child); Assert.IsNotNull(actual); Assert.IsTrue(actual.Count > 0); Assert.AreEqual(expected[0].ClassName, actual[0].ClassName); Assert.AreEqual(expected[0].NamespaceName, actual[0].NamespaceName); Assert.IsTrue(actual[0].PocoListObjects.Count > 0); for (var i = 0; i < actual[0].PocoListObjects.Count; i++) { Assert.AreEqual(expected[0].PocoListObjects[i].Type, actual[0].PocoListObjects[i].Type); Assert.AreEqual(expected[0].PocoListObjects[i].ColumnFamilyName, actual[0].PocoListObjects[i].ColumnFamilyName); } }
/// <summary> /// Convert Fetched Data to List format. /// </summary> /// <param name="nmspcenameName"></param> /// <param name="columnFamilyName"></param> /// <param name="keyDataType"></param> /// <param name="columnsAndDataType"></param> /// <param name="isCqlScript"></param> /// <returns>Returns List</returns> public static PocoObjectListForExport ConvertGeneratedMetaDataToListFormat(string nmspcenameName,string columnFamilyName,string keyDataType, Dictionary<string,string> columnsAndDataType, bool isCqlScript) { _initializeMappings = new Mapper(); _initializeMappings.InitializeDataTypeMappings(); var pocoChildList = new List<PocoListofObjects>(); var exportPocoItem = new PocoObjectListForExport { ClassName = columnFamilyName, NamespaceName = String.IsNullOrEmpty(nmspcenameName) ? KeyspaceName : nmspcenameName }; foreach (var columnName in columnsAndDataType.Keys) { var pocoChildItem = new PocoListofObjects { ColumnFamilyName = columnName, Type = isCqlScript ? _initializeMappings.DataTypes[String.Concat(columnsAndDataType[columnName], "type")] : _initializeMappings.DataTypes[columnsAndDataType[columnName]] }; pocoChildList.Add(pocoChildItem); } exportPocoItem.PocoListObjects = pocoChildList; return exportPocoItem; }
public void Convert_Fetched_Data_To_Export_Format_In_PocoToDB() { const string keyspaceName = "test"; const string columnFamilyName = "account"; var pocoChildList = new List<PocoListofObjects>(); var pocoChildItem = new PocoListofObjects {Type = "string"}; pocoChildItem.Type = "name"; pocoChildList.Add(pocoChildItem); var exportPocoItem=new PocoObjectListForExport { NamespaceName = "test", ClassName = "account", PocoListObjects = pocoChildList }; var expected = exportPocoItem; var actual = LangParser.ConvertFetchedDataToExportFormatInPocoToDb(keyspaceName, columnFamilyName, pocoChildList); Assert.AreEqual(expected.NamespaceName, actual.NamespaceName); Assert.AreEqual(expected.ClassName, actual.ClassName); Assert.IsNotNull(actual); Assert.IsTrue(actual.PocoListObjects.Count > 0); for (var i = 0; i < actual.PocoListObjects.Count; i++) { Assert.AreEqual(expected.PocoListObjects[i].Type, actual.PocoListObjects[i].Type); Assert.AreEqual(expected.PocoListObjects[i].ColumnFamilyName, actual.PocoListObjects[i].ColumnFamilyName); } }
public void Check_Available_ColumnFamilyNames_If_Not_Available_UnitTest() { //Checking if the specified columnFamilyName exists in database keyspaces. (Not Available) const bool expected = true; var parentItem = new PocoObjectListForExport {NamespaceName = "test", ClassName = "TestNotAvailable"}; var actual = _conn.CheckAvailableColumnFamilyNames(parentItem); Assert.AreEqual(expected, actual); }
public void Check_Available_KeyspaceName_If_Not_Available_UnitTest() { //Checking if the specified keyspace exists in database keyspaces. (Not Available) const bool expected = false; var keyspaceCollection = _conn.FetchKeyspacesfromCluster(); var parentItem = new PocoObjectListForExport {NamespaceName = "ManageTestClass"}; var actual = _conn.CheckAvailableKeyspaceName(keyspaceCollection, parentItem); Assert.AreEqual(expected, actual); }
/// <summary> /// This function Converts fetched Data as List Item /// </summary> /// <param name="keyspaceName"></param> /// <param name="columnFamilyName"></param> /// <param name="pocoChildList"></param> /// <returns>Returns List Item</returns> public static PocoObjectListForExport ConvertFetchedDataToExportFormatInPocoToDb(string keyspaceName, string columnFamilyName, List<PocoListofObjects> pocoChildList) { var exportPocoItem = new PocoObjectListForExport { ClassName = columnFamilyName, NamespaceName = keyspaceName, PocoListObjects = pocoChildList }; return exportPocoItem; }
public void Read_Per_Script_From_ExportList_UnitTest() { ScriptReader.ReinitializeExportList(); var parent = new PocoObjectListForExport {NamespaceName = "test", ClassName = "account"}; var child = new PocoListofObjects {Type = "string", ColumnFamilyName = "UserName"}; parent.PocoListObjects.Add(child); const string expected = "create table test.account\r\n(\r\nUserName string,\r\nPRIMARY KEY(UserName) \n)\r\n"; var actual = Reader.ReadPerScriptFromExportList(parent); Assert.AreEqual(expected, actual); }
public void GenerateSummary_If_List_Provided() { const string expected = "Total Number of keyspaces : 1\r\n\r\nKeyspace Name : test\r\nColumnFamily Count : 1\r\nColumnFamily Name : CreateTestClass\r\n\r\n"; var exportList = new List<PocoObjectListForExport>(); var exportItem = new PocoObjectListForExport {NamespaceName = "test", ClassName = "CreateTestClass"}; var pocoObjItem = new PocoListofObjects {Type = "varchar", ColumnFamilyName = "idname"}; exportItem.PocoListObjects.Add(pocoObjItem); exportList.Add(exportItem); ScriptReader.ReinitializeExportList(); var actual = ListSummary.GenerateSummary(exportList); Assert.AreEqual(expected,actual); }
/// <summary> /// This function read data per keyspace. /// </summary> /// <param name="parentItem"></param> /// <returns>Returns script created per keyspace</returns> public static string ReadPerScriptFromExportList(PocoObjectListForExport parentItem) { var stringBuilder = new StringBuilder(); var columnFamilyName = parentItem.PocoListObjects[0].ColumnFamilyName; stringBuilder.AppendLine("create table " + parentItem.NamespaceName + "." + parentItem.ClassName); stringBuilder.AppendLine("("); foreach (var childItem in parentItem.PocoListObjects) stringBuilder.AppendLine(childItem.ColumnFamilyName + " " + childItem.Type + ","); stringBuilder.Append("PRIMARY KEY(" + columnFamilyName + ") \n"); stringBuilder.AppendLine(")"); return stringBuilder.ToString(); }
/// <summary> /// This function generates Per Object CQL Script /// </summary> /// <param name="parentItem"></param> /// <param name="key"></param> /// <returns>Returns CQL Script</returns> private static string ExtractPerScriptFromExportList(PocoObjectListForExport parentItem, string key) { if (key == null) throw new ArgumentNullException("key"); var stringBuilder = new StringBuilder(); key = parentItem.PocoListObjects[0].ColumnFamilyName; stringBuilder.AppendLine("create table " + parentItem.NamespaceName + "." + parentItem.ClassName); stringBuilder.AppendLine("("); foreach (var childItem in parentItem.PocoListObjects) stringBuilder.AppendLine(childItem.ColumnFamilyName + " " + childItem.Type + ","); stringBuilder.Append("PRIMARY KEY(" + key + ") \n"); stringBuilder.AppendLine(")"); return stringBuilder.ToString(); }
public void ConvertListToVbScriptUnitTestForSingleFile() { var exportPocoList = new List<PocoObjectListForExport>(); var exportItem = new PocoObjectListForExport(); const string namespaceName = "test"; exportItem.NamespaceName = namespaceName; exportItem.ClassName = "CreateTestClass"; var pocoObjItem = new PocoListofObjects {Type = "varchar", ColumnFamilyName = "idname"}; exportItem.PocoListObjects.Add(pocoObjItem); exportPocoList.Add(exportItem); const string expected = "Imports System\r\nNamespace test\r\n\r\n\r\nPublic Class CreateTestClass\r\n\r\nPublic Property varchar As idname\r\n\r\nEnd Class\r\n\r\n\r\nEnd Namespace\r\n"; var actual = _vbWriter.Writer(exportPocoList, null, namespaceName); Assert.AreEqual(expected, actual); }
/// <summary> /// This function checks specified ColumnFamily Name is Available for specified keyspace in Cassandra DB /// </summary> /// <param name="parentItem"></param> /// <returns>Returns bool</returns> public bool CheckAvailableColumnFamilyNames(PocoObjectListForExport parentItem) { var columnFamilyNames = PopulateColumnfamilynames(parentItem.NamespaceName); return columnFamilyNames.All(childItem => childItem.Columnfamilyname != parentItem.ClassName); //foreach (var childItem in columnFamilyNames) //{ // if (childItem.Columnfamilyname == parentItem.ClassName) // { // flagchild = false; break; // } //} //return flagchild; }
public void ConvertListToCSharpScriptUnitTestForSingleFileOption() { var exportPocoList = new List<PocoObjectListForExport>() ; var exportItem=new PocoObjectListForExport(); const string namespaceName = "test"; exportItem.NamespaceName = namespaceName; exportItem.ClassName = "CreateTestClass"; var pocoObjItem = new PocoListofObjects {Type = "varchar", ColumnFamilyName = "idname"}; exportItem.PocoListObjects.Add(pocoObjItem); exportPocoList.Add(exportItem); const string expected = "using System\r\nnamespace test\r\n{\r\npublic class CreateTestClass\r\n{\r\npublic varchar idname { get; set; } \n}\r\n\r\n\r\n}\r\n"; var actual = _csharpLang.Writer(exportPocoList, null, namespaceName); Assert.AreEqual(expected,actual); }
/// <summary> /// Generates Writer functionality Per Object /// </summary> /// <param name="parentItem"></param> /// <returns>Returns VB Script</returns> private static string SaveAsFileOptionPerObject(PocoObjectListForExport parentItem) { var stringBuilder = new StringBuilder(); stringBuilder.AppendLine(); stringBuilder.AppendLine("Public Class " + parentItem.ClassName); stringBuilder.AppendLine(); foreach(var childItem in parentItem.PocoListObjects) { stringBuilder.AppendFormat("Public Property " + childItem.Type + " As " + childItem.ColumnFamilyName); stringBuilder.AppendLine(); } stringBuilder.AppendLine(); stringBuilder.AppendLine("End Class"); return stringBuilder.ToString(); }
/// <summary> /// This function generates Script Per Object. /// </summary> /// <param name="parentItem"></param> /// <returns>Returns Class Data As String</returns> private static string SaveAsFileOptionPerObject(PocoObjectListForExport parentItem) { var stringBuilder = new StringBuilder(); const string getsetProp = "{ get; set; } "; stringBuilder.AppendLine("public class " + parentItem.ClassName); stringBuilder.AppendLine("{"); foreach (var childItem in parentItem.PocoListObjects) { stringBuilder.AppendFormat("public " + childItem.Type + " " + childItem.ColumnFamilyName); stringBuilder.Append(" " + getsetProp + "\n"); } stringBuilder.AppendLine("}"); return stringBuilder.ToString(); }
public void CreateDbScriptFromList() { var pocoChildList = new List<PocoListofObjects>(); var pocoChildItem = new PocoListofObjects {Type = "string"}; pocoChildItem.Type = "name"; pocoChildList.Add(pocoChildItem); var exportList = new List<PocoObjectListForExport>(); var exportPocoItem = new PocoObjectListForExport { NamespaceName = "test", ClassName = "account", PocoListObjects = pocoChildList }; exportList.Add(exportPocoItem); const string expected = "create table test.account\r\n(\r\n name,\r\nPRIMARY KEY() \n)\r\n\r\n"; var actual = LangParser.CreateCqlScriptFromList(exportList); Assert.AreEqual(expected, actual); }
/// <summary> /// This function implements writer functionality VB Script generation. /// </summary> /// <param name="exportPocoList"></param> /// <param name="exportItem"></param> /// <param name="namespaceName"></param> /// <returns>Return VB Script</returns> public string Writer(List<PocoObjectListForExport> exportPocoList, PocoObjectListForExport exportItem, string namespaceName) { var stringBuilder = new StringBuilder(); stringBuilder.AppendLine("Imports System"); stringBuilder.AppendLine("Namespace " + namespaceName); stringBuilder.AppendLine(""); if (exportItem == null) { foreach (var parentItem in exportPocoList) { stringBuilder.AppendLine(SaveAsFileOptionPerObject(parentItem)); stringBuilder.AppendLine(); } } else stringBuilder.AppendLine(SaveAsFileOptionPerObject(exportItem)); stringBuilder.AppendLine("End Namespace"); var pocoScript = stringBuilder.ToString(); return pocoScript; }
/// <summary> /// This function Assign the Values to the Summary Object. /// </summary> /// <param name="pocoObjectList"></param> /// <returns>Returns Object Of Summary Details</returns> private static SummaryDetails AssignValuesToSummary(IEnumerable<PocoObjectListForExport> pocoObjectList) { var initializeSummaryDetails = new SummaryDetails(); var keyspacesInfo = new List<KeySpaceDetails>(); KeySpaceDetails keyspaceObject = null; List<PocoObjectListForExport> columnfamilyDetails = null; var namespce = string.Empty; var keyspaceCount = 0; foreach (var parentItem in pocoObjectList) { if (!parentItem.NamespaceName.Equals(namespce)) { keyspaceObject = new KeySpaceDetails(); columnfamilyDetails = new List<PocoObjectListForExport>(); namespce = parentItem.NamespaceName; keyspaceObject.KeyspaceName = parentItem.NamespaceName; keyspaceCount = keyspaceCount + 1; } var columnfamilyObject = new PocoObjectListForExport {ClassName = parentItem.ClassName}; if (columnfamilyDetails != null) { columnfamilyDetails.Add(columnfamilyObject); keyspaceObject.ColumnFamilyDetails = columnfamilyDetails; } if (keyspaceObject != null) { keyspaceObject.ColumnfamilyCount = keyspaceObject.ColumnFamilyDetails.Count; keyspacesInfo.Add(keyspaceObject); } } initializeSummaryDetails.KeyspaceCount = keyspaceCount; initializeSummaryDetails.KeyspaceDetails = keyspacesInfo; return initializeSummaryDetails; }
/// <summary> /// This function checks the specified keyspace exists in Cassandra DB /// </summary> /// <param name="keyspaceCollection"></param> /// <param name="parentItem"></param> /// <returns>Returns bool</returns> public bool CheckAvailableKeyspaceName(List<TableNames> keyspaceCollection, PocoObjectListForExport parentItem) { return keyspaceCollection.Any(t => parentItem.NamespaceName == t.Keyspacename); }
/// <summary> /// This function writes Scripts As Per Selected Script Type /// </summary> /// <param name="exportPocoList"></param> /// <param name="exportItem"></param> /// <param name="fileName"></param> /// <param name="namespaceName"></param> /// <returns>Returns the Writer Work is Finished and Saved as bool<POCOObjectListForExport/></returns> public bool WriteScriptAsPerSelectedLanguage(List<PocoObjectListForExport> exportPocoList, PocoObjectListForExport exportItem, string namespaceName, string fileName) { return _writer.GenerateScriptAsPerSelectedLanguage(exportPocoList, exportItem, namespaceName, fileName); }
/// <summary> /// This function creates List by Appending Metadata. /// </summary> /// <param name="parent"></param> /// <param name="pocoObjectsMetadataDetails"></param> /// <returns>Return List</returns> private static List<PocoObjectListForExport> AppendCSharpPocoClassMetadata(string parent, PocoObjectsMetadata pocoObjectsMetadataDetails) { var exportPocoList = new List<PocoObjectListForExport>(); _initializeMappings = new Mapper(); _initializeMappings.InitializeDataTypeMappings(); var listitem = new PocoObjectListForExport {ClassName = pocoObjectsMetadataDetails.ClassName}; foreach (var detail in pocoObjectsMetadataDetails.PropertyDetail) { listitem.NamespaceName = parent; listitem.PocoListObjects.Add(new PocoListofObjects { ColumnFamilyName = detail.Key, Type = _initializeMappings.DataTypes[detail.Value] }); } exportPocoList.Add(listitem); return exportPocoList; }