Skip to content

Commit

Permalink
Merge pull request #241 from delegateas/incident_update_nullreference
Browse files Browse the repository at this point in the history
FIX: Avoid NullReferenceException in incident update handler
  • Loading branch information
mkholt authored Sep 18, 2024
2 parents de30fcb + a666e94 commit 352853e
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 11 deletions.
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);
}
}
}

0 comments on commit 352853e

Please sign in to comment.