Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<metadata>

<id>Microsoft.CommonDataModel.ObjectModel.Adapter.Adls.All</id>
<version>1.2.1</version>
<version>1.2.2</version>
<description>The ADLS adapter implementation for the Microsoft Common Data Model Object Model.</description>

<authors>Microsoft</authors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net45;net462</TargetFrameworks>
<version>1.2.1</version>
<version>1.2.2</version>
<Description>The ADLS adapter implementation for the Microsoft Common Data Model Object Model.</Description>

<Authors>Microsoft</Authors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<metadata>

<id>Microsoft.CommonDataModel.ObjectModel.Adapter.Adls</id>
<version>1.2.1</version>
<version>1.2.2</version>
<description>The ADLS adapter implementation for the Microsoft Common Data Model Object Model.</description>

<authors>Microsoft</authors>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

namespace Microsoft.CommonDataModel.ObjectModel.Tests.Cdm
{
using Microsoft.CommonDataModel.ObjectModel.Cdm;
using Microsoft.VisualStudio.TestTools.UnitTesting;

[TestClass]
public class ManifestDefinitionTests
{
/// <summary>
/// Tests if the copy function creates copies of the sub objects
/// </summary>
[TestMethod]
public void TestManifestCopy()
{
var corpus = new CdmCorpusDefinition();
var manifest = new CdmManifestDefinition(corpus.Ctx, "name");

var entityName = "entity";
var subManifestName = "subManifest";
var relationshipName = "relName";
var traitName = "traitName";

var entityDec = manifest.Entities.Add(entityName);
var subManifest = manifest.SubManifests.Add(subManifestName);
var relationship = manifest.Relationships.Add(relationshipName);
var trait = manifest.ExhibitsTraits.Add(traitName);

var copy = manifest.Copy() as CdmManifestDefinition;
copy.Entities[0].EntityName = "newEntity";
copy.SubManifests[0].ManifestName = "newSubManifest";
copy.Relationships[0].Name = "newRelName";
copy.ExhibitsTraits[0].NamedReference = "newTraitName";

Assert.AreEqual(entityName, entityDec.EntityName);
Assert.AreEqual(subManifestName, subManifest.ManifestName);
Assert.AreEqual(relationshipName, relationship.Name);
Assert.AreEqual(traitName, trait.NamedReference);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,10 @@ private void GetArgumentValues(CdmArgumentDefinition args)
/// <summary>
/// A function to validate if the attribute context tree & traits generated for a resolved entity is the same as the expected and saved attribute context tree & traits for a test case
/// </summary>
/// <param name="corpus"></param>
/// <param name="expectedOutputPath"></param>
/// <param name="entityName"></param>
/// <param name="resolvedEntity"></param>
public static async Task ValidateAttributeContext(CdmCorpusDefinition corpus, string expectedOutputPath, string entityName, CdmEntityDefinition resolvedEntity)
public static async Task ValidateAttributeContext(string expectedOutputPath, string entityName, CdmEntityDefinition resolvedEntity, bool updateExpectedOutput = false)
{
if (resolvedEntity.AttributeContext != null)
{
Expand All @@ -174,6 +173,12 @@ public static async Task ValidateAttributeContext(CdmCorpusDefinition corpus, st

// Expected
string expectedStringFilePath = Path.GetFullPath(Path.Combine(expectedOutputPath, $"AttrCtx_{entityName}.txt"));

if (updateExpectedOutput)
{
File.WriteAllText(expectedStringFilePath, File.ReadAllText(actualStringFilePath));
}

string expectedText = File.ReadAllText(expectedStringFilePath);

// Test if Actual is Equal to Expected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public async Task TestCompositeKeyNonPolymorphicRelationship()
/// </summary>
/// <param name="testName"></param>
/// <param name="entityName"></param>
private async Task TestRun(string testName, string entityName, bool isEntitySet)
private async Task TestRun(string testName, string entityName, bool isEntitySet, bool updateExpectedOutput = false)
{
CdmCorpusDefinition corpus = TestHelper.GetLocalCorpus(testsSubpath, testName);
string inputFolder = TestHelper.GetInputFolderPath(testsSubpath, testName);
Expand All @@ -155,7 +155,7 @@ private async Task TestRun(string testName, string entityName, bool isEntitySet)
CdmEntityDefinition resolvedEntity = await ProjectionTestUtils.GetResolvedEntity(corpus, entity, new List<string> { "referenceOnly" });
AssertEntityShapeInResolvedEntity(resolvedEntity, isEntitySet);

await AttributeContextUtil.ValidateAttributeContext(corpus, expectedOutputFolder, entityName, resolvedEntity);
await AttributeContextUtil.ValidateAttributeContext(expectedOutputFolder, entityName, resolvedEntity, updateExpectedOutput);

await corpus.CalculateEntityGraphAsync(manifest);
await manifest.PopulateManifestRelationshipsAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace Microsoft.CommonDataModel.ObjectModel.Tests.Cdm
using System.Threading.Tasks;
using Microsoft.CommonDataModel.ObjectModel.Cdm;
using Microsoft.CommonDataModel.ObjectModel.Storage;
using Microsoft.CommonDataModel.ObjectModel.Tests.Cdm.Projection;
using Microsoft.CommonDataModel.ObjectModel.Tests.Cdm.Resolution;
using Microsoft.CommonDataModel.ObjectModel.Utilities;
using Microsoft.CommonDataModel.Tools.Processor;
Expand Down Expand Up @@ -285,5 +286,20 @@ public async Task TestSettingTraitsForResolutionGuidanceAttributes()

Assert.IsNotNull(resolvedEntity.Attributes[0].AppliedTraits.Item("is.linkedEntity.identifier"));
}

/// <summary>
/// Test that traits(including the ones inside of dataTypeRefence and PurposeReference) are applied to an entity attribute and type attribute.
/// </summary>
/// <returns></returns>
[TestMethod]
public async Task TestAppliedTraitsInAttributes()
{
CdmCorpusDefinition corpus = TestHelper.GetLocalCorpus(testsSubpath, "TestAppliedTraitsInAttributes");
string expectedOutputFolder = TestHelper.GetExpectedOutputFolderPath(testsSubpath, "TestAppliedTraitsInAttributes");
CdmEntityDefinition entity = await corpus.FetchObjectAsync<CdmEntityDefinition>("local:/Sales.cdm.json/Sales");
CdmEntityDefinition resolvedEntity = await ProjectionTestUtils.GetResolvedEntity(corpus, entity, new List<string> { "referenceOnly" });

await AttributeContextUtil.ValidateAttributeContext(expectedOutputFolder, "Sales", resolvedEntity);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ public async Task TestTraitsFromTraitGroup()
CdmCorpusDefinition cdmCorpus = TestHelper.GetLocalCorpus(testsSubpath, "TestResolvedTraitGroup");

cdmCorpus.SetEventCallback(new EventCallback { Invoke = (CdmStatusLevel statusLevel, string message) =>
{
Assert.Fail($"Received {statusLevel} message: {message}");
}
{
if (!message.Contains("Resolution guidance is being deprecated in favor of Projections."))
{
Assert.Fail($"Received {statusLevel} message: {message}");
}
}
}, CdmStatusLevel.Warning);

var ent = await cdmCorpus.FetchObjectAsync<CdmEntityDefinition>("local:/E2EResolution/Contact.cdm.json/Contact");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ protected static async Task RunTestWithValues(
List<AttributeExpectedValue> expected_normalized_structured,
List<AttributeExpectedValue> expected_referenceOnly_normalized,
List<AttributeExpectedValue> expected_referenceOnly_structured,
List<AttributeExpectedValue> expected_referenceOnly_normalized_structured
List<AttributeExpectedValue> expected_referenceOnly_normalized_structured,
bool updateExpectedOutput = false
)
{
try
Expand Down Expand Up @@ -99,7 +100,7 @@ List<AttributeExpectedValue> expected_referenceOnly_normalized_structured
outputEntityName = $"{sourceEntityName}_R_{entityFileName}";
outputEntityFileName = $"{outputEntityName}.cdm.json";
resolvedEntityDef = await srcEntityDef.CreateResolvedEntityAsync(outputEntityName, resOpt, outFolder);
await SaveActualEntityAndValidateWithExpected(Path.Combine(testExpectedPath, outputEntityFileName), resolvedEntityDef);
await SaveActualEntityAndValidateWithExpected(Path.Combine(testExpectedPath, outputEntityFileName), resolvedEntityDef, updateExpectedOutput);
}

if (expectedContext_normalized != null && expected_normalized != null)
Expand All @@ -109,7 +110,7 @@ List<AttributeExpectedValue> expected_referenceOnly_normalized_structured
outputEntityName = $"{sourceEntityName}_R_{entityFileName}";
outputEntityFileName = $"{outputEntityName}.cdm.json";
resolvedEntityDef = await srcEntityDef.CreateResolvedEntityAsync(outputEntityName, resOpt, outFolder);
await SaveActualEntityAndValidateWithExpected(Path.Combine(testExpectedPath, outputEntityFileName), resolvedEntityDef);
await SaveActualEntityAndValidateWithExpected(Path.Combine(testExpectedPath, outputEntityFileName), resolvedEntityDef, updateExpectedOutput);
}

if (expectedContext_referenceOnly != null && expected_referenceOnly != null)
Expand All @@ -119,7 +120,7 @@ List<AttributeExpectedValue> expected_referenceOnly_normalized_structured
outputEntityName = $"{sourceEntityName}_R_{entityFileName}";
outputEntityFileName = $"{outputEntityName}.cdm.json";
resolvedEntityDef = await srcEntityDef.CreateResolvedEntityAsync(outputEntityName, resOpt, outFolder);
await SaveActualEntityAndValidateWithExpected(Path.Combine(testExpectedPath, outputEntityFileName), resolvedEntityDef);
await SaveActualEntityAndValidateWithExpected(Path.Combine(testExpectedPath, outputEntityFileName), resolvedEntityDef, updateExpectedOutput);
}

if (expectedContext_structured != null && expected_structured != null)
Expand All @@ -129,7 +130,7 @@ List<AttributeExpectedValue> expected_referenceOnly_normalized_structured
outputEntityName = $"{sourceEntityName}_R_{entityFileName}";
outputEntityFileName = $"{outputEntityName}.cdm.json";
resolvedEntityDef = await srcEntityDef.CreateResolvedEntityAsync(outputEntityName, resOpt, outFolder);
await SaveActualEntityAndValidateWithExpected(Path.Combine(testExpectedPath, outputEntityFileName), resolvedEntityDef);
await SaveActualEntityAndValidateWithExpected(Path.Combine(testExpectedPath, outputEntityFileName), resolvedEntityDef, updateExpectedOutput);
}

if (expectedContext_normalized_structured != null && expected_normalized_structured != null)
Expand All @@ -139,7 +140,7 @@ List<AttributeExpectedValue> expected_referenceOnly_normalized_structured
outputEntityName = $"{sourceEntityName}_R_{entityFileName}";
outputEntityFileName = $"{outputEntityName}.cdm.json";
resolvedEntityDef = await srcEntityDef.CreateResolvedEntityAsync(outputEntityName, resOpt, outFolder);
await SaveActualEntityAndValidateWithExpected(Path.Combine(testExpectedPath, outputEntityFileName), resolvedEntityDef);
await SaveActualEntityAndValidateWithExpected(Path.Combine(testExpectedPath, outputEntityFileName), resolvedEntityDef, updateExpectedOutput);
}

if (expectedContext_referenceOnly_normalized != null && expected_referenceOnly_normalized != null)
Expand All @@ -149,7 +150,7 @@ List<AttributeExpectedValue> expected_referenceOnly_normalized_structured
outputEntityName = $"{sourceEntityName}_R_{entityFileName}";
outputEntityFileName = $"{outputEntityName}.cdm.json";
resolvedEntityDef = await srcEntityDef.CreateResolvedEntityAsync(outputEntityName, resOpt, outFolder);
await SaveActualEntityAndValidateWithExpected(Path.Combine(testExpectedPath, outputEntityFileName), resolvedEntityDef);
await SaveActualEntityAndValidateWithExpected(Path.Combine(testExpectedPath, outputEntityFileName), resolvedEntityDef, updateExpectedOutput);
}

if (expectedContext_referenceOnly_structured != null && expected_referenceOnly_structured != null)
Expand All @@ -159,7 +160,7 @@ List<AttributeExpectedValue> expected_referenceOnly_normalized_structured
outputEntityName = $"{sourceEntityName}_R_{entityFileName}";
outputEntityFileName = $"{outputEntityName}.cdm.json";
resolvedEntityDef = await srcEntityDef.CreateResolvedEntityAsync(outputEntityName, resOpt, outFolder);
await SaveActualEntityAndValidateWithExpected(Path.Combine(testExpectedPath, outputEntityFileName), resolvedEntityDef);
await SaveActualEntityAndValidateWithExpected(Path.Combine(testExpectedPath, outputEntityFileName), resolvedEntityDef, updateExpectedOutput);
}

if (expectedContext_referenceOnly_normalized_structured != null && expected_referenceOnly_normalized_structured != null)
Expand All @@ -169,7 +170,7 @@ List<AttributeExpectedValue> expected_referenceOnly_normalized_structured
outputEntityName = $"{sourceEntityName}_R_{entityFileName}";
outputEntityFileName = $"{outputEntityName}.cdm.json";
resolvedEntityDef = await srcEntityDef.CreateResolvedEntityAsync(outputEntityName, resOpt, outFolder);
await SaveActualEntityAndValidateWithExpected(Path.Combine(testExpectedPath, outputEntityFileName), resolvedEntityDef);
await SaveActualEntityAndValidateWithExpected(Path.Combine(testExpectedPath, outputEntityFileName), resolvedEntityDef, updateExpectedOutput);
}
}
catch (Exception e)
Expand All @@ -181,10 +182,14 @@ List<AttributeExpectedValue> expected_referenceOnly_normalized_structured
/// <summary>
/// Runs validation to test actual output vs expected output for attributes collection vs attribute context
/// </summary>
protected static async Task SaveActualEntityAndValidateWithExpected(string expectedPath, CdmEntityDefinition actualResolvedEntityDef)
protected static async Task SaveActualEntityAndValidateWithExpected(string expectedPath, CdmEntityDefinition actualResolvedEntityDef, bool updateExpectedOutput)
{
await actualResolvedEntityDef.InDocument.SaveAsAsync(actualResolvedEntityDef.InDocument.Name);
string actualPath = actualResolvedEntityDef.Ctx.Corpus.Storage.CorpusPathToAdapterPath(actualResolvedEntityDef.InDocument.AtCorpusPath);
if (updateExpectedOutput)
{
File.WriteAllText(expectedPath, File.ReadAllText(actualPath));
}

Assert.AreEqual( File.ReadAllText(expectedPath),
File.ReadAllText(actualPath));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class ResolutionGuidanceAddInSupportOfTest : CommonTest
[TestMethod]
public async Task TestAddInSupportOf()
{
bool updateResults = false;
string testName = "TestAddInSupportOf";
{
string entityName = "Product";
Expand Down Expand Up @@ -60,7 +61,8 @@ await RunTestWithValues(
expected_normalized_structured,
expected_referenceOnly_normalized,
expected_referenceOnly_structured,
expected_referenceOnly_normalized_structured
expected_referenceOnly_normalized_structured,
updateResults
);
}
}
Expand All @@ -71,6 +73,7 @@ await RunTestWithValues(
[TestMethod]
public async Task TestAddInSupportOfWithIsCorrelatedWith()
{
bool updateResults = false;
string testName = "TestAddInSupportOfWithIsCorrelatedWith";
{
string entityName = "Product";
Expand Down Expand Up @@ -113,7 +116,8 @@ await RunTestWithValues(
expected_normalized_structured,
expected_referenceOnly_normalized,
expected_referenceOnly_structured,
expected_referenceOnly_normalized_structured
expected_referenceOnly_normalized_structured,
updateResults
);
}
}
Expand Down
Loading