From 3ff69f0088d72a76bb248fb3e49290101c8f807e Mon Sep 17 00:00:00 2001
From: Betim Beja <11160171+BetimBeja@users.noreply.github.com>
Date: Sun, 9 May 2021 16:17:12 +0200
Subject: [PATCH 1/2] Improved coverage.
Added coverage-report.ps1
---
.../ParameterCollectionTests.cs | 40 +++++
.../RemoteExecutionContextTests.cs | 6 +-
.../SampleData/RemoteExecutionContext.json | 162 ++++++++++++++++++
.../XrmEntitySerializer.Tests.projitems | 6 +
XrmEntitySerializer.sln | 1 +
coverage-report.ps1 | 16 ++
coverage.ps1 | 4 +-
7 files changed, 229 insertions(+), 6 deletions(-)
create mode 100644 XrmEntitySerializer.Tests/ParameterCollectionTests.cs
create mode 100644 XrmEntitySerializer.Tests/SampleData/RemoteExecutionContext.json
create mode 100644 coverage-report.ps1
diff --git a/XrmEntitySerializer.Tests/ParameterCollectionTests.cs b/XrmEntitySerializer.Tests/ParameterCollectionTests.cs
new file mode 100644
index 0000000..ceedc0c
--- /dev/null
+++ b/XrmEntitySerializer.Tests/ParameterCollectionTests.cs
@@ -0,0 +1,40 @@
+using Microsoft.Xrm.Sdk;
+using Newtonsoft.Json;
+using System;
+using System.IO;
+using System.Linq;
+using Xunit;
+
+namespace XrmEntitySerializer.Tests
+{
+ public class ParameterCollectionTests
+ {
+ [Fact]
+ public void ParameterCollectionCanBeSerializedAndDeserialized()
+ {
+ ParameterCollection parameterCollection = new ParameterCollection();
+ parameterCollection.Add("Entity", new Entity("account"));
+ parameterCollection.Add("EntityReference", new EntityReference("contact", Guid.NewGuid()));
+
+ EntitySerializer serializer = new EntitySerializer();
+ serializer.TypeNameHandling = TypeNameHandling.Objects;
+ MemoryStream memoryStream = new MemoryStream(new byte[9000], true);
+
+ using (StreamWriter writer = new StreamWriter(memoryStream))
+ {
+ serializer.Serialize(new JsonTextWriter(writer), parameterCollection);
+ }
+
+ ParameterCollection deserializedParameterCollection;
+ memoryStream = new MemoryStream(memoryStream.ToArray());
+ using (StreamReader reader = new StreamReader(memoryStream))
+ {
+ deserializedParameterCollection = (ParameterCollection)serializer.Deserialize(new JsonTextReader(reader), typeof(ParameterCollection));
+ }
+
+ Assert.Equal(parameterCollection.GetType(), deserializedParameterCollection.GetType());
+ Assert.Equal(parameterCollection.Count, deserializedParameterCollection.Count);
+ Assert.Equal(parameterCollection.Keys.First(), deserializedParameterCollection.Keys.First());
+ }
+ }
+}
diff --git a/XrmEntitySerializer.Tests/RemoteExecutionContextTests.cs b/XrmEntitySerializer.Tests/RemoteExecutionContextTests.cs
index f20339f..0f48351 100644
--- a/XrmEntitySerializer.Tests/RemoteExecutionContextTests.cs
+++ b/XrmEntitySerializer.Tests/RemoteExecutionContextTests.cs
@@ -38,14 +38,12 @@ public void RemoteExecutionContextCanBeSerializedAndDeserialized()
[Fact]
public void RemoteExecutionContextCanBeDeserializedFromAzureServiceBusMessage()
{
- var input = "{ \"BusinessUnitId\": \"f0bf3c9a-8150-e811-a953-000d3af29fc0\", \"CorrelationId\": \"39499111-e689-42a1-ae8a-5b14a84514ce\", \"Depth\": 1, \"InitiatingUserId\": \"df010dad-f103-4589-ba66-76a5a04c2a11\", \"InputParameters\": [ { \"key\": \"Target\", \"value\": { \"__type\": \"Entity:http:\\/\\/schemas.microsoft.com\\/xrm\\/2011\\/Contracts\", \"Attributes\": [ { \"key\": \"telephone1\", \"value\": \"1111\" }, { \"key\": \"accountid\", \"value\": \"ec4e2f7d-9d60-e811-a95a-000d3af24950\" }, { \"key\": \"modifiedon\", \"value\": \"\\/Date(1527757524000)\\/\" }, { \"key\": \"modifiedby\", \"value\": { \"__type\": \"EntityReference:http:\\/\\/schemas.microsoft.com\\/xrm\\/2011\\/Contracts\", \"Id\": \"df010dad-f103-4589-ba66-76a5a04c2a11\", \"KeyAttributes\": [], \"LogicalName\": \"systemuser\", \"Name\": null, \"RowVersion\": null } }, { \"key\": \"modifiedonbehalfby\", \"value\": null } ], \"EntityState\": null, \"FormattedValues\": [], \"Id\": \"ec4e2f7d-9d60-e811-a95a-000d3af24950\", \"KeyAttributes\": [], \"LogicalName\": \"account\", \"RelatedEntities\": [], \"RowVersion\": null } } ], \"IsExecutingOffline\": false, \"IsInTransaction\": true, \"IsOfflinePlayback\": false, \"IsolationMode\": 1, \"MessageName\": \"Update\", \"Mode\": 0, \"OperationCreatedOn\": \"\\/Date(1527757530151)\\/\", \"OperationId\": \"08fec203-ec78-4f7a-a024-c96e329a64fe\", \"OrganizationId\": \"b0714265-8e72-4d3b-8239-ecf0970a3da6\", \"OrganizationName\": \"org94971a24\", \"OutputParameters\": [], \"OwningExtension\": { \"Id\": \"3db800fe-0963-e811-a95a-000d3af24324\", \"KeyAttributes\": [], \"LogicalName\": \"sdkmessageprocessingstep\", \"Name\": \"D365WebHookHttpTrigger: Update of account\", \"RowVersion\": null }, \"ParentContext\": { \"BusinessUnitId\": \"f0bf3c9a-8150-e811-a953-000d3af29fc0\", \"CorrelationId\": \"39499111-e689-42a1-ae8a-5b14a84514ce\", \"Depth\": 1, \"InitiatingUserId\": \"df010dad-f103-4589-ba66-76a5a04c2a11\", \"InputParameters\": [ { \"key\": \"Target\", \"value\": { \"__type\": \"Entity:http:\\/\\/schemas.microsoft.com\\/xrm\\/2011\\/Contracts\", \"Attributes\": [ { \"key\": \"telephone1\", \"value\": \"1111\" }, { \"key\": \"accountid\", \"value\": \"ec4e2f7d-9d60-e811-a95a-000d3af24950\" } ], \"EntityState\": null, \"FormattedValues\": [], \"Id\": \"ec4e2f7d-9d60-e811-a95a-000d3af24950\", \"KeyAttributes\": [], \"LogicalName\": \"account\", \"RelatedEntities\": [], \"RowVersion\": null } }, { \"key\": \"SuppressDuplicateDetection\", \"value\": false } ], \"IsExecutingOffline\": false, \"IsInTransaction\": true, \"IsOfflinePlayback\": false, \"IsolationMode\": 1, \"MessageName\": \"Update\", \"Mode\": 0, \"OperationCreatedOn\": \"\\/Date(1527757524631)\\/\", \"OperationId\": \"08fec203-ec78-4f7a-a024-c96e329a64fe\", \"OrganizationId\": \"b0714265-8e72-4d3b-8239-ecf0970a3da6\", \"OrganizationName\": \"org94971a24\", \"OutputParameters\": [], \"OwningExtension\": { \"Id\": \"63cdbb1b-ea3e-db11-86a7-000a3a5473e8\", \"KeyAttributes\": [], \"LogicalName\": \"sdkmessageprocessingstep\", \"Name\": \"ObjectModel Implementation\", \"RowVersion\": null }, \"ParentContext\": null, \"PostEntityImages\": [], \"PreEntityImages\": [], \"PrimaryEntityId\": \"ec4e2f7d-9d60-e811-a95a-000d3af24950\", \"PrimaryEntityName\": \"account\", \"RequestId\": \"08fec203-ec78-4f7a-a024-c96e329a64fe\", \"SecondaryEntityName\": \"none\", \"SharedVariables\": [ { \"key\": \"ChangedEntityTypes\", \"value\": [ { \"__type\": \"KeyValuePairOfstringstring:#System.Collections.Generic\", \"key\": \"account\", \"value\": \"Update\" } ] } ], \"Stage\": 30, \"UserId\": \"df010dad-f103-4589-ba66-76a5a04c2a11\" }, \"PostEntityImages\": [], \"PreEntityImages\": [], \"PrimaryEntityId\": \"ec4e2f7d-9d60-e811-a95a-000d3af24950\", \"PrimaryEntityName\": \"account\", \"RequestId\": \"08fec203-ec78-4f7a-a024-c96e329a64fe\", \"SecondaryEntityName\": \"none\", \"SharedVariables\": [], \"Stage\": 40, \"UserId\": \"df010dad-f103-4589-ba66-76a5a04c2a11\"}";
-
EntitySerializer serializer = new EntitySerializer();
MemoryStream memoryStream = new MemoryStream(new byte[9000], true);
-
+ using(StreamReader reader = new StreamReader("SampleData\\RemoteExecutionContext.json"))
using (StreamWriter writer = new StreamWriter(memoryStream))
{
- writer.Write(input);
+ writer.Write(reader.ReadToEnd());
}
RemoteExecutionContext deserializedExecutionContext;
diff --git a/XrmEntitySerializer.Tests/SampleData/RemoteExecutionContext.json b/XrmEntitySerializer.Tests/SampleData/RemoteExecutionContext.json
new file mode 100644
index 0000000..1864277
--- /dev/null
+++ b/XrmEntitySerializer.Tests/SampleData/RemoteExecutionContext.json
@@ -0,0 +1,162 @@
+{
+ "BusinessUnitId": "f0bf3c9a-8150-e811-a953-000d3af29fc0",
+ "CorrelationId": "39499111-e689-42a1-ae8a-5b14a84514ce",
+ "Depth": 1,
+ "InitiatingUserId": "df010dad-f103-4589-ba66-76a5a04c2a11",
+ "InputParameters": [
+ {
+ "key": "Target",
+ "value": {
+ "__type": "Entity:http:\/\/schemas.microsoft.com\/xrm\/2011\/Contracts",
+ "Attributes": [
+ {
+ "key": "telephone1",
+ "value": "1111"
+ },
+ {
+ "key": "accountid",
+ "value": "ec4e2f7d-9d60-e811-a95a-000d3af24950"
+ },
+ {
+ "key": "modifiedon",
+ "value": "\/Date(1527757524000)\/"
+ },
+ {
+ "key": "modifiedby",
+ "value": {
+ "__type": "EntityReference:http:\/\/schemas.microsoft.com\/xrm\/2011\/Contracts",
+ "Id": "df010dad-f103-4589-ba66-76a5a04c2a11",
+ "KeyAttributes": [],
+ "LogicalName": "systemuser",
+ "Name": null,
+ "RowVersion": null
+ }
+ },
+ {
+ "key": "modifiedonbehalfby",
+ "value": null
+ }
+ ],
+ "EntityState": null,
+ "FormattedValues": [],
+ "Id": "ec4e2f7d-9d60-e811-a95a-000d3af24950",
+ "KeyAttributes": [],
+ "LogicalName": "account",
+ "RelatedEntities": [],
+ "RowVersion": null
+ }
+ },
+ {
+ "key": "TargetReference",
+ "value": {
+ "__type": "EntityReference:http:\/\/schemas.microsoft.com\/xrm\/2011\/Contracts",
+ "Id": "df010dad-f103-4589-ba66-76a5a04c2a11",
+ "KeyAttributes": [],
+ "LogicalName": "systemuser",
+ "Name": null,
+ "RowVersion": null
+ }
+ }
+ ],
+ "IsExecutingOffline": false,
+ "IsInTransaction": true,
+ "IsOfflinePlayback": false,
+ "IsolationMode": 1,
+ "MessageName": "Update",
+ "Mode": 0,
+ "OperationCreatedOn": "\/Date(1527757530151)\/",
+ "OperationId": "08fec203-ec78-4f7a-a024-c96e329a64fe",
+ "OrganizationId": "b0714265-8e72-4d3b-8239-ecf0970a3da6",
+ "OrganizationName": "org94971a24",
+ "OutputParameters": [],
+ "OwningExtension": {
+ "Id": "3db800fe-0963-e811-a95a-000d3af24324",
+ "KeyAttributes": [],
+ "LogicalName": "sdkmessageprocessingstep",
+ "Name": "D365WebHookHttpTrigger: Update of account",
+ "RowVersion": null
+ },
+ "ParentContext": {
+ "BusinessUnitId": "f0bf3c9a-8150-e811-a953-000d3af29fc0",
+ "CorrelationId": "39499111-e689-42a1-ae8a-5b14a84514ce",
+ "Depth": 1,
+ "InitiatingUserId": "df010dad-f103-4589-ba66-76a5a04c2a11",
+ "InputParameters": [
+ {
+ "key": "Target",
+ "value": {
+ "__type": "Entity:http:\/\/schemas.microsoft.com\/xrm\/2011\/Contracts",
+ "Attributes": [
+ {
+ "key": "telephone1",
+ "value": "1111"
+ },
+ {
+ "key": "accountid",
+ "value": "ec4e2f7d-9d60-e811-a95a-000d3af24950"
+ }
+ ],
+ "EntityState": null,
+ "FormattedValues": [],
+ "Id": "ec4e2f7d-9d60-e811-a95a-000d3af24950",
+ "KeyAttributes": [],
+ "LogicalName": "account",
+ "RelatedEntities": [],
+ "RowVersion": null
+ }
+ },
+ {
+ "key": "SuppressDuplicateDetection",
+ "value": false
+ }
+ ],
+ "IsExecutingOffline": false,
+ "IsInTransaction": true,
+ "IsOfflinePlayback": false,
+ "IsolationMode": 1,
+ "MessageName": "Update",
+ "Mode": 0,
+ "OperationCreatedOn": "\/Date(1527757524631)\/",
+ "OperationId": "08fec203-ec78-4f7a-a024-c96e329a64fe",
+ "OrganizationId": "b0714265-8e72-4d3b-8239-ecf0970a3da6",
+ "OrganizationName": "org94971a24",
+ "OutputParameters": [],
+ "OwningExtension": {
+ "Id": "63cdbb1b-ea3e-db11-86a7-000a3a5473e8",
+ "KeyAttributes": [],
+ "LogicalName": "sdkmessageprocessingstep",
+ "Name": "ObjectModel Implementation",
+ "RowVersion": null
+ },
+ "ParentContext": null,
+ "PostEntityImages": [],
+ "PreEntityImages": [],
+ "PrimaryEntityId": "ec4e2f7d-9d60-e811-a95a-000d3af24950",
+ "PrimaryEntityName": "account",
+ "RequestId": "08fec203-ec78-4f7a-a024-c96e329a64fe",
+ "SecondaryEntityName": "none",
+ "SharedVariables": [
+ {
+ "key": "ChangedEntityTypes",
+ "value": [
+ {
+ "__type": "KeyValuePairOfstringstring:#System.Collections.Generic",
+ "key": "account",
+ "value": "Update"
+ }
+ ]
+ }
+ ],
+ "Stage": 30,
+ "UserId": "df010dad-f103-4589-ba66-76a5a04c2a11"
+ },
+ "PostEntityImages": [],
+ "PreEntityImages": [],
+ "PrimaryEntityId": "ec4e2f7d-9d60-e811-a95a-000d3af24950",
+ "PrimaryEntityName": "account",
+ "RequestId": "08fec203-ec78-4f7a-a024-c96e329a64fe",
+ "SecondaryEntityName": "none",
+ "SharedVariables": [],
+ "Stage": 40,
+ "UserId": "df010dad-f103-4589-ba66-76a5a04c2a11"
+}
\ No newline at end of file
diff --git a/XrmEntitySerializer.Tests/XrmEntitySerializer.Tests.projitems b/XrmEntitySerializer.Tests/XrmEntitySerializer.Tests.projitems
index d7a5a42..0819937 100644
--- a/XrmEntitySerializer.Tests/XrmEntitySerializer.Tests.projitems
+++ b/XrmEntitySerializer.Tests/XrmEntitySerializer.Tests.projitems
@@ -10,6 +10,7 @@
+
@@ -19,4 +20,9 @@
+
+
+ PreserveNewest
+
+
\ No newline at end of file
diff --git a/XrmEntitySerializer.sln b/XrmEntitySerializer.sln
index fd094d3..b07c086 100644
--- a/XrmEntitySerializer.sln
+++ b/XrmEntitySerializer.sln
@@ -36,6 +36,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
ProjectSection(SolutionItems) = preProject
azure-pipelines.yml = azure-pipelines.yml
.github\workflows\build-and-test.yml = .github\workflows\build-and-test.yml
+ coverage-report.ps1 = coverage-report.ps1
coverage.ps1 = coverage.ps1
Logo_80x80.png = Logo_80x80.png
README.md = README.md
diff --git a/coverage-report.ps1 b/coverage-report.ps1
new file mode 100644
index 0000000..8cb2826
--- /dev/null
+++ b/coverage-report.ps1
@@ -0,0 +1,16 @@
+& .\coverage.ps1
+
+IF(!(Test-Path .coverage\ReportGenerator* -PathType Container))
+{
+ & nuget install ReportGenerator -OutputDirectory .coverage
+}
+
+$ReportGenerator=Get-ChildItem -Path $((Get-ChildItem -Path .coverage\ReportGenerator* | Sort-Object -Descending | Select-Object -First 1).FullName)tools\net47\ReportGenerator.exe
+
+If($ReportGenerator -eq ''){
+ throw "Could not find ReportGenerator. Make sure to restore NuGet packages"
+}
+
+& $ReportGenerator -reports:".coverage\XrmEntitySerializer.5.net40.xml;.coverage\XrmEntitySerializer.6.net40.xml;.coverage\XrmEntitySerializer.7.net452.xml;.coverage\XrmEntitySerializer.8.net452.xml;.coverage\XrmEntitySerializer.9.net452.xml;.coverage\XrmEntitySerializer.9.net462.xml;.coverage\XrmEntitySerializer.core.net5.0.xml;.coverage\XrmEntitySerializer.core.netcoreapp3.0.xml;.coverage\XrmEntitySerializer.core.netcoreapp3.1.xml" -targetdir:".coverage\report" -reporttypes:"html"
+
+Start-Process .coverage\report\index.htm
diff --git a/coverage.ps1 b/coverage.ps1
index c319418..2a826b3 100644
--- a/coverage.ps1
+++ b/coverage.ps1
@@ -6,11 +6,11 @@ If(!(test-path $path -PathType Container ))
IF(!(Test-Path .coverage\OpenCover* -PathType Container))
{
-Install-Package -Name OpenCover -ProviderName NuGet -Scope CurrentUser -Destination $path -SkipDependencies -Force
+ & nuget install OpenCover -OutputDirectory $path
}
IF(!(Test-Path .coverage\xunit.runner.console* -PathType Container))
{
-Install-Package -Name xunit.runner.console -ProviderName NuGet -Scope CurrentUser -Destination $path -SkipDependencies -Force
+ & nuget install xunit.runner.console -OutputDirectory $path
}
$DotNet=(Get-Command dotnet).Source
From 940759e211a329913e7435f6c2b9bf6a1d8971e1 Mon Sep 17 00:00:00 2001
From: Betim Beja <11160171+BetimBeja@users.noreply.github.com>
Date: Sun, 9 May 2021 16:28:39 +0200
Subject: [PATCH 2/2] Updated Readme.md
---
README.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/README.md b/README.md
index 92c4a71..c14cafd 100644
--- a/README.md
+++ b/README.md
@@ -6,6 +6,7 @@
|Package|NuGet|
|------------|------------|
+|XrmEntitySerializer.Core|[![XrmEntitySerializer.Core](https://buildstats.info/nuget/xrmentityserializer.Core)](https://www.nuget.org/packages/XrmEntitySerializer.Core)|
|XrmEntitySerializer.9|[![XrmEntitySerializer.9](https://buildstats.info/nuget/xrmentityserializer.9)](https://www.nuget.org/packages/XrmEntitySerializer.9)|
|XrmEntitySerializer.8|[![XrmEntitySerializer.8](https://buildstats.info/nuget/xrmentityserializer.8)](https://www.nuget.org/packages/XrmEntitySerializer.8)|
|XrmEntitySerializer.7|[![XrmEntitySerializer.7](https://buildstats.info/nuget/xrmentityserializer.7)](https://www.nuget.org/packages/XrmEntitySerializer.7)|