Skip to content

Commit

Permalink
Add RetrieveCurrentOrganizationRequest executor - DynamicsValue/fake-…
Browse files Browse the repository at this point in the history
  • Loading branch information
jordimontana82 committed Mar 2, 2024
1 parent e7c8aab commit 05db9a3
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## [2.5.0]

### Added

- Add RetrieveCurrentOrganizationRequest executor - https://github.com/DynamicsValue/fake-xrm-easy/issues/136

### Changed

- Increase code coverage for NavigateToNextEntityOrganizationRequest
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Microsoft.Xrm.Sdk.Organization;

Check failure on line 1 in src/FakeXrmEasy.Messages/ContextProperties/CurrentOrganizationDetails.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY)

The type or namespace name 'Organization' does not exist in the namespace 'Microsoft.Xrm.Sdk' (are you missing an assembly reference?)

Check failure on line 1 in src/FakeXrmEasy.Messages/ContextProperties/CurrentOrganizationDetails.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY)

The type or namespace name 'Organization' does not exist in the namespace 'Microsoft.Xrm.Sdk' (are you missing an assembly reference?)

Check failure on line 1 in src/FakeXrmEasy.Messages/ContextProperties/CurrentOrganizationDetails.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_2013)

The type or namespace name 'Organization' does not exist in the namespace 'Microsoft.Xrm.Sdk' (are you missing an assembly reference?)

Check failure on line 1 in src/FakeXrmEasy.Messages/ContextProperties/CurrentOrganizationDetails.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_2013)

The type or namespace name 'Organization' does not exist in the namespace 'Microsoft.Xrm.Sdk' (are you missing an assembly reference?)

namespace FakeXrmEasy.Messages.ContextProperties
{
/// <summary>
/// Stores information about the current organization details
/// </summary>
public class CurrentOrganizationDetails
{
/// <summary>
/// The organization details
/// </summary>
public OrganizationDetail Details { get; set; }

Check failure on line 13 in src/FakeXrmEasy.Messages/ContextProperties/CurrentOrganizationDetails.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY)

The type or namespace name 'OrganizationDetail' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 13 in src/FakeXrmEasy.Messages/ContextProperties/CurrentOrganizationDetails.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY)

The type or namespace name 'OrganizationDetail' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 13 in src/FakeXrmEasy.Messages/ContextProperties/CurrentOrganizationDetails.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_2013)

The type or namespace name 'OrganizationDetail' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 13 in src/FakeXrmEasy.Messages/ContextProperties/CurrentOrganizationDetails.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_2013)

The type or namespace name 'OrganizationDetail' could not be found (are you missing a using directive or an assembly reference?)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using System;
using FakeXrmEasy.Abstractions;
using FakeXrmEasy.Abstractions.FakeMessageExecutors;
using FakeXrmEasy.Messages.ContextProperties;
using Microsoft.Crm.Sdk.Messages;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Organization;

Check failure on line 7 in src/FakeXrmEasy.Messages/FakeMessageExecutors/RetrieveCurrentOrganizationRequestExecutor.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY)

The type or namespace name 'Organization' does not exist in the namespace 'Microsoft.Xrm.Sdk' (are you missing an assembly reference?)

Check failure on line 7 in src/FakeXrmEasy.Messages/FakeMessageExecutors/RetrieveCurrentOrganizationRequestExecutor.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY)

The type or namespace name 'Organization' does not exist in the namespace 'Microsoft.Xrm.Sdk' (are you missing an assembly reference?)

Check failure on line 7 in src/FakeXrmEasy.Messages/FakeMessageExecutors/RetrieveCurrentOrganizationRequestExecutor.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_2013)

The type or namespace name 'Organization' does not exist in the namespace 'Microsoft.Xrm.Sdk' (are you missing an assembly reference?)

Check failure on line 7 in src/FakeXrmEasy.Messages/FakeMessageExecutors/RetrieveCurrentOrganizationRequestExecutor.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_2013)

The type or namespace name 'Organization' does not exist in the namespace 'Microsoft.Xrm.Sdk' (are you missing an assembly reference?)

namespace FakeXrmEasy.FakeMessageExecutors
{
/// <summary>
/// Implements an executor for the RetrieveCurrentOrganizationRequest: https://learn.microsoft.com/en-us/dotnet/api/microsoft.crm.sdk.messages.retrievecurrentorganizationrequest?view=dataverse-sdk-latest
/// </summary>
public class RetrieveCurrentOrganizationRequestExecutor: IFakeMessageExecutor
{
public bool CanExecute(OrganizationRequest request)
{
return request is RetrieveCurrentOrganizationRequest;
}

public OrganizationResponse Execute(OrganizationRequest request, IXrmFakedContext ctx)
{
OrganizationDetail orgDetail = null;
if (ctx.HasProperty<CurrentOrganizationDetails>())
{
orgDetail = ctx.GetProperty<CurrentOrganizationDetails>().Details;
}

if (orgDetail == null)
{
orgDetail = new OrganizationDetail()
{
Endpoints =
{
{ EndpointType.OrganizationDataService, "http://baseUrl/XrmServices/2011/OrganizationDataService.svc" }
}
};
}
return new RetrieveCurrentOrganizationResponse()
{
Results = new ParameterCollection
{
{ "Detail", orgDetail }
}
};
}

public Type GetResponsibleRequestType()
{
return typeof(RetrieveCurrentOrganizationRequest);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System;
using FakeXrmEasy.Messages.ContextProperties;
using Microsoft.Crm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Organization;
using Xunit;

namespace FakeXrmEasy.Messages.Tests.FakeMessageExecutors.RetrieveCurrentOrganizationRequestTests
{
public class RetrieveCurrentOrganizationRequestTests: FakeXrmEasyTestsBase
{
[Fact]
public void Should_retrieve_current_organization_details_if_none_was_set_by_default()
{
var response = _service.Execute(new RetrieveCurrentOrganizationRequest());
Assert.NotNull(response);

var orgDetail = (response as RetrieveCurrentOrganizationResponse).Detail;
Assert.NotNull(orgDetail);
}

[Fact]
public void Should_retrieve_current_organization_details()
{
var currentOrgDetails = new CurrentOrganizationDetails()
{
Details = new OrganizationDetail()
{
Geo = "Geo",

Check failure on line 28 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/RetrieveCurrentOrganizationRequestTests/RetrieveCurrentOrganizationRequestTests.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_2015)

'OrganizationDetail' does not contain a definition for 'Geo'

Check failure on line 28 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/RetrieveCurrentOrganizationRequestTests/RetrieveCurrentOrganizationRequestTests.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_2015)

'OrganizationDetail' does not contain a definition for 'Geo'

Check failure on line 28 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/RetrieveCurrentOrganizationRequestTests/RetrieveCurrentOrganizationRequestTests.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_2016)

'OrganizationDetail' does not contain a definition for 'Geo'

Check failure on line 28 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/RetrieveCurrentOrganizationRequestTests/RetrieveCurrentOrganizationRequestTests.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_2016)

'OrganizationDetail' does not contain a definition for 'Geo'

Check failure on line 28 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/RetrieveCurrentOrganizationRequestTests/RetrieveCurrentOrganizationRequestTests.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_365)

'OrganizationDetail' does not contain a definition for 'Geo'

Check failure on line 28 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/RetrieveCurrentOrganizationRequestTests/RetrieveCurrentOrganizationRequestTests.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_365)

'OrganizationDetail' does not contain a definition for 'Geo'
EnvironmentId = Guid.NewGuid().ToString(),

Check failure on line 29 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/RetrieveCurrentOrganizationRequestTests/RetrieveCurrentOrganizationRequestTests.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_2015)

'OrganizationDetail' does not contain a definition for 'EnvironmentId'

Check failure on line 29 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/RetrieveCurrentOrganizationRequestTests/RetrieveCurrentOrganizationRequestTests.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_2016)

'OrganizationDetail' does not contain a definition for 'EnvironmentId'

Check failure on line 29 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/RetrieveCurrentOrganizationRequestTests/RetrieveCurrentOrganizationRequestTests.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_365)

'OrganizationDetail' does not contain a definition for 'EnvironmentId'

Check failure on line 29 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/RetrieveCurrentOrganizationRequestTests/RetrieveCurrentOrganizationRequestTests.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_365)

'OrganizationDetail' does not contain a definition for 'EnvironmentId'
State = OrganizationState.Enabled,
FriendlyName = "OrgFriendlyName",
UniqueName = "UniqueName",
UrlName = "UrlName",
OrganizationId = Guid.NewGuid(),
TenantId = Guid.NewGuid().ToString(),

Check failure on line 35 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/RetrieveCurrentOrganizationRequestTests/RetrieveCurrentOrganizationRequestTests.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_2015)

'OrganizationDetail' does not contain a definition for 'TenantId'

Check failure on line 35 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/RetrieveCurrentOrganizationRequestTests/RetrieveCurrentOrganizationRequestTests.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_2016)

'OrganizationDetail' does not contain a definition for 'TenantId'

Check failure on line 35 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/RetrieveCurrentOrganizationRequestTests/RetrieveCurrentOrganizationRequestTests.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_365)

'OrganizationDetail' does not contain a definition for 'TenantId'

Check failure on line 35 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/RetrieveCurrentOrganizationRequestTests/RetrieveCurrentOrganizationRequestTests.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_365)

'OrganizationDetail' does not contain a definition for 'TenantId'
OrganizationVersion = "0.0.0.0",
Endpoints =
{
{ EndpointType.OrganizationDataService, "http://localhost/XrmService/2011/OrganizationData.svc" }
}
}
};

_context.SetProperty(currentOrgDetails);

var response = _service.Execute(new RetrieveCurrentOrganizationRequest());
Assert.NotNull(response);

var orgDetail = (response as RetrieveCurrentOrganizationResponse).Detail;
Assert.Equal(currentOrgDetails.Details.EnvironmentId, orgDetail.EnvironmentId);

Check failure on line 50 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/RetrieveCurrentOrganizationRequestTests/RetrieveCurrentOrganizationRequestTests.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_2015)

'OrganizationDetail' does not contain a definition for 'EnvironmentId' and no accessible extension method 'EnvironmentId' accepting a first argument of type 'OrganizationDetail' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 50 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/RetrieveCurrentOrganizationRequestTests/RetrieveCurrentOrganizationRequestTests.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_2015)

'OrganizationDetail' does not contain a definition for 'EnvironmentId' and no accessible extension method 'EnvironmentId' accepting a first argument of type 'OrganizationDetail' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 50 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/RetrieveCurrentOrganizationRequestTests/RetrieveCurrentOrganizationRequestTests.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_2016)

'OrganizationDetail' does not contain a definition for 'EnvironmentId' and no accessible extension method 'EnvironmentId' accepting a first argument of type 'OrganizationDetail' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 50 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/RetrieveCurrentOrganizationRequestTests/RetrieveCurrentOrganizationRequestTests.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_2016)

'OrganizationDetail' does not contain a definition for 'EnvironmentId' and no accessible extension method 'EnvironmentId' accepting a first argument of type 'OrganizationDetail' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 50 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/RetrieveCurrentOrganizationRequestTests/RetrieveCurrentOrganizationRequestTests.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_365)

'OrganizationDetail' does not contain a definition for 'EnvironmentId' and no accessible extension method 'EnvironmentId' accepting a first argument of type 'OrganizationDetail' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 50 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/RetrieveCurrentOrganizationRequestTests/RetrieveCurrentOrganizationRequestTests.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_365)

'OrganizationDetail' does not contain a definition for 'EnvironmentId' and no accessible extension method 'EnvironmentId' accepting a first argument of type 'OrganizationDetail' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 50 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/RetrieveCurrentOrganizationRequestTests/RetrieveCurrentOrganizationRequestTests.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_365)

'OrganizationDetail' does not contain a definition for 'EnvironmentId' and no accessible extension method 'EnvironmentId' accepting a first argument of type 'OrganizationDetail' could be found (are you missing a using directive or an assembly reference?)
Assert.Equal(currentOrgDetails.Details.Geo, orgDetail.Geo);

Check failure on line 51 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/RetrieveCurrentOrganizationRequestTests/RetrieveCurrentOrganizationRequestTests.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_2015)

'OrganizationDetail' does not contain a definition for 'Geo' and no accessible extension method 'Geo' accepting a first argument of type 'OrganizationDetail' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 51 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/RetrieveCurrentOrganizationRequestTests/RetrieveCurrentOrganizationRequestTests.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_2015)

'OrganizationDetail' does not contain a definition for 'Geo' and no accessible extension method 'Geo' accepting a first argument of type 'OrganizationDetail' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 51 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/RetrieveCurrentOrganizationRequestTests/RetrieveCurrentOrganizationRequestTests.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_2016)

'OrganizationDetail' does not contain a definition for 'Geo' and no accessible extension method 'Geo' accepting a first argument of type 'OrganizationDetail' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 51 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/RetrieveCurrentOrganizationRequestTests/RetrieveCurrentOrganizationRequestTests.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_2016)

'OrganizationDetail' does not contain a definition for 'Geo' and no accessible extension method 'Geo' accepting a first argument of type 'OrganizationDetail' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 51 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/RetrieveCurrentOrganizationRequestTests/RetrieveCurrentOrganizationRequestTests.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_365)

'OrganizationDetail' does not contain a definition for 'Geo' and no accessible extension method 'Geo' accepting a first argument of type 'OrganizationDetail' could be found (are you missing a using directive or an assembly reference?)
Assert.Equal(currentOrgDetails.Details.State, orgDetail.State);
Assert.Equal(currentOrgDetails.Details.FriendlyName, orgDetail.FriendlyName);
Assert.Equal(currentOrgDetails.Details.UniqueName, orgDetail.UniqueName);
Assert.Equal(currentOrgDetails.Details.UrlName, orgDetail.UrlName);
Assert.Equal(currentOrgDetails.Details.OrganizationId, orgDetail.OrganizationId);
Assert.Equal(currentOrgDetails.Details.TenantId, orgDetail.TenantId);

Check failure on line 57 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/RetrieveCurrentOrganizationRequestTests/RetrieveCurrentOrganizationRequestTests.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_2015)

'OrganizationDetail' does not contain a definition for 'TenantId' and no accessible extension method 'TenantId' accepting a first argument of type 'OrganizationDetail' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 57 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/RetrieveCurrentOrganizationRequestTests/RetrieveCurrentOrganizationRequestTests.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_2015)

'OrganizationDetail' does not contain a definition for 'TenantId' and no accessible extension method 'TenantId' accepting a first argument of type 'OrganizationDetail' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 57 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/RetrieveCurrentOrganizationRequestTests/RetrieveCurrentOrganizationRequestTests.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_2016)

'OrganizationDetail' does not contain a definition for 'TenantId' and no accessible extension method 'TenantId' accepting a first argument of type 'OrganizationDetail' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 57 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/RetrieveCurrentOrganizationRequestTests/RetrieveCurrentOrganizationRequestTests.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_2016)

'OrganizationDetail' does not contain a definition for 'TenantId' and no accessible extension method 'TenantId' accepting a first argument of type 'OrganizationDetail' could be found (are you missing a using directive or an assembly reference?)
Assert.Equal(currentOrgDetails.Details.OrganizationVersion, orgDetail.OrganizationVersion);
}
}
}

0 comments on commit 05db9a3

Please sign in to comment.