Skip to content

Commit

Permalink
small addition to test where we insert an aspect
Browse files Browse the repository at this point in the history
nick4598 committed Jan 9, 2025
1 parent 8dc4667 commit 87a6d20
Showing 3 changed files with 83 additions and 18 deletions.
49 changes: 49 additions & 0 deletions packages/transformer/src/test/IModelTransformerUtils.ts
Original file line number Diff line number Diff line change
@@ -139,6 +139,55 @@ export class IModelTransformerTestUtils extends TestUtils.IModelTestUtils {
return iModelDb;
}

/** Returns path to a schema which contains a multiAspect TestSchema2:MyMultiAspect.
* The schema is created in the output directory.
* The multi aspect has a prop 'MyProp1'.
* Users should import this schema in order to insert multi aspects.
*/
public static getPathToSchemaWithMultiAspect(): string {
const testSchema1Path = IModelTransformerTestUtils.prepareOutputFile(
"IModelTransformer",
"TestSchema2.ecschema.xml"
);
IModelJsFs.writeFileSync(
testSchema1Path,
`<?xml version="1.0" encoding="UTF-8"?>
<ECSchema schemaName="TestSchema2" alias="ts1" version="01.00" xmlns="http://www.bentley.com/schemas/Bentley.ECXML.3.1">
<ECSchemaReference name="BisCore" version="01.00" alias="bis"/>
<ECEntityClass typeName="MyMultiAspect" description="A test unique aspect" displayLabel="a test unique aspect" modifier="Sealed">
<BaseClass>bis:ElementMultiAspect</BaseClass>
<ECProperty propertyName="MyProp1" typeName="string"/>
</ECEntityClass>
</ECSchema>`
);
return testSchema1Path;
}

/** Returns path to a schema which contains a UniqueAspect TestSchema1:MyUniqueAspect.
* The schema is created in the output directory.
* the only two ElementUniqueAspect's in bis are ignored by the transformer, so we can add our own to test their export
* The unique aspect has a prop 'MyProp1'.
* Users should import this schema in order to insert unique aspects.
*/
public static getPathToSchemaWithUniqueAspect(): string {
const testSchema1Path = IModelTransformerTestUtils.prepareOutputFile(
"IModelTransformer",
"TestSchema1.ecschema.xml"
);
IModelJsFs.writeFileSync(
testSchema1Path,
`<?xml version="1.0" encoding="UTF-8"?>
<ECSchema schemaName="TestSchema1" alias="ts1" version="01.00" xmlns="http://www.bentley.com/schemas/Bentley.ECXML.3.1">
<ECSchemaReference name="BisCore" version="01.00" alias="bis"/>
<ECEntityClass typeName="MyUniqueAspect" description="A test unique aspect" displayLabel="a test unique aspect" modifier="Sealed">
<BaseClass>bis:ElementUniqueAspect</BaseClass>
<ECProperty propertyName="MyProp1" typeName="string"/>
</ECEntityClass>
</ECSchema>`
);
return testSchema1Path;
}

public static populateTeamIModel(
teamDb: IModelDb,
teamName: string,
21 changes: 3 additions & 18 deletions packages/transformer/src/test/standalone/IModelTransformer.test.ts
Original file line number Diff line number Diff line change
@@ -3086,24 +3086,9 @@ describe("IModelTransformer", () => {
rootSubject: { name: "deferred-element-with-aspects" },
});

const testSchema1Path = IModelTransformerTestUtils.prepareOutputFile(
"IModelTransformer",
"TestSchema1.ecschema.xml"
);
// the only two ElementUniqueAspect's in bis are ignored by the transformer, so we add our own to test their export
IModelJsFs.writeFileSync(
testSchema1Path,
`<?xml version="1.0" encoding="UTF-8"?>
<ECSchema schemaName="TestSchema1" alias="ts1" version="01.00" xmlns="http://www.bentley.com/schemas/Bentley.ECXML.3.1">
<ECSchemaReference name="BisCore" version="01.00" alias="bis"/>
<ECEntityClass typeName="MyUniqueAspect" description="A test unique aspect" displayLabel="a test unique aspect" modifier="Sealed">
<BaseClass>bis:ElementUniqueAspect</BaseClass>
<ECProperty propertyName="MyProp1" typeName="string"/>
</ECEntityClass>
</ECSchema>`
);

await sourceDb.importSchemas([testSchema1Path]);
const testSchemaPath =
IModelTransformerTestUtils.getPathToSchemaWithUniqueAspect();
await sourceDb.importSchemas([testSchemaPath]);

const myPhysicalModelId = PhysicalModel.insert(
sourceDb,
Original file line number Diff line number Diff line change
@@ -20,9 +20,11 @@ import {
ECSqlStatement,
// eslint-disable-next-line @typescript-eslint/no-redeclare
Element,
ElementAspect,
ElementGroupsMembers,
ElementOwnsChildElements,
ElementOwnsExternalSourceAspects,
ElementOwnsMultiAspects,
ElementRefersToElements,
ExternalSourceAspect,
GenericSchema,
@@ -1824,6 +1826,9 @@ describe("IModelTransformerHub", () => {
});
// eslint-disable-next-line deprecation/deprecation
masterSeedDb.nativeDb.setITwinId(iTwinId); // workaround for "ContextId was not properly setup in the checkpoint" issue
const schemaPathForMultiAspect =
IModelTransformerTestUtils.getPathToSchemaWithMultiAspect();
masterSeedDb.importSchemas([schemaPathForMultiAspect]);
for await (const row of masterSeedDb.createQueryReader(
"SELECT ECInstanceId FROM ECdbMeta.ECClassDef WHERE Name LIKE 'ElementGroupsMembers'"
)) {
@@ -1842,6 +1847,7 @@ describe("IModelTransformerHub", () => {
let sourceIdOfRel: Id64String | undefined;
let targetIdOfRel: Id64String | undefined;
let elementIdInSource: Id64String | undefined;
let aspectIdInSource: Id64String | undefined;
let physicalModelIdInSource: Id64String | undefined;
let modelUnderRepositoryModel: Id64String | undefined;
const timeline: Timeline = [
@@ -1873,6 +1879,16 @@ describe("IModelTransformerHub", () => {
IModel.rootSubjectId,
"MyModelUnderRepositoryModel"
);
// insert aspect
const multiAspectProps = {
classFullName: "TestSchema2:MyMultiAspect",
element: {
id: elementIdInSource,
relClassName: ElementOwnsMultiAspects.classFullName,
},
myProp1: "prop_value",
};
aspectIdInSource = db.elements.insertAspect(multiAspectProps);
},
},
},
@@ -1892,6 +1908,11 @@ describe("IModelTransformerHub", () => {

const idOfElement = IModelTestUtils.queryByUserLabel(db, "100");
expect(idOfElement).to.not.be.undefined;
const aspectsOnElement = db.elements.getAspects(
idOfElement,
ElementAspect.classFullName
);
expect(aspectsOnElement.length).to.equal(1);
db.elements.deleteElement(idOfElement);
const physicalPartitionIdInTarget =
IModelTestUtils.queryByCodeValue(db, "MyPhysicalModel");
@@ -1928,6 +1949,7 @@ describe("IModelTransformerHub", () => {
expect(rel).to.be.undefined;
const element = IModelTestUtils.queryByUserLabel(branch1.db, "100");
expect(element).to.equal(Id64.invalid);
// assume if element is gone, aspect is gone
const physicalPartitionIdInTarget = IModelTestUtils.queryByCodeValue(
branch1.db,
"MyPhysicalModel"
@@ -1960,6 +1982,10 @@ describe("IModelTransformerHub", () => {
"Inserted",
elementIdInSource!
);
exporter.sourceDbChanges?.addCustomAspectChange(
"Inserted",
aspectIdInSource!
);
exporter.sourceDbChanges?.addCustomElementChange(
"Inserted",
physicalModelIdInSource!
@@ -2004,6 +2030,11 @@ describe("IModelTransformerHub", () => {
"100"
);
expect(elementInTarget).to.not.equal(Id64.invalid);
const aspectsOnElement = branch1.db.elements.getAspects(
elementInTarget,
ElementAspect.classFullName
);
expect(aspectsOnElement.length).to.equal(1);
const physicalPartitionIdInTarget = IModelTestUtils.queryByCodeValue(
branch1.db,
"MyPhysicalModel"

0 comments on commit 87a6d20

Please sign in to comment.