Skip to content

Commit

Permalink
Merge pull request #86 from DynamicsValue/feature/26-updates
Browse files Browse the repository at this point in the history
2.6.x
  • Loading branch information
jordimontana82 authored Aug 2, 2024
2 parents 7177f4d + f0dadc2 commit 42711a6
Show file tree
Hide file tree
Showing 25 changed files with 11,297 additions and 185 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
## [2.6.0]

### Added

- Added default max file size for file and image uploads - https://github.com/DynamicsValue/fake-xrm-easy/issues/157

### Changed

- Resolves issue in MetadataGenerator where relationship properties were generated in the wrong order, also generates ManyToMany relationship properties - https://github.com/DynamicsValue/fake-xrm-easy/issues/135
- Adds implementation of RelatedEntities in Update message , before it was implemented only for Create - https://github.com/DynamicsValue/fake-xrm-easy/issues/154

## [2.5.1]

### Changed
Expand Down
88 changes: 60 additions & 28 deletions src/FakeXrmEasy.Core/Extensions/EntityExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -367,28 +367,78 @@ public static Entity Clone(this Entity e, IXrmFakedContext context = null)
cloned.Id = e.Id;
cloned.LogicalName = e.LogicalName;

if (e.FormattedValues != null)
CloneEntity(e, cloned, context);

return cloned;
}

/// <summary>
/// Clones source entity data into cloned entity
/// </summary>
/// <param name="source"></param>
/// <param name="cloned"></param>
/// <param name="context">The IXrmFakedContext where the source Entity lives, if any</param>
internal static void CloneEntity(Entity source, Entity cloned, IXrmFakedContext context = null)
{
if (source.FormattedValues != null)
{
var formattedValues = new FormattedValueCollection();
foreach (var key in e.FormattedValues.Keys)
formattedValues.Add(key, e.FormattedValues[key]);
foreach (var key in source.FormattedValues.Keys)
formattedValues.Add(key, source.FormattedValues[key]);

cloned.Inject("FormattedValues", formattedValues);
}

foreach (var attKey in e.Attributes.Keys)
foreach (var attKey in source.Attributes.Keys)
{
cloned[attKey] = e[attKey] != null ? CloneAttribute(e[attKey], context) : null;
cloned[attKey] = source[attKey] != null ? CloneAttribute(source[attKey], context) : null;
}
#if !FAKE_XRM_EASY && !FAKE_XRM_EASY_2013 && !FAKE_XRM_EASY_2015
foreach (var attKey in e.KeyAttributes.Keys)
foreach (var attKey in source.KeyAttributes.Keys)
{
cloned.KeyAttributes[attKey] = e.KeyAttributes[attKey] != null ? CloneAttribute(e.KeyAttributes[attKey]) : null;
cloned.KeyAttributes[attKey] = source.KeyAttributes[attKey] != null ? CloneAttribute(source.KeyAttributes[attKey]) : null;
}
#endif
return cloned;
foreach (var relatedEntityKeyValuePair in source.RelatedEntities)
{
var relationShip = CloneRelationship(relatedEntityKeyValuePair.Key);
var newKeyValuePair = new KeyValuePair<Relationship, EntityCollection>(relationShip,
CloneEntityCollection(relatedEntityKeyValuePair.Value));
cloned.RelatedEntities.Add(newKeyValuePair);
}
}

/// <summary>
/// Clones an entire EntityCollection
/// </summary>
/// <param name="entityCollection">The source entity collection to clone</param>
/// <param name="context">A reference to an in-memory context</param>
/// <returns></returns>
internal static EntityCollection CloneEntityCollection(EntityCollection entityCollection, IXrmFakedContext context = null)
{
var listOfClones = new List<Entity>();

foreach (var source in entityCollection.Entities)
{
listOfClones.Add(source.Clone(context));
}

return new EntityCollection(listOfClones);
}

/// <summary>
/// Clones an existing relationship object
/// </summary>
/// <param name="relationShip"></param>
/// <returns></returns>
internal static Relationship CloneRelationship(Relationship relationShip)
{
return new Relationship(relationShip.SchemaName)
{
PrimaryEntityRole = relationShip.PrimaryEntityRole
};
}

/// <summary>
///
/// </summary>
Expand Down Expand Up @@ -416,26 +466,8 @@ public static Entity Clone(this Entity e, Type t, IXrmFakedContext context = nul
cloned.Id = e.Id;
cloned.LogicalName = e.LogicalName;

if (e.FormattedValues != null)
{
var formattedValues = new FormattedValueCollection();
foreach (var key in e.FormattedValues.Keys)
formattedValues.Add(key, e.FormattedValues[key]);

cloned.Inject("FormattedValues", formattedValues);
}

foreach (var attKey in e.Attributes.Keys)
{
cloned[attKey] = e[attKey] != null ? CloneAttribute(e[attKey], context) : null;
}

#if !FAKE_XRM_EASY && !FAKE_XRM_EASY_2013 && !FAKE_XRM_EASY_2015
foreach (var attKey in e.KeyAttributes.Keys)
{
cloned.KeyAttributes[attKey] = e.KeyAttributes[attKey] != null ? CloneAttribute(e.KeyAttributes[attKey]) : null;
}
#endif
CloneEntity(e, cloned, context);

return cloned;
}

Expand Down
12 changes: 12 additions & 0 deletions src/FakeXrmEasy.Core/Extensions/PropertyInfoExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Reflection;

namespace FakeXrmEasy.Core.Extensions
{
internal static class PropertyInfoExtensions
{
internal static bool IsEnumerable(this PropertyInfo propertyInfo)
{
return propertyInfo.PropertyType.Name == "IEnumerable`1";
}
}
}
7 changes: 7 additions & 0 deletions src/FakeXrmEasy.Core/Extensions/TypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,12 @@ public static PropertyInfo GetEarlyBoundTypeAttribute(this Type earlyBoundType,

return attributeInfo;
}

public static string GetPrimaryIdFieldName(this Type earlyBoundType)

Check warning on line 110 in src/FakeXrmEasy.Core/Extensions/TypeExtensions.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_2016)

Missing XML comment for publicly visible type or member 'TypeExtensions.GetPrimaryIdFieldName(Type)'

Check warning on line 110 in src/FakeXrmEasy.Core/Extensions/TypeExtensions.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_2016)

Missing XML comment for publicly visible type or member 'TypeExtensions.GetPrimaryIdFieldName(Type)'

Check warning on line 110 in src/FakeXrmEasy.Core/Extensions/TypeExtensions.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_2013)

Missing XML comment for publicly visible type or member 'TypeExtensions.GetPrimaryIdFieldName(Type)'

Check warning on line 110 in src/FakeXrmEasy.Core/Extensions/TypeExtensions.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_2013)

Missing XML comment for publicly visible type or member 'TypeExtensions.GetPrimaryIdFieldName(Type)'

Check warning on line 110 in src/FakeXrmEasy.Core/Extensions/TypeExtensions.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_9)

Missing XML comment for publicly visible type or member 'TypeExtensions.GetPrimaryIdFieldName(Type)'

Check warning on line 110 in src/FakeXrmEasy.Core/Extensions/TypeExtensions.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_9)

Missing XML comment for publicly visible type or member 'TypeExtensions.GetPrimaryIdFieldName(Type)'

Check warning on line 110 in src/FakeXrmEasy.Core/Extensions/TypeExtensions.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_2015)

Missing XML comment for publicly visible type or member 'TypeExtensions.GetPrimaryIdFieldName(Type)'

Check warning on line 110 in src/FakeXrmEasy.Core/Extensions/TypeExtensions.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_2015)

Missing XML comment for publicly visible type or member 'TypeExtensions.GetPrimaryIdFieldName(Type)'

Check warning on line 110 in src/FakeXrmEasy.Core/Extensions/TypeExtensions.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_365)

Missing XML comment for publicly visible type or member 'TypeExtensions.GetPrimaryIdFieldName(Type)'

Check warning on line 110 in src/FakeXrmEasy.Core/Extensions/TypeExtensions.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_365)

Missing XML comment for publicly visible type or member 'TypeExtensions.GetPrimaryIdFieldName(Type)'

Check warning on line 110 in src/FakeXrmEasy.Core/Extensions/TypeExtensions.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY)

Missing XML comment for publicly visible type or member 'TypeExtensions.GetPrimaryIdFieldName(Type)'

Check warning on line 110 in src/FakeXrmEasy.Core/Extensions/TypeExtensions.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY)

Missing XML comment for publicly visible type or member 'TypeExtensions.GetPrimaryIdFieldName(Type)'

Check warning on line 110 in src/FakeXrmEasy.Core/Extensions/TypeExtensions.cs

View workflow job for this annotation

GitHub Actions / pack-push

Missing XML comment for publicly visible type or member 'TypeExtensions.GetPrimaryIdFieldName(Type)'

Check warning on line 110 in src/FakeXrmEasy.Core/Extensions/TypeExtensions.cs

View workflow job for this annotation

GitHub Actions / pack-push

Missing XML comment for publicly visible type or member 'TypeExtensions.GetPrimaryIdFieldName(Type)'

Check warning on line 110 in src/FakeXrmEasy.Core/Extensions/TypeExtensions.cs

View workflow job for this annotation

GitHub Actions / pack-push

Missing XML comment for publicly visible type or member 'TypeExtensions.GetPrimaryIdFieldName(Type)'

Check warning on line 110 in src/FakeXrmEasy.Core/Extensions/TypeExtensions.cs

View workflow job for this annotation

GitHub Actions / pack-push

Missing XML comment for publicly visible type or member 'TypeExtensions.GetPrimaryIdFieldName(Type)'

Check warning on line 110 in src/FakeXrmEasy.Core/Extensions/TypeExtensions.cs

View workflow job for this annotation

GitHub Actions / pack-push

Missing XML comment for publicly visible type or member 'TypeExtensions.GetPrimaryIdFieldName(Type)'

Check warning on line 110 in src/FakeXrmEasy.Core/Extensions/TypeExtensions.cs

View workflow job for this annotation

GitHub Actions / pack-push

Missing XML comment for publicly visible type or member 'TypeExtensions.GetPrimaryIdFieldName(Type)'
{
return earlyBoundType.GetProperties()
.FirstOrDefault(p => p.Name == "Id")
.GetCustomAttribute<AttributeLogicalNameAttribute>().LogicalName;
}
}
}
2 changes: 1 addition & 1 deletion src/FakeXrmEasy.Core/FakeXrmEasy.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<TargetFrameworks Condition="'$(Configuration)'=='FAKE_XRM_EASY_2013'">net452</TargetFrameworks>
<TargetFrameworks Condition="'$(Configuration)'=='FAKE_XRM_EASY'">net452</TargetFrameworks>
<PackageId>FakeXrmEasy.Core</PackageId>
<VersionPrefix>2.5.1</VersionPrefix>
<VersionPrefix>2.6.0</VersionPrefix>
<Authors>Jordi Montaña</Authors>
<Company>Dynamics Value</Company>
<Title>FakeXrmEasy Core</Title>
Expand Down
54 changes: 54 additions & 0 deletions src/FakeXrmEasy.Core/FileStorage/FileStorageSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
namespace FakeXrmEasy.Core.FileStorage
{
public interface IFileStorageSettings

Check warning on line 3 in src/FakeXrmEasy.Core/FileStorage/FileStorageSettings.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_2016)

Missing XML comment for publicly visible type or member 'IFileStorageSettings'

Check warning on line 3 in src/FakeXrmEasy.Core/FileStorage/FileStorageSettings.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_2016)

Missing XML comment for publicly visible type or member 'IFileStorageSettings'

Check warning on line 3 in src/FakeXrmEasy.Core/FileStorage/FileStorageSettings.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_2013)

Missing XML comment for publicly visible type or member 'IFileStorageSettings'

Check warning on line 3 in src/FakeXrmEasy.Core/FileStorage/FileStorageSettings.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_2013)

Missing XML comment for publicly visible type or member 'IFileStorageSettings'

Check warning on line 3 in src/FakeXrmEasy.Core/FileStorage/FileStorageSettings.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_9)

Missing XML comment for publicly visible type or member 'IFileStorageSettings'

Check warning on line 3 in src/FakeXrmEasy.Core/FileStorage/FileStorageSettings.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_9)

Missing XML comment for publicly visible type or member 'IFileStorageSettings'

Check warning on line 3 in src/FakeXrmEasy.Core/FileStorage/FileStorageSettings.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_2015)

Missing XML comment for publicly visible type or member 'IFileStorageSettings'

Check warning on line 3 in src/FakeXrmEasy.Core/FileStorage/FileStorageSettings.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_2015)

Missing XML comment for publicly visible type or member 'IFileStorageSettings'

Check warning on line 3 in src/FakeXrmEasy.Core/FileStorage/FileStorageSettings.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_365)

Missing XML comment for publicly visible type or member 'IFileStorageSettings'

Check warning on line 3 in src/FakeXrmEasy.Core/FileStorage/FileStorageSettings.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_365)

Missing XML comment for publicly visible type or member 'IFileStorageSettings'

Check warning on line 3 in src/FakeXrmEasy.Core/FileStorage/FileStorageSettings.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY)

Missing XML comment for publicly visible type or member 'IFileStorageSettings'

Check warning on line 3 in src/FakeXrmEasy.Core/FileStorage/FileStorageSettings.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY)

Missing XML comment for publicly visible type or member 'IFileStorageSettings'

Check warning on line 3 in src/FakeXrmEasy.Core/FileStorage/FileStorageSettings.cs

View workflow job for this annotation

GitHub Actions / pack-push

Missing XML comment for publicly visible type or member 'IFileStorageSettings'

Check warning on line 3 in src/FakeXrmEasy.Core/FileStorage/FileStorageSettings.cs

View workflow job for this annotation

GitHub Actions / pack-push

Missing XML comment for publicly visible type or member 'IFileStorageSettings'

Check warning on line 3 in src/FakeXrmEasy.Core/FileStorage/FileStorageSettings.cs

View workflow job for this annotation

GitHub Actions / pack-push

Missing XML comment for publicly visible type or member 'IFileStorageSettings'

Check warning on line 3 in src/FakeXrmEasy.Core/FileStorage/FileStorageSettings.cs

View workflow job for this annotation

GitHub Actions / pack-push

Missing XML comment for publicly visible type or member 'IFileStorageSettings'

Check warning on line 3 in src/FakeXrmEasy.Core/FileStorage/FileStorageSettings.cs

View workflow job for this annotation

GitHub Actions / pack-push

Missing XML comment for publicly visible type or member 'IFileStorageSettings'

Check warning on line 3 in src/FakeXrmEasy.Core/FileStorage/FileStorageSettings.cs

View workflow job for this annotation

GitHub Actions / pack-push

Missing XML comment for publicly visible type or member 'IFileStorageSettings'
{
/// <summary>
/// Sets or gets the default maximum file size for file uploads
/// </summary>
int MaxSizeInKB { get; set; }

/// <summary>
/// Sets or gets the default maximum file size for image uploads
/// </summary>
int ImageMaxSizeInKB { get; set; }
}
public class FileStorageSettings: IFileStorageSettings

Check warning on line 15 in src/FakeXrmEasy.Core/FileStorage/FileStorageSettings.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_2016)

Missing XML comment for publicly visible type or member 'FileStorageSettings'

Check warning on line 15 in src/FakeXrmEasy.Core/FileStorage/FileStorageSettings.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_2016)

Missing XML comment for publicly visible type or member 'FileStorageSettings'

Check warning on line 15 in src/FakeXrmEasy.Core/FileStorage/FileStorageSettings.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_2013)

Missing XML comment for publicly visible type or member 'FileStorageSettings'

Check warning on line 15 in src/FakeXrmEasy.Core/FileStorage/FileStorageSettings.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_2013)

Missing XML comment for publicly visible type or member 'FileStorageSettings'

Check warning on line 15 in src/FakeXrmEasy.Core/FileStorage/FileStorageSettings.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_9)

Missing XML comment for publicly visible type or member 'FileStorageSettings'

Check warning on line 15 in src/FakeXrmEasy.Core/FileStorage/FileStorageSettings.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_9)

Missing XML comment for publicly visible type or member 'FileStorageSettings'

Check warning on line 15 in src/FakeXrmEasy.Core/FileStorage/FileStorageSettings.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_2015)

Missing XML comment for publicly visible type or member 'FileStorageSettings'

Check warning on line 15 in src/FakeXrmEasy.Core/FileStorage/FileStorageSettings.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_2015)

Missing XML comment for publicly visible type or member 'FileStorageSettings'

Check warning on line 15 in src/FakeXrmEasy.Core/FileStorage/FileStorageSettings.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_365)

Missing XML comment for publicly visible type or member 'FileStorageSettings'

Check warning on line 15 in src/FakeXrmEasy.Core/FileStorage/FileStorageSettings.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_365)

Missing XML comment for publicly visible type or member 'FileStorageSettings'

Check warning on line 15 in src/FakeXrmEasy.Core/FileStorage/FileStorageSettings.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY)

Missing XML comment for publicly visible type or member 'FileStorageSettings'

Check warning on line 15 in src/FakeXrmEasy.Core/FileStorage/FileStorageSettings.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY)

Missing XML comment for publicly visible type or member 'FileStorageSettings'

Check warning on line 15 in src/FakeXrmEasy.Core/FileStorage/FileStorageSettings.cs

View workflow job for this annotation

GitHub Actions / pack-push

Missing XML comment for publicly visible type or member 'FileStorageSettings'

Check warning on line 15 in src/FakeXrmEasy.Core/FileStorage/FileStorageSettings.cs

View workflow job for this annotation

GitHub Actions / pack-push

Missing XML comment for publicly visible type or member 'FileStorageSettings'

Check warning on line 15 in src/FakeXrmEasy.Core/FileStorage/FileStorageSettings.cs

View workflow job for this annotation

GitHub Actions / pack-push

Missing XML comment for publicly visible type or member 'FileStorageSettings'

Check warning on line 15 in src/FakeXrmEasy.Core/FileStorage/FileStorageSettings.cs

View workflow job for this annotation

GitHub Actions / pack-push

Missing XML comment for publicly visible type or member 'FileStorageSettings'

Check warning on line 15 in src/FakeXrmEasy.Core/FileStorage/FileStorageSettings.cs

View workflow job for this annotation

GitHub Actions / pack-push

Missing XML comment for publicly visible type or member 'FileStorageSettings'

Check warning on line 15 in src/FakeXrmEasy.Core/FileStorage/FileStorageSettings.cs

View workflow job for this annotation

GitHub Actions / pack-push

Missing XML comment for publicly visible type or member 'FileStorageSettings'
{

/// <summary>
/// The default max size (i.e 32 MB)
/// </summary>
public const int DEFAULT_MAX_FILE_SIZE_IN_KB = 32768;

/// <summary>
/// The maximum file size supported by the platform
/// https://learn.microsoft.com/en-us/dotnet/api/microsoft.xrm.sdk.metadata.fileattributemetadata.maxsizeinkb?view=dataverse-sdk-latest#microsoft-xrm-sdk-metadata-fileattributemetadata-maxsizeinkb
/// </summary>
public const int MAX_SUPPORTED_FILE_SIZE_IN_KB = 10485760;

/// <summary>
/// The maximum file size supported for Image column types
/// https://learn.microsoft.com/en-us/power-apps/developer/data-platform/files-images-overview?tabs=sdk
/// </summary>
public const int MAX_SUPPORTED_IMAGE_FILE_SIZE_IN_KB = 30 * 1024;

/// <summary>
/// Sets or gets the current maximum file size for file uploads that use file storage
/// </summary>
public int MaxSizeInKB { get; set; }

/// <summary>
/// Sets or gets the default maximum file size for image uploads
/// </summary>
public int ImageMaxSizeInKB { get; set; }

/// <summary>
/// Default constructor
/// </summary>
public FileStorageSettings()
{
MaxSizeInKB = DEFAULT_MAX_FILE_SIZE_IN_KB;
ImageMaxSizeInKB = MAX_SUPPORTED_IMAGE_FILE_SIZE_IN_KB;
}
}
}
Loading

0 comments on commit 42711a6

Please sign in to comment.