public void CreateCatalog() { var connectionString = "Filename=./sqlite.db; Mode=ReadWriteCreate"; var catalog = new CatalogDefinition("test_db"); var schema = catalog.AddSchema(_schemaName); var table = schema.AddTable("Test"); var colPk = table.AddColumn("TestId", DbType.Int64); colPk.IsPrimaryKey = true; var colName = table.AddColumn("Name", DbType.String); colName.MaxLength = 256; colName.IsNullable = false; var builder = new SqliteScriptBuilder(); var sql = builder.BuildCreateScript(catalog); IParameterFactory parameterFactory = new SqliteParameterFactory(); IConnectionFactory connectionFactory = new SqliteConnectionFactory(); using (var connection = connectionFactory.Open(connectionString)) using (var command = new Command(connection, parameterFactory)) { var affected = command.Execute(sql); //Assert.IsNotNull(dataSet); //Assert.AreEqual(1, dataSet.Tables.Count); //Assert.IsTrue(dataSet.Tables[0].Rows.Count > 0); } }
private void ReadSheet(CatalogDefinition catalogDefinition, string sheetName) { _logger.LogInformation($"Reading sheet {sheetName}"); var sheet = _workbook.GetSheet(sheetName); if (sheet == null) { return; } ColumnDefinition clave = catalogDefinition.Columns .OrderBy(p => p.Index) .FirstOrDefault(); int records = 0; for (int rowIndex = 0; rowIndex <= sheet.LastRowNum; rowIndex++) { try { var row = sheet.GetRow(rowIndex); if (row == null) { continue; } var tempCellValue = row.GetCell(0)?.ToString(); if (!_startProcess && tempCellValue?.ToUpper() == clave?.Name?.ToUpper()) { _startProcess = true; continue; } if (_startProcess && catalogDefinition.ExcludedValues.All(p => p as string != tempCellValue)) { var jtoken = _catalogJsonConverter.WriteJson(row, catalogDefinition); if (jtoken != null) { var message = new Message { RecordIndex = records, Type = catalogDefinition.EntityName ?? catalogDefinition.SheetName, JToken = jtoken }; _logger.LogDebug($"Sending message {rowIndex} of type {message.Type} to bufferBlock", message); _targetBlock.Post(message); records++; } } } catch (Exception e) { _logger.LogDebug(e, "Error al convertir a json", rowIndex); } } _logger.LogInformation($"Founded records {sheet.SheetName}: {records}"); }
public CatalogDefinition CreateCatalog(string name) { CatalogDefinition catalog = new CatalogDefinition { Name = name }; return(Repository.Save(catalog)); }
public CatalogDefinition RenameCatalog(string catalogCuid, string name) { CatalogDefinition catalog = Repository.Query <CatalogDefinition>(new { Cuid = catalogCuid }).FirstOrDefault(); Args.ThrowIf(catalog == null, "Catalog ({0}) was not found", catalogCuid); catalog.Name = name; return(Repository.Save(catalog)); }
public void CanGetCatalogByCuid() { string catalogName = "Test Catalog To Find ".RandomLetters(10); CatalogService svc = _serviceRegistry.Get <CatalogService>(); CatalogDefinition catalog = svc.CreateCatalog(catalogName); CatalogDefinition gotCatalog = svc.GetCatalog(catalog.Cuid); Expect.IsNotNull(gotCatalog, "catalog was null"); Expect.AreEqual(catalogName, gotCatalog.Name); }
public void CanCreateCatalog() { string catalogName = "Test Catalog Name ".RandomLetters(8); CatalogService svc = _serviceRegistry.Get <CatalogService>(); CatalogDefinition catalog = svc.CreateCatalog(catalogName); Expect.IsNotNull(catalog, "catalog was null"); Expect.AreEqual(catalogName, catalog.Name); Expect.IsNotNullOrEmpty(catalog.Cuid, "cuid was not set"); }
public void CanAddItemToCatalog() { string itemName = "Test AddItem ".RandomLetters(6); CatalogService svc = _serviceRegistry.Get <CatalogService>(); CatalogDefinition catalog = svc.CreateCatalog(5.RandomLetters()); ItemDefinition item = svc.CreateItem(6.RandomLetters()); svc.AddItem(catalog.Cuid, item.Cuid); catalog = svc.GetCatalog(catalog.Cuid); Expect.IsTrue(catalog.Items.Select(i => i.Cuid.Equals(item.Cuid)).Count() == 1); }
public void CanCreateCatalog() { CatalogService svc = GetTestCatalogService(nameof(CanCreateCatalog), out DaoRepository ignore); string testCatalogName = "TestCatalog"; CatalogDefinition catalogDefinition = svc.CreateCatalog(testCatalogName); Expect.IsNotNull(catalogDefinition); Expect.IsGreaterThan(catalogDefinition.Id, 0); Expect.IsGreaterThan(catalogDefinition.Key, 0); }
public void CanFindCatalog() { string testCatalogName = $"{nameof(CanFindCatalog)}_TestCatalog"; CatalogService svc = GetTestCatalogService(testCatalogName, nameof(CanFindCatalog)); CatalogDefinition retrieved = svc.FindCatalog(testCatalogName); Expect.IsNotNull(retrieved); Expect.AreEqual(testCatalogName, retrieved.Name); Expect.AreEqual(svc.ServerOrganization.Key, retrieved.OrganizationKey); Expect.AreEqual(svc.ServerApplication.Key, retrieved.ApplicationKey); }
public void CanRenameCatalog() { string catalogName = "Test Catalog To Find ".RandomLetters(10); string renamedName = "Renamed Test Catalog ".RandomLetters(10); CatalogService svc = _serviceRegistry.Get <CatalogService>(); CatalogDefinition catalog = svc.CreateCatalog(catalogName); Expect.AreEqual(catalogName, catalog.Name); svc.RenameCatalog(catalog.Cuid, renamedName); catalog = svc.GetCatalog(catalog.Cuid); Expect.AreEqual(renamedName, catalog.Name); }
private CatalogService GetTestCatalogService(string testCatalogToCreate, string databaseName = "testDatabaseName") { CatalogService svc = GetTestCatalogService(databaseName, out DaoRepository daoRepository); CatalogDefinition catalogDefinition = new CatalogDefinition() { Name = testCatalogToCreate, OrganizationKey = svc.ServerOrganization.Key, ApplicationKey = svc.ServerApplication.Key }; catalogDefinition.SaveByKey <CatalogDefinition>(daoRepository); return(svc); }
public CatalogDefinition GetCatalog(string catalogCuid) { CatalogDefinition catalog = Repository.Query <CatalogDefinition>(new { Cuid = catalogCuid }).FirstOrDefault(); if (catalog != null) { catalog = Repository.Retrieve <CatalogDefinition>(catalog.Uuid); catalog.Items = GetCatalogItems(catalog.Cuid).ToList(); return(catalog); } return(null); }
public void CanAddItemToCatalog() { string testCatalogName = nameof(CanAddItemToCatalog); string testItemName = "testItem_".RandomLetters(6); CatalogService svc = GetTestCatalogService(testCatalogName); CatalogDefinition catalogDefinition = svc.FindCatalog(testCatalogName); ItemDefinition item = svc.AddItem(catalogDefinition, testItemName); catalogDefinition = svc.GetCatalog(catalogDefinition.Key); Expect.AreEqual(1, catalogDefinition.Items.Count); Expect.AreEqual(testItemName, catalogDefinition.Items[0].Name); }
public void CanGetItem() { string itemName = "Test RenameItem ".RandomLetters(8); string newName = "New Name ".RandomLetters(8); CatalogService svc = _serviceRegistry.Get <CatalogService>(); CatalogDefinition catalog = svc.CreateCatalog(5.RandomLetters()); ItemDefinition item = svc.CreateItem(itemName); ItemDefinition gotItem = svc.GetItem(item.Cuid); Expect.IsNotNull(gotItem); Expect.AreEqual(item.Cuid, gotItem.Cuid); Expect.AreEqual(item.Name, gotItem.Name); }
public void CanDeleteItem() { string itemName = "Test RenameItem ".RandomLetters(8); string newName = "New Name ".RandomLetters(8); CatalogService svc = _serviceRegistry.Get <CatalogService>(); CatalogDefinition catalog = svc.CreateCatalog(5.RandomLetters()); ItemDefinition item = svc.CreateItem(itemName); svc.DeleteItem(item.Cuid); ItemDefinition shouldBeNull = svc.GetItem(item.Cuid); Expect.IsNull(shouldBeNull); }
public void CanAddItemProperties() { string testCatalogName = nameof(CanAddItemProperties); string testItemName = "testItem_".RandomLetters(6); CatalogService svc = GetTestCatalogService(testCatalogName); CatalogDefinition catalogDefinition = svc.FindCatalog(testCatalogName); ItemDefinition item = svc.AddItem(catalogDefinition, testItemName); List <ItemProperty> properties = svc.AddItemProperties(item, new { TailCount = 5, FallopianTubes = true }).ToList(); Expect.AreEqual(2, properties.Count); Expect.AreEqual("5", properties.First(p => p.Name.Equals("TailCount")).Value); Expect.AreEqual("True", properties.First(p => p.Name.Equals("FallopianTubes")).Value); }
public void CanDeleteCatalog() { string testCatalogName = nameof(CanDeleteCatalog); CatalogService svc = GetTestCatalogService(testCatalogName); CatalogDefinition catalogDefinition = svc.FindCatalog(testCatalogName); Expect.IsNotNull(catalogDefinition); svc.DeleteCatalog(catalogDefinition); catalogDefinition = svc.FindCatalog(testCatalogName); Expect.IsNull(catalogDefinition); }
public void ShouldFindItemCatalogs() { string itemName = "Test RenameItem ".RandomLetters(8); string newName = "New Name ".RandomLetters(8); CatalogService svc = _serviceRegistry.Get <CatalogService>(); CatalogDefinition catalog = svc.CreateCatalog(5.RandomLetters()); CatalogDefinition catalog2 = svc.CreateCatalog(6.RandomLetters()); ItemDefinition item = svc.CreateItem(itemName); svc.AddItem(catalog.Cuid, item.Cuid); svc.AddItem(catalog2.Cuid, item.Cuid); string[] catalogCuids = svc.FindItemCatalogs(item.Cuid); Expect.AreEqual(2, catalogCuids.Length); }
public void CanSaveByKey() { CatalogService svc = GetTestCatalogService(nameof(CanSaveByKey), out DaoRepository daoRepository); string testCatalogName = $"{nameof(CanFindCatalog)}_TestCatalog"; CatalogDefinition catalogDefinition = new CatalogDefinition() { Name = testCatalogName, OrganizationKey = svc.ServerOrganization.Key, ApplicationKey = svc.ServerApplication.Key }; ulong key = catalogDefinition.Key; CatalogDefinition saved = catalogDefinition.SaveByKey <CatalogDefinition>(daoRepository); Expect.IsNotNull(saved); Expect.AreEqual(key, saved.Key); }
public ItemDefinition AddItem(string catalogCuid, string itemCuid) { CatalogDefinition catalog = GetCatalog(catalogCuid); Args.ThrowIf(catalog == null, "Catalog not found ({0})", catalogCuid); ItemDefinition item = GetItem(itemCuid); Args.ThrowIf(item == null, "Item not found ({0})", itemCuid); CatalogItem xref = new CatalogItem { CatalogCuid = catalogCuid, ItemCuid = itemCuid }; Repository.Save(xref); return(item); }
public void CanRenameCatalog() { CatalogService svc = GetTestCatalogService(nameof(CanRenameCatalog), out DaoRepository daoRepository); string testCatalogName = $"{nameof(CanRenameCatalog)}_TestCatalog"; string renamedName = $"{testCatalogName}_Renamed"; CatalogDefinition catalogDefinition = svc.CreateCatalog(testCatalogName); Expect.AreEqual(testCatalogName, catalogDefinition.Name); CatalogDefinition renamed = svc.RenameCatalog(catalogDefinition, renamedName); Expect.AreEqual(renamedName, renamed.Name); CatalogDefinition retrieved = svc.FindCatalog(renamedName); Expect.AreEqual(retrieved, renamed); }
public void CanSaveCatalog() { DaoRepository repo = new DaoRepository(); repo.AddType <CatalogDefinition>(); Organization org = Organization.Public; string catalogName = "MyTestCatalog"; CatalogDefinition catalogDefinition = new CatalogDefinition() { OrganizationKey = org.Key, Name = catalogName }; CatalogDefinition saved = catalogDefinition.SaveByKey <CatalogDefinition>(repo); Expect.AreEqual(saved.Key, catalogDefinition.Key); Expect.AreEqual(saved, catalogDefinition); }
public void CanRemoveItemFromCatalog() { string itemName = "Test AddItem ".RandomLetters(6); CatalogService svc = _serviceRegistry.Get <CatalogService>(); CatalogDefinition catalog = svc.CreateCatalog(5.RandomLetters()); ItemDefinition item = svc.CreateItem(6.RandomLetters()); svc.AddItem(catalog.Cuid, item.Cuid); catalog = svc.GetCatalog(catalog.Cuid); List <ItemDefinition> items = catalog.Items.Where(i => i.Cuid.Equals(item.Cuid)).ToList(); Expect.IsTrue(items.Count == 1, $"Expected 1 catalog item but there were {items.Count}"); svc.RemoveItem(catalog.Cuid, item.Cuid); catalog = svc.GetCatalog(catalog.Cuid); items = catalog.Items.Where(i => i.Cuid.Equals(item.Cuid)).ToList(); Expect.IsTrue(items.Count == 0, $"Expected 0 catalog items but there were {items.Count}"); }
public void CanRemoveItemFromCatalogWithoutDeletingItem() { string testCatalogName = nameof(CanRemoveItemFromCatalogWithoutDeletingItem); string testItemName = "testItem_".RandomLetters(4); CatalogService svc = GetTestCatalogService(testCatalogName); CatalogDefinition catalogDefinition = svc.FindCatalog(testCatalogName); ItemDefinition item = svc.AddItem(catalogDefinition, testItemName); catalogDefinition = svc.GetCatalog(catalogDefinition); Expect.AreEqual(1, catalogDefinition.Items.Count); svc.RemoveItem(catalogDefinition, item); catalogDefinition = svc.GetCatalog(catalogDefinition); Expect.AreEqual(0, catalogDefinition.Items.Count); item = svc.GetItem(item); Expect.IsNotNull(item); }
public void ConsoleInvokableIntegrationTest() { ConsoleLogger logger = new ConsoleLogger(); logger.StartLoggingThread(); CoreClient client = new CoreClient("TestOr", "TestApp", "localhost", 9100, logger); CatalogService svc = client.GetProxy <CatalogService>(); CatalogDefinition list = svc.CreateCatalog("test list"); //ListDefinition CreateList(string name); //ItemDefinition CreateItem(string name); //ListDefinition AddItem(string listCuid, string itemCuid); //bool RemoveItem(string listCuid, string itemCuid); //ListDefinition GetList(string listCuid); //ListDefinition FindList(string name); //ListDefinition RenameList(string listCuid, string name); //ItemDefinition RenameItem(string itemCuid, string name); //bool DeleteList(string listCuid); //bool DeleteItem(string itemCuid); }
public void KeysCalculateCorrectlyForValues() { OutLine(new CatalogDefinition().ToJson(true)); CatalogService svc = GetTestCatalogService(nameof(CanFindCatalog), out DaoRepository daoRepository); string testCatalogName = $"{nameof(CanFindCatalog)}_TestCatalog"; CatalogDefinition catalogDefinition = new CatalogDefinition() { Name = testCatalogName, OrganizationKey = svc.ServerOrganization.Key, ApplicationKey = svc.ServerApplication.Key }; CatalogDefinition catalogDefinition2 = new CatalogDefinition() { Name = testCatalogName, OrganizationKey = svc.ServerOrganization.Key, ApplicationKey = svc.ServerApplication.Key }; Expect.AreEqual(catalogDefinition.Key, catalogDefinition2.Key); Message.PrintLine(catalogDefinition2.Key.ToString(), ConsoleColor.Yellow); }
public void CanGetCatalogItems() { string catalogName = $"{nameof(CanGetCatalogItems)}_TestCatalog"; string testItemName = $"{nameof(CanGetCatalogItems)}_TestItem"; string testItemName2 = $"{nameof(CanGetCatalogItems)}_TestItem2"; CatalogService svc = GetTestCatalogService(catalogName, nameof(CanGetCatalogItems)); CatalogDefinition catalogDefinition = svc.FindCatalog(catalogName); ItemDefinition itemOne = svc.AddItem(catalogDefinition, testItemName, out CatalogItem xref); Expect.IsNotNull(xref); ItemDefinition itemTwo = svc.AddItem(catalogDefinition, testItemName2, out CatalogItem xref2); Expect.IsNotNull(xref2); CatalogDefinition retrievedCatalog = svc.GetCatalog(catalogDefinition); Expect.AreEqual(2, retrievedCatalog.Items.Count); retrievedCatalog.Items.Contains(itemOne).IsTrue(); retrievedCatalog.Items.Contains(itemTwo).IsTrue(); }
public void CanRenameItem() { string itemName = "Test RenameItem ".RandomLetters(8); string newName = "New Name ".RandomLetters(8); CatalogService svc = _serviceRegistry.Get <CatalogService>(); CatalogDefinition catalog = svc.CreateCatalog(5.RandomLetters()); ItemDefinition item = svc.CreateItem(itemName); svc.AddItem(catalog.Cuid, item.Cuid); catalog = svc.GetCatalog(catalog.Cuid); List <ItemDefinition> namedItems = catalog.Items.Where(i => i.Name.Equals(itemName)).ToList(); Expect.IsTrue(namedItems.Count == 1, $"expected 1 item in catalog but there were {namedItems.Count}"); svc.RenameItem(item.Cuid, newName); catalog = svc.GetCatalog(catalog.Cuid); List <ItemDefinition> oldNamedItems = catalog.Items.Where(i => i.Name.Equals(itemName)).ToList(); Expect.IsTrue(oldNamedItems.Count == 0); List <ItemDefinition> newNamedItems = catalog.Items.Where(i => i.Name.Equals(newName)).ToList(); Expect.IsTrue(newNamedItems.Count == 1, $"Expected 1 new item but there were {newNamedItems.Count}"); }
public void CanLoadByKey() { CatalogService svc = GetTestCatalogService(nameof(CanLoadByKey), out DaoRepository daoRepository); string testCatalogName = $"{nameof(CanLoadByKey)}_TestCatalog"; CatalogDefinition catalogDefinition = new CatalogDefinition() { Name = testCatalogName, OrganizationKey = svc.ServerOrganization.Key, ApplicationKey = svc.ServerApplication.Key }; ulong key = catalogDefinition.Key; CatalogDefinition saved = catalogDefinition.SaveByKey <CatalogDefinition>(daoRepository); CatalogDefinition copied = catalogDefinition.CopyAs <CatalogDefinition>(); CatalogDefinition loaded = copied.LoadByKey <CatalogDefinition>(daoRepository); Expect.AreEqual(copied, loaded); Expect.AreEqual(copied.Name, loaded.Name); Expect.AreEqual(loaded.Name, testCatalogName); Expect.AreEqual(copied.Key, loaded.Key); Expect.IsGreaterThan(loaded.Key, 0); }
internal static string ToCreateScript(this CatalogDefinition catalog, bool checkExists = false) { var builder = new StringBuilder(); if (catalog.Comments != null) { builder.Append("-- CATALOG"); if (!string.IsNullOrEmpty(catalog.Name)) { builder.Append($" [{catalog.Name.ToUpper()}]"); } builder.AppendLine(" COMMENTS"); foreach (var comment in catalog.Comments) { builder.AppendLine($"-- {comment}"); } builder.AppendLine(); } if (catalog.Schemas != null) { builder.Append("-- CATALOG"); if (!string.IsNullOrEmpty(catalog.Name)) { builder.Append($" [{catalog.Name.ToUpper()}]"); } builder.AppendLine(" SCHEMAS"); builder.AppendLine(); foreach (var schema in catalog.Schemas) { builder.AppendLine(schema.ToCreateScript(checkExists)); builder.AppendLine(); } } return(builder.ToString()); }