Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Avoid NullReferenceException in incident update handler #241

Merged
merged 1 commit into from
Sep 18, 2024
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### 1.13.1 - 18 September 2024
* Fix: An update request of Incident without a StateCode would throw NullReferenceException (@mkholt)

### 1.13.0 - 18 September 2024
* Add support for .NET8 (@mkholt)
* Remove support for versions older than 9 (365) (@mkholt)
Expand Down
8 changes: 4 additions & 4 deletions src/MetadataGen/MetadataGenerator365/AssemblyInfo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ using System.Reflection;
[assembly: AssemblyDescription("A simulation engine that can mock a specific MS CRM instance. Useful for testing and debugging business logic.")]
[assembly: AssemblyCompany("Delegate A/S")]
[assembly: AssemblyCopyright("Copyright (c) Delegate A/S 2017")]
[assembly: AssemblyVersion("1.13.0")]
[assembly: AssemblyFileVersion("1.13.0")]
[assembly: AssemblyVersion("1.13.1")]
[assembly: AssemblyFileVersion("1.13.1")]
namespace System {
internal static class AssemblyVersionInformation {
internal const System.String AssemblyTitle = "XrmMockup";
internal const System.String AssemblyProduct = "XrmMockup";
internal const System.String AssemblyDescription = "A simulation engine that can mock a specific MS CRM instance. Useful for testing and debugging business logic.";
internal const System.String AssemblyCompany = "Delegate A/S";
internal const System.String AssemblyCopyright = "Copyright (c) Delegate A/S 2017";
internal const System.String AssemblyVersion = "1.13.0";
internal const System.String AssemblyFileVersion = "1.13.0";
internal const System.String AssemblyVersion = "1.13.1";
internal const System.String AssemblyFileVersion = "1.13.1";
}
}
8 changes: 4 additions & 4 deletions src/XrmMockup365/AssemblyInfo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ using System.Reflection;
[assembly: AssemblyDescription("A simulation engine that can mock a specific MS CRM instance. Useful for testing and debugging business logic.")]
[assembly: AssemblyCompany("Delegate A/S")]
[assembly: AssemblyCopyright("Copyright (c) Delegate A/S 2017")]
[assembly: AssemblyVersion("1.13.0")]
[assembly: AssemblyFileVersion("1.13.0")]
[assembly: AssemblyVersion("1.13.1")]
[assembly: AssemblyFileVersion("1.13.1")]
namespace System {
internal static class AssemblyVersionInformation {
internal const System.String AssemblyTitle = "XrmMockup";
internal const System.String AssemblyProduct = "XrmMockup";
internal const System.String AssemblyDescription = "A simulation engine that can mock a specific MS CRM instance. Useful for testing and debugging business logic.";
internal const System.String AssemblyCompany = "Delegate A/S";
internal const System.String AssemblyCopyright = "Copyright (c) Delegate A/S 2017";
internal const System.String AssemblyVersion = "1.13.0";
internal const System.String AssemblyFileVersion = "1.13.0";
internal const System.String AssemblyVersion = "1.13.1";
internal const System.String AssemblyFileVersion = "1.13.1";
}
}
2 changes: 2 additions & 0 deletions src/XrmMockup365/XrmMockup365.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
<RepositoryUrl>https://github.com/delegateas/XrmMockup</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<Optimize>false</Optimize>
Expand Down
7 changes: 4 additions & 3 deletions src/XrmMockupShared/Requests/UpdateRequestHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ internal override OrganizationResponse Execute(OrganizationRequest orgRequest, E
var request = MakeRequest<UpdateRequest>(orgRequest);
var settings = MockupExecutionContext.GetSettings(request);

if (request.Target.LogicalName is "incident" &&
request.Target.GetAttributeValue<OptionSetValue>("statecode").Value is 1 &&
!request.Parameters.ContainsKey("CloseIncidentRequestHandler"))
if (request.Target.LogicalName is "incident"
&& !request.Parameters.ContainsKey("CloseIncidentRequestHandler")
&& request.Target.TryGetAttributeValue<OptionSetValue>("statecode", out var stateCode)
&& stateCode.Value is 1)
{
throw new FaultException("This message can not be used to set the state of incident to Resolved. In order to set state of incident to Resolved, use the CloseIncidentRequest message instead.");
}
Expand Down
17 changes: 17 additions & 0 deletions tests/SharedTests/TestIncident.cs
Original file line number Diff line number Diff line change
Expand Up @@ -536,5 +536,22 @@ public void TestUpdateIncidentAsResolvedFails()

Assert.Throws<FaultException>(() => orgAdminService.Update(incident));
}

[Fact]
public void TestCanUpdateOpenIncident()
{
var incident = new Incident
{
Description = nameof(TestCanUpdateOpenIncident)
};

incident.Id = orgAdminUIService.Create(incident);

incident.Description = "Updated description";
orgAdminService.Update(incident);

var retrievedIncident = Incident.Retrieve(orgAdminService, incident.Id);
Assert.Equal("Updated description", retrievedIncident.Description);
}
}
}