public async Task LoadTreeModel() { IDataModel dm = await _dbContext.LoadModelAsync(null, "a2test.TreeModel"); var md = new MetadataTester(dm); md.IsAllKeys("TRoot,TMenu"); md.HasAllProperties("TRoot", "Menu"); md.HasAllProperties("TMenu", "Menu,Name"); md.IsName("TMenu", "Name"); var dt = new DataTester(dm, "Menu"); dt.IsArray(2); dt.AreArrayValueEqual("Item 1", 0, "Name"); dt.AreArrayValueEqual("Item 2", 1, "Name"); dt = new DataTester(dm, "Menu[0].Menu"); dt.IsArray(2); dt.AreArrayValueEqual("Item 1.1", 0, "Name"); dt.AreArrayValueEqual("Item 1.2", 1, "Name"); dt = new DataTester(dm, "Menu[0].Menu[0].Menu"); dt.IsArray(1); dt.AreArrayValueEqual("Item 1.1.1", 0, "Name"); }
public async Task LoadGroupModel() { IDataModel dm = await _dbContext.LoadModelAsync(null, "a2test.GroupModel"); var md = new MetadataTester(dm); md.IsAllKeys("TRoot,TModel"); md.HasAllProperties("TRoot", "Model"); md.HasAllProperties("TModel", "Company,Agent,Amount,Items"); var dt = new DataTester(dm, "Model"); dt.AreValueEqual(550M, "Amount"); dt.IsNull("Company"); dt.IsNull("Agent"); dt = new DataTester(dm, "Model.Items"); dt.IsArray(2); dt.AreArrayValueEqual("Company 1", 0, "Company"); dt.AreArrayValueEqual("Company 2", 1, "Company"); dt.AreArrayValueEqual(500M, 0, "Amount"); dt.AreArrayValueEqual(50M, 1, "Amount"); dt = new DataTester(dm, "Model.Items[0].Items"); dt.IsArray(2); dt.AreArrayValueEqual("Company 1", 0, "Company"); dt.AreArrayValueEqual("Company 1", 1, "Company"); dt.AreArrayValueEqual("Agent 1", 0, "Agent"); dt.AreArrayValueEqual("Agent 2", 1, "Agent"); dt.AreArrayValueEqual(400M, 0, "Amount"); dt.AreArrayValueEqual(100M, 1, "Amount"); dt = new DataTester(dm, "Model.Items[1].Items"); dt.IsArray(2); dt.AreArrayValueEqual("Company 2", 0, "Company"); dt.AreArrayValueEqual("Company 2", 1, "Company"); dt.AreArrayValueEqual("Agent 1", 0, "Agent"); dt.AreArrayValueEqual("Agent 2", 1, "Agent"); dt.AreArrayValueEqual(40M, 0, "Amount"); dt.AreArrayValueEqual(10M, 1, "Amount"); }
public async Task LoadMapObjects() { var dm = await _dbContext.LoadModelAsync(null, "a2test.[MapObjects.Load]"); var dt = new DataTester(dm, "Document"); dt.AreValueEqual("Document name", "Name"); dt = new DataTester(dm, "Document.Category"); dt.AreValueEqual("CAT1", "Id"); //dt.AreValueEqual("CAT1", "Key"); dt.AreValueEqual("Category_1", "Name"); dt = new DataTester(dm, "Categories.CAT1"); //dt.AreValueEqual("CAT1", "Key"); dt.AreValueEqual("CAT1", "Id"); dt.AreValueEqual("Category_1", "Name"); // check for script creation var scripter = new VueScriptBuilder(); var script = dm.CreateScript(scripter); Assert.IsFalse(String.IsNullOrEmpty(script)); dm = await _dbContext.LoadModelAsync(null, "a2test.[MapObjects.NoKey.Load]"); dt = new DataTester(dm, "Document"); dt.AreValueEqual("Document name", "Name"); dt = new DataTester(dm, "Document.Category"); dt.AreValueEqual("CAT1", "Id"); dt.AreValueEqual("Category_1", "Name"); dt = new DataTester(dm, "Categories"); dt.IsArray(1); dt.AreArrayValueEqual("CAT1", 0, "Id"); dt.AreArrayValueEqual("Category_1", 0, "Name"); }
public async Task LoadDocumentWithRowsAndMethods() { var dm = await _dbContext.LoadModelAsync(null, "a2test.[Document.RowsMethods.Load]"); var md = new MetadataTester(dm); md.IsAllKeys("TRoot,TDocument,TRow,TMethod,TMethodMap,TMethodData"); md.HasAllProperties("TRoot", "Document"); md.HasAllProperties("TDocument", "Name,Id,Rows"); md.HasAllProperties("TMethodMap", "Mtd1,Mtd2"); md.HasAllProperties("TMethodData", "Id,Code"); md.IsId("TDocument", "Id"); md.HasAllProperties("TRow", "Id,Methods"); md.HasAllProperties("TMethod", "Key,Name,Id,Data"); var dt = new DataTester(dm, "Document"); dt.AreValueEqual(123, "Id"); dt = new DataTester(dm, "Document.Rows"); dt.IsArray(1); dt = new DataTester(dm, "Document.Rows[0].Methods.Mtd1"); dt.AreValueEqual("Mtd1", "Key"); dt.AreValueEqual("Method 1", "Name"); dt = new DataTester(dm, "Document.Rows[0].Methods.Mtd2"); dt.AreValueEqual("Mtd2", "Key"); dt.AreValueEqual("Method 2", "Name"); dt = new DataTester(dm, "Document.Rows[0].Methods.Mtd1.Data"); dt.IsArray(1); dt.AreArrayValueEqual("Code1", 0, "Code"); dt.AreArrayValueEqual(276, 0, "Id"); }
public async Task WriteSubObjectData() { // DATA with ROOT var jsonData = @" { MainObject: { Id : 45, Name: 'MainObjectName', NumValue : 531.55, BitValue : true, SubObject : { Id: 55, Name: 'SubObjectName', SubArray: [ {X: 5, Y:6, D:5.1 }, {X: 8, Y:9, D:7.23 } ] } } } " ; IDataModel dm = null; var dataToSave = JsonConvert.DeserializeObject <ExpandoObject>(jsonData.Replace('\'', '"'), new ExpandoObjectConverter()); try { dm = await _dbContext.SaveModelAsync(null, "a2test.[NestedObject.Update]", dataToSave); } catch (Exception /*ex*/) { throw; } var dt = new DataTester(dm, "MainObject"); dt.AreValueEqual(45L, "Id"); dt.AreValueEqual("MainObjectName", "Name"); var guid = dt.GetValue <Guid>("GUID"); var tdsub = new DataTester(dm, "MainObject.SubObject"); tdsub.AreValueEqual(55L, "Id"); tdsub.AreValueEqual("SubObjectName", "Name"); tdsub.AreValueEqual(guid, "ParentGuid"); var tdsubarray = new DataTester(dm, "MainObject.SubObject.SubArray"); tdsubarray.IsArray(2); tdsubarray.AreArrayValueEqual(5, 0, "X"); tdsubarray.AreArrayValueEqual(6, 0, "Y"); tdsubarray.AreArrayValueEqual(5.1M, 0, "D"); tdsubarray.AreArrayValueEqual(8, 1, "X"); tdsubarray.AreArrayValueEqual(9, 1, "Y"); tdsubarray.AreArrayValueEqual(7.23M, 1, "D"); }
public async Task WriteModelWithGuids() { // DATA with ROOT var jsonData = @" { Document: { Id : 150, Rows: [ { Id: 10, Code: 'C10', SubRows: [ {Id: 100, Code: 'SUBCODE:100'}, {Id: 200, Code: 'SUBCODE:200'} ]}, { Id: 20, Code: 'C20'}, ] } } " ; var dataToSave = JsonConvert.DeserializeObject <ExpandoObject>(jsonData.Replace('\'', '"'), new ExpandoObjectConverter()); IDataModel dm = await _dbContext.SaveModelAsync(null, "a2test.[Guid.Update]", dataToSave); var dt = new DataTester(dm, "Document"); dt.AreValueEqual(150L, "Id"); var guid = dt.GetValue <Guid>("GUID"); var rows = new DataTester(dm, "Document.Rows"); rows.IsArray(2); rows.AreArrayValueEqual(guid, 0, "ParentGuid"); rows.AreArrayValueEqual(guid, 1, "ParentGuid"); rows.AreArrayValueEqual(10L, 0, "Id"); rows.AreArrayValueEqual(20L, 1, "Id"); rows.AreArrayValueEqual(1, 0, "RowNo"); // 1-based rows.AreArrayValueEqual(2, 1, "RowNo"); var rowguid = rows.GetArrayValue <Guid>(0, "GUID"); Assert.AreNotEqual(guid, rowguid); var subrows = new DataTester(dm, "Document.Rows[0].SubRows"); subrows.IsArray(2); subrows.AreArrayValueEqual(rowguid, 0, "ParentGuid"); subrows.AreArrayValueEqual(rowguid, 1, "ParentGuid"); subrows.AreArrayValueEqual(1, 0, "RowNo"); // 1-based subrows.AreArrayValueEqual(2, 1, "RowNo"); subrows.AreArrayValueEqual(1, 0, "ParentRN"); // 1-based subrows.AreArrayValueEqual(1, 1, "ParentRN"); }
public async Task Aliases() { Int64 docId = 10; ExpandoObject prms = new ExpandoObject { { "UserId", 100 }, { "Id", docId } }; IDataModel dm = await _dbContext.LoadModelAsync(null, "a2test.[Document.Aliases]", prms); var md = new MetadataTester(dm); md.IsAllKeys("TRoot,TDocument,TRow,TEntity"); md.HasAllProperties("TRoot", "Document"); md.HasAllProperties("TDocument", "Id,Rows"); md.HasAllProperties("TRow", "Id,Entity"); md.HasAllProperties("TEntity", "Id,Name"); var dt = new DataTester(dm, "Document"); dt.AreValueEqual(docId, "Id"); dt = new DataTester(dm, "Document.Rows"); dt.IsArray(1); dt.AreArrayValueEqual(59, 0, "Id"); }
public async Task LoadComplexModel() { IDataModel dm = await _dbContext.LoadModelAsync(null, "a2test.ComplexModel"); var md = new MetadataTester(dm); md.IsAllKeys("TRoot,TDocument,TRow,TAgent,TProduct,TSeries,TUnit"); md.HasAllProperties("TRoot", "Document"); md.HasAllProperties("TDocument", "Id,No,Date,Agent,Company,Rows1,Rows2"); md.HasAllProperties("TRow", "Id,Product,Qty,Price,Sum,Series1"); md.HasAllProperties("TProduct", "Id,Name,Unit"); md.HasAllProperties("TUnit", "Id,Name"); var docT = new DataTester(dm, "Document"); docT.AreValueEqual(123, "Id"); docT.AreValueEqual("DocNo", "No"); var agentT = new DataTester(dm, "Document.Agent"); agentT.AreValueEqual(512, "Id"); agentT.AreValueEqual("Agent 512", "Name"); agentT.AreValueEqual("Code 512", "Code"); agentT = new DataTester(dm, "Document.Company"); agentT.AreValueEqual(512, "Id"); agentT.AreValueEqual("Agent 512", "Name"); agentT.AreValueEqual("Code 512", "Code"); var row1T = new DataTester(dm, "Document.Rows1"); row1T.IsArray(1); row1T.AreArrayValueEqual(78, 0, "Id"); row1T.AreArrayValueEqual(4.0, 0, "Qty"); var row2T = new DataTester(dm, "Document.Rows2"); row2T.IsArray(1); row2T.AreArrayValueEqual(79, 0, "Id"); row2T.AreArrayValueEqual(7.0, 0, "Qty"); var row1Obj = new DataTester(dm, "Document.Rows1[0]"); row1Obj.AreValueEqual(78, "Id"); row1Obj.AreValueEqual(4.0, "Qty"); row1Obj.AllProperties("Id,Qty,Price,Sum,Product,Series1"); var prodObj = new DataTester(dm, "Document.Rows1[0].Product"); prodObj.AreValueEqual(782, "Id"); prodObj.AreValueEqual("Product 782", "Name"); prodObj.AllProperties("Id,Name,Unit"); var unitObj = new DataTester(dm, "Document.Rows1[0].Product.Unit"); unitObj.AreValueEqual(7, "Id"); unitObj.AreValueEqual("Unit7", "Name"); unitObj.AllProperties("Id,Name"); prodObj = new DataTester(dm, "Document.Rows2[0].Product"); prodObj.AreValueEqual(785, "Id"); prodObj.AreValueEqual("Product 785", "Name"); unitObj = new DataTester(dm, "Document.Rows2[0].Product.Unit"); unitObj.AreValueEqual(8, "Id"); unitObj.AreValueEqual("Unit8", "Name"); var seriesObj = new DataTester(dm, "Document.Rows1[0].Series1"); seriesObj.IsArray(1); seriesObj.AreArrayValueEqual(500, 0, "Id"); seriesObj.AreArrayValueEqual(5.0, 0, "Price"); seriesObj = new DataTester(dm, "Document.Rows2[0].Series1"); seriesObj.IsArray(1); seriesObj.AreArrayValueEqual(501, 0, "Id"); seriesObj.AreArrayValueEqual(10.0, 0, "Price"); }
public async Task LoadDocument2() { ExpandoObject prms = new ExpandoObject { { "UserId", 100 } }; Int64 docId = 10; prms.Add("Id", docId); IDataModel dm = await _dbContext.LoadModelAsync(null, "a2test.[Document2.Load]", prms); var md = new MetadataTester(dm); md.IsAllKeys("TRoot,TDocument,TRow,TPriceList,TPriceKind,TPrice,TEntity"); md.HasAllProperties("TRoot", "Document,PriceLists,PriceKinds"); md.HasAllProperties("TDocument", "Id,Rows,PriceKind"); md.HasAllProperties("TPriceList", "Id,Name,PriceKinds"); md.HasAllProperties("TPriceKind", "Id,Name,Main"); md.HasAllProperties("TPrice", "Price,PriceKind"); md.HasAllProperties("TRow", "Id,Entity"); md.HasAllProperties("TEntity", "Id,Name,Prices"); md.IsItemType("TDocument", "Rows", FieldType.Array); md.IsId("TDocument", "Id"); md.IsItemType("TRow", "Entity", FieldType.Object); md.IsId("TRow", "Id"); md.IsId("TPriceList", "Id"); md.IsId("TPriceKind", "Id"); md.IsItemType("TEntity", "Prices", FieldType.Array); // data var dt = new DataTester(dm, "Document"); dt.AreValueEqual(docId, "Id"); dt = new DataTester(dm, "Document.PriceKind"); dt.AreValueEqual(4294967306L, "Id"); dt = new DataTester(dm, "Document.Rows"); dt.IsArray(1); dt.AreArrayValueEqual(59, 0, "Id"); dt = new DataTester(dm, "Document.Rows[0].Entity.Prices"); dt.IsArray(3); dt.AreArrayValueEqual(185.7M, 0, "Price"); dt.AreArrayValueEqual(179.4M, 1, "Price"); dt.AreArrayValueEqual(172.44M, 2, "Price"); dt = new DataTester(dm, "Document.Rows[0].Entity.Prices[0].PriceKind"); dt.AreValueEqual(4294967305L, "Id"); dt.AreValueEqual("Kind 1", "Name"); dt = new DataTester(dm, "Document.Rows[0].Entity.Prices[1].PriceKind"); dt.AreValueEqual(4294967304L, "Id"); dt.AreValueEqual("Kind 2", "Name"); dt = new DataTester(dm, "Document.Rows[0].Entity.Prices[2].PriceKind"); dt.AreValueEqual(4294967306L, "Id"); dt.AreValueEqual("Kind 3", "Name"); dt = new DataTester(dm, "PriceLists"); dt.IsArray(2); dt.AreArrayValueEqual(4294967300L, 0, "Id"); dt.AreArrayValueEqual(4294967304L, 1, "Id"); dt = new DataTester(dm, "PriceKinds"); dt.IsArray(4); dt.AreArrayValueEqual(4294967305L, 0, "Id"); dt.AreArrayValueEqual(4294967304L, 1, "Id"); dt.AreArrayValueEqual(4294967306L, 2, "Id"); dt.AreArrayValueEqual(4294967303L, 3, "Id"); }
public async Task LoadDocument() { Int64 docId = 10; ExpandoObject prms = new ExpandoObject { { "UserId", 100 }, { "Id", docId } }; IDataModel dm = await _dbContext.LoadModelAsync(null, "a2test.[Document.Load]", prms); var md = new MetadataTester(dm); md.IsAllKeys("TRoot,TDocument,TAgent,TRow,TPriceList,TPriceKind,TPrice,TEntity"); md.HasAllProperties("TRoot", "Document,PriceLists,PriceKinds"); md.HasAllProperties("TDocument", "Id,Agent,Company,PriceList,PriceKind,Rows"); md.HasAllProperties("TPriceList", "Id,Name,PriceKinds"); md.HasAllProperties("TPriceKind", "Id,Name,Prices"); md.HasAllProperties("TPrice", "Id,Price,PriceKind"); md.HasAllProperties("TRow", "Id,PriceKind,Entity"); md.HasAllProperties("TEntity", "Id,Name,Prices"); md.IsItemType("TDocument", "Rows", FieldType.Array); md.IsId("TDocument", "Id"); md.IsItemType("TRow", "PriceKind", FieldType.Object); md.IsItemType("TRow", "Entity", FieldType.Object); md.IsId("TRow", "Id"); md.IsId("TPriceList", "Id"); md.IsId("TPriceKind", "Id"); md.IsItemType("TEntity", "Prices", FieldType.Array); // data var dt = new DataTester(dm, "Document"); dt.AreValueEqual(docId, "Id"); dt = new DataTester(dm, "Document.PriceKind.Prices"); dt.IsArray(2); dt.AreArrayValueEqual(22.5M, 0, "Price"); dt.AreArrayValueEqual(36.8M, 1, "Price"); dt = new DataTester(dm, "Document.Rows"); dt.IsArray(1); dt.AreArrayValueEqual(59, 0, "Id"); dt = new DataTester(dm, "Document.Rows[0].PriceKind"); dt.AreValueEqual(7, "Id"); dt = new DataTester(dm, "Document.Rows[0].PriceKind.Prices"); dt.IsArray(2); dt.AreArrayValueEqual(22.5M, 0, "Price"); dt.AreArrayValueEqual(36.8M, 1, "Price"); dt = new DataTester(dm, "Document.Rows[0].Entity.Prices"); dt.IsArray(2); dt.AreArrayValueEqual(22.5M, 0, "Price"); dt.AreArrayValueEqual(36.8M, 1, "Price"); dt = new DataTester(dm, "Document.Rows[0].Entity.Prices[0].PriceKind"); dt.AreValueEqual(8, "Id"); dt = new DataTester(dm, "PriceLists"); dt.IsArray(1); dt.AreArrayValueEqual(1, 0, "Id"); dt = new DataTester(dm, "PriceKinds"); dt.IsArray(2); dt.AreArrayValueEqual(7, 0, "Id"); dt.AreArrayValueEqual(8, 1, "Id"); }
public async Task WriteDocumentWithRowsAndMethods() { const String jsonData = @" {'Document': { 'Id': 0, 'Name':'Document', 'Rows':[{ 'Id': 0, 'Methods': { 'Mtd1':{ 'Name':'Method 1', 'Data':[ {'Id':0,'Code':'Code1'}, {'Id':0,'Code':'Code2'} ] }, 'Mtd2':{ 'Name':'Method 2', 'Data':[ {'Id':0,'Code':'Code3'} ] } }, }, { 'Id': 0, 'Methods': { 'Mtd1': { 'Name': 'Method 3', 'Data' : [ {'Id':0,'Code':'Code4'} ] } } }] }}"; var dataToSave = JsonConvert.DeserializeObject <ExpandoObject>(jsonData.Replace('\'', '"'), new ExpandoObjectConverter()); IDataModel dm = null; try { dm = await _dbContext.SaveModelAsync(null, "a2test.[Document.RowsMethods.Update]", dataToSave); } catch (Exception /*ex*/) { throw; } var dt = new DataTester(dm, "Document"); dt.AreValueEqual <Object>(null, "Id"); dt = new DataTester(dm, "Rows"); dt.IsArray(2); dt.AreArrayValueEqual <Object>(null, 0, "Id"); dt.AreArrayValueEqual(1, 0, "RowNo"); dt.AreArrayValueEqual(2, 1, "RowNo"); dt.AreArrayValueEqual <Object>(null, 0, "Id"); dt.AreArrayValueEqual <Object>(null, 1, "Id"); dt = new DataTester(dm, "Methods"); dt.IsArray(3); dt.AreArrayValueEqual("Method 1", 0, "Name"); dt.AreArrayValueEqual("Mtd1", 0, "Key"); dt.AreArrayValueEqual(1, 0, "RowNo"); dt.AreArrayValueEqual("Method 2", 1, "Name"); dt.AreArrayValueEqual("Mtd2", 1, "Key"); dt.AreArrayValueEqual(1, 1, "RowNo"); dt.AreArrayValueEqual("Method 3", 2, "Name"); dt.AreArrayValueEqual("Mtd1", 2, "Key"); dt.AreArrayValueEqual(2, 2, "RowNo"); dt = new DataTester(dm, "MethodData"); dt.IsArray(4); dt.AreArrayValueEqual("Code1", 0, "Code"); dt.AreArrayValueEqual("Code2", 1, "Code"); dt.AreArrayValueEqual("Code3", 2, "Code"); dt.AreArrayValueEqual("Code4", 3, "Code"); dt.AreArrayValueEqual(1, 0, "RowNo"); dt.AreArrayValueEqual(1, 1, "RowNo"); dt.AreArrayValueEqual(1, 2, "RowNo"); dt.AreArrayValueEqual(2, 3, "RowNo"); dt.AreArrayValueEqual("Mtd1", 0, "Key"); dt.AreArrayValueEqual("Mtd1", 1, "Key"); dt.AreArrayValueEqual("Mtd2", 2, "Key"); dt.AreArrayValueEqual("Mtd1", 3, "Key"); }