From 41f46065a41d7881ee111722533e9c909d0e3094 Mon Sep 17 00:00:00 2001 From: Konstantin Lapeev Date: Fri, 25 Aug 2023 01:46:20 +0300 Subject: [PATCH 1/5] chore: cleanup code --- CrmNx.Xrm.Identity/Dto/CrmSystemUser.cs | 5 +---- CrmNx.Xrm.Identity/Dto/EntityIdComparer.cs | 2 -- .../Infrastructure/WebApiMetadata.cs | 20 ------------------- 3 files changed, 1 insertion(+), 26 deletions(-) diff --git a/CrmNx.Xrm.Identity/Dto/CrmSystemUser.cs b/CrmNx.Xrm.Identity/Dto/CrmSystemUser.cs index a2d7dc1..5f9431f 100644 --- a/CrmNx.Xrm.Identity/Dto/CrmSystemUser.cs +++ b/CrmNx.Xrm.Identity/Dto/CrmSystemUser.cs @@ -15,10 +15,7 @@ public CrmSystemUser() : base(EntityLogicalName) public sealed override Guid Id { get => GetAttributeValue(PrimaryIdAttribute); - set - { - SetAttributeValue(PrimaryIdAttribute, value); - } + set => SetAttributeValue(PrimaryIdAttribute, value); } public string DomainName diff --git a/CrmNx.Xrm.Identity/Dto/EntityIdComparer.cs b/CrmNx.Xrm.Identity/Dto/EntityIdComparer.cs index 798c3a1..e9a2ac0 100644 --- a/CrmNx.Xrm.Identity/Dto/EntityIdComparer.cs +++ b/CrmNx.Xrm.Identity/Dto/EntityIdComparer.cs @@ -1,7 +1,5 @@ using CrmNx.Xrm.Toolkit; -using System; using System.Collections.Generic; -using System.Text; namespace CrmNx.Xrm.Identity.Dto { diff --git a/CrmNx.Xrm.Toolkit/Infrastructure/WebApiMetadata.cs b/CrmNx.Xrm.Toolkit/Infrastructure/WebApiMetadata.cs index 7141217..e1056ea 100644 --- a/CrmNx.Xrm.Toolkit/Infrastructure/WebApiMetadata.cs +++ b/CrmNx.Xrm.Toolkit/Infrastructure/WebApiMetadata.cs @@ -171,12 +171,7 @@ protected virtual async Task GetDateTimeBehaviorAttributeAsync Parameters = { - // {"$select", "LogicalName,Format,DateTimeBehavior"}, { "$select", "LogicalName,Format,DateTimeBehavior" }, - // { - // "$filter", - // "DateTimeBehavior ne null and Format eq Microsoft.Dynamics.CRM.DateTimeFormat'DateOnly'" - // } } }; @@ -194,21 +189,6 @@ protected virtual async Task GetDateTimeBehaviorAttributeAsync behavior = (DateTimeBehavior)parsedValue; } } - catch (Exception) - { - throw; - } - // catch (WebApiException ex) - // { - // // if (Equals(ex.StatusCode, HttpStatusCode.NotFound)) - // // { - // // isDateOnly = false; - // // } - // // else - // // { - // // throw; - // // } - // } finally { watch.Stop(); From 8b18746e39adc182db8a7cfb10c00937a09d7dd5 Mon Sep 17 00:00:00 2001 From: Konstantin Lapeev Date: Fri, 25 Aug 2023 01:47:00 +0300 Subject: [PATCH 2/5] tests: add tests for ToEntity<> --- Tests/UnitTests/EntityTests.cs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/Tests/UnitTests/EntityTests.cs b/Tests/UnitTests/EntityTests.cs index c6f0bc9..dce114d 100644 --- a/Tests/UnitTests/EntityTests.cs +++ b/Tests/UnitTests/EntityTests.cs @@ -303,5 +303,37 @@ public async Task Retrieve_Request_Have_HttpHeader_Prefer_Included_ODataAnnotati requestHeaders.GetValues("Prefer").Contains("odata.include-annotations=\"*\"").Should().BeTrue(); } + + [Fact] + public async Task Convert_Entity_To_ProxyEntity_By_Attr_When_ID_IS_Overriden_Then_ID_Correct() + { + Entity entity = new Entity("account"); + entity.Attributes.Add("accountid", new Guid("00000000-0000-0000-0000-000000000001")); + entity.Attributes["statecode"] = 1; + + Account account = entity.ToEntity(); + account.Id.Should().Be(new Guid("00000000-0000-0000-0000-000000000001")); + } + + [Fact] + public async Task Convert_Entity_To_ProxyEntity_When_ID_IS_Overriden_Then_ID_Correct() + { + Entity entity = new Entity("account"); + entity.Id = new Guid("00000000-0000-0000-0000-000000000001"); + + Account account = entity.ToEntity(); + account.Id.Should().Be(new Guid("00000000-0000-0000-0000-000000000001")); + } + + [Fact] + public async Task Convert_Entity_To_ProxyEntity_When_ID_IS_Overriden_AND_HAVE_ATTR_Then_ID_Correct() + { + Entity entity = new Entity("account"); + entity.Id = new Guid("00000000-0000-0000-0000-000000000001"); + entity.Attributes.Add("accountid", new Guid("00000000-0000-0000-0000-000000000002")); + + Account account = entity.ToEntity(); + account.Id.Should().Be(new Guid("00000000-0000-0000-0000-000000000002")); + } } } \ No newline at end of file From 48221fae32614cc3ea5e96c89b1e68e47e76737f Mon Sep 17 00:00:00 2001 From: Konstantin Lapeev Date: Fri, 25 Aug 2023 01:47:30 +0300 Subject: [PATCH 3/5] fix: duplicate key exception --- CrmNx.Xrm.Toolkit/Extensions/EntityExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CrmNx.Xrm.Toolkit/Extensions/EntityExtensions.cs b/CrmNx.Xrm.Toolkit/Extensions/EntityExtensions.cs index 72d8803..9b2a797 100644 --- a/CrmNx.Xrm.Toolkit/Extensions/EntityExtensions.cs +++ b/CrmNx.Xrm.Toolkit/Extensions/EntityExtensions.cs @@ -50,7 +50,7 @@ public static TEntity ToEntity(this Entity otherEntity) foreach (var (keyName, value) in otherEntity.Attributes) { - entity.Attributes.Add(keyName, value); + entity.Attributes[keyName] = value; } foreach (var (keyName, value) in otherEntity.FormattedValues) From 271db4a7ef9fdbaacb6ae41c55e2dcc375b951d1 Mon Sep 17 00:00:00 2001 From: Konstantin Lapeev Date: Fri, 25 Aug 2023 01:51:42 +0300 Subject: [PATCH 4/5] chore: reformat code --- Tests/UnitTests/EntityTests.cs | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/Tests/UnitTests/EntityTests.cs b/Tests/UnitTests/EntityTests.cs index dce114d..c3dae32 100644 --- a/Tests/UnitTests/EntityTests.cs +++ b/Tests/UnitTests/EntityTests.cs @@ -305,33 +305,39 @@ public async Task Retrieve_Request_Have_HttpHeader_Prefer_Included_ODataAnnotati } [Fact] - public async Task Convert_Entity_To_ProxyEntity_By_Attr_When_ID_IS_Overriden_Then_ID_Correct() + public void Convert_Entity_To_ProxyEntity_By_Attr_When_ID_IS_Overriden_Then_ID_Correct() { - Entity entity = new Entity("account"); - entity.Attributes.Add("accountid", new Guid("00000000-0000-0000-0000-000000000001")); - entity.Attributes["statecode"] = 1; + Entity entity = new Entity("account") + { + ["accountid"] = new Guid("00000000-0000-0000-0000-000000000001"), + ["statecode"] = 1 + }; Account account = entity.ToEntity(); account.Id.Should().Be(new Guid("00000000-0000-0000-0000-000000000001")); } [Fact] - public async Task Convert_Entity_To_ProxyEntity_When_ID_IS_Overriden_Then_ID_Correct() + public void Convert_Entity_To_ProxyEntity_When_ID_IS_Overriden_Then_ID_Correct() { - Entity entity = new Entity("account"); - entity.Id = new Guid("00000000-0000-0000-0000-000000000001"); + Entity entity = new Entity("account") + { + Id = new Guid("00000000-0000-0000-0000-000000000001") + }; Account account = entity.ToEntity(); account.Id.Should().Be(new Guid("00000000-0000-0000-0000-000000000001")); } [Fact] - public async Task Convert_Entity_To_ProxyEntity_When_ID_IS_Overriden_AND_HAVE_ATTR_Then_ID_Correct() + public void Convert_Entity_To_ProxyEntity_When_ID_IS_Overriden_AND_HAVE_ATTR_Then_ID_Correct() { - Entity entity = new Entity("account"); - entity.Id = new Guid("00000000-0000-0000-0000-000000000001"); - entity.Attributes.Add("accountid", new Guid("00000000-0000-0000-0000-000000000002")); - + Entity entity = new Entity("account") + { + Id = new Guid("00000000-0000-0000-0000-000000000001"), + ["accountid"] = new Guid("00000000-0000-0000-0000-000000000002") + }; + Account account = entity.ToEntity(); account.Id.Should().Be(new Guid("00000000-0000-0000-0000-000000000002")); } From 85a11dfd3a12ad4fca5bab8e21dad853dcbe188d Mon Sep 17 00:00:00 2001 From: Konstantin Lapeev Date: Fri, 25 Aug 2023 01:51:56 +0300 Subject: [PATCH 5/5] chore: bump version to 1.0.28 --- CrmNx.Libs.Build.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CrmNx.Libs.Build.props b/CrmNx.Libs.Build.props index ba63120..2faba67 100644 --- a/CrmNx.Libs.Build.props +++ b/CrmNx.Libs.Build.props @@ -1,6 +1,6 @@ - 1.0.27 + 1.0.28 $([System.DateTime]::UtcNow.AddHours(3).ToString(`yyyyMMdd-HHmm`)) $(VersionNumber)-$(BuildDate) rc