Пример #1
0
        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");
        }