Skip to content
Open
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
7 changes: 6 additions & 1 deletion src/XrmMockup365/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,12 @@ private OrganizationResponse ExecuteRequest(
var handler = RequestHandlers.FirstOrDefault(x => x.HandlesRequest(request.RequestName));
if (handler != null)
{
return handler.Execute(request, userRef);
var response = handler.Execute(request, userRef);
if (response != null && string.IsNullOrEmpty(response.ResponseName))
{
response.ResponseName = request.RequestName;
}
return response;
}

if (settings.ExceptionFreeRequests?.Contains(request.RequestName) ?? false)
Expand Down
55 changes: 55 additions & 0 deletions src/XrmMockup365/Internal/Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,61 @@
var newCollection = new OptionSetValueCollection(typed.Values.Select(x => new OptionSetValue(x)).ToList());
return newCollection;
}
else if (type == typeof(EntityCollection))
{
var node = JsonNode.Parse(colToSerialize.Value);
var typed = (EntityCollectionDTO)node.Deserialize(typeof(EntityCollectionDTO));

// Manually deserialize entities
var entities = new List<Entity>();
if (typed.Entities.ValueKind == JsonValueKind.Array)
{
foreach (var entityElement in typed.Entities.EnumerateArray())
{
var entity = new Entity();

// Deserialize LogicalName
if (entityElement.TryGetProperty("LogicalName", out var logicalNameProp))
{
entity.LogicalName = logicalNameProp.GetString();
}

// Deserialize Id
if (entityElement.TryGetProperty("Id", out var idProp) && idProp.ValueKind == JsonValueKind.String)
{
entity.Id = Guid.Parse(idProp.GetString());
}

// Deserialize Attributes
if (entityElement.TryGetProperty("Attributes", out var attributesProp) && attributesProp.ValueKind == JsonValueKind.Array)
{
foreach (var attr in attributesProp.EnumerateArray())
{
if (attr.TryGetProperty("Key", out var keyProp) && attr.TryGetProperty("Value", out var valueProp))
{
var key = keyProp.GetString();
// Recursively deserialize attribute values (could be EntityReference, etc.)
var value = JsonSerializer.Deserialize<object>(valueProp.GetRawText());
entity[key] = value;
}
}
}

entities.Add(entity);
}
}

var newCollection = new EntityCollection(entities)
{
MoreRecords = typed.MoreRecords,
PagingCookie = typed.PagingCookie,
MinActiveRowVersion = typed.MinActiveRowVersion,
TotalRecordCount = typed.TotalRecordCount,
TotalRecordCountLimitExceeded = typed.TotalRecordCountLimitExceeded,
EntityName = typed.EntityName
};
return newCollection;
}
else if (type == typeof(BooleanManagedProperty))
{
var node = JsonNode.Parse(colToSerialize.Value);
Expand Down Expand Up @@ -1179,7 +1234,7 @@
}

[DataContract()]
internal enum componentstate

Check warning on line 1237 in src/XrmMockup365/Internal/Utility.cs

View workflow job for this annotation

GitHub Actions / run-ci

The type name 'componentstate' only contains lower-cased ascii characters. Such names may become reserved for the language.
{

[EnumMember()]
Expand Down
16 changes: 16 additions & 0 deletions src/XrmMockup365/Serialization/EntityCollectionDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Collections.Generic;
using System.Text.Json;

namespace DG.Tools.XrmMockup.Serialization
{
public class EntityCollectionDTO
{
public JsonElement Entities { get; set; }
public bool MoreRecords { get; set; }
public string PagingCookie { get; set; }
public string MinActiveRowVersion { get; set; }
public int TotalRecordCount { get; set; }
public bool TotalRecordCountLimitExceeded { get; set; }
public string EntityName { get; set; }
}
}
Loading