Skip to content

Commit

Permalink
Improved coverage.
Browse files Browse the repository at this point in the history
Added coverage-report.ps1
  • Loading branch information
BetimBeja committed May 9, 2021
1 parent 85ee617 commit 3ff69f0
Show file tree
Hide file tree
Showing 7 changed files with 229 additions and 6 deletions.
40 changes: 40 additions & 0 deletions XrmEntitySerializer.Tests/ParameterCollectionTests.cs
Original file line number Diff line number Diff line change
@@ -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());
}
}
}
6 changes: 2 additions & 4 deletions XrmEntitySerializer.Tests/RemoteExecutionContextTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
162 changes: 162 additions & 0 deletions XrmEntitySerializer.Tests/SampleData/RemoteExecutionContext.json
Original file line number Diff line number Diff line change
@@ -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"
}
6 changes: 6 additions & 0 deletions XrmEntitySerializer.Tests/XrmEntitySerializer.Tests.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)DecimalConverterTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ParameterCollectionTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)RemoteExecutionContextTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)KeyAttributeCollectionConverterTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)OptionSetValueConverterTests.cs" />
Expand All @@ -19,4 +20,9 @@
<Compile Include="$(MSBuildThisFileDirectory)EntityTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)GuidConverterTests.cs" />
</ItemGroup>
<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)SampleData\RemoteExecutionContext.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions XrmEntitySerializer.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions coverage-report.ps1
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions coverage.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3ff69f0

Please sign in to comment.