using FakeXrmEasy;
using FakeItEasy;
using Microsoft.Xrm.Sdk;
using Xunit;
public class CaspPluginTests
{
[Fact]
public void Should_Call_CaspService_And_Set_Attribute()
{
// Arrange
var context = new XrmFakedContext();
var fakeService = A.Fake<ICaspService>();
// Fake the method return value
A.CallTo(() => fakeService.GetCaspMedicalData("123", "DLN456"))
.Returns("{\"status\":\"success\"}");
// Register your plugin and pass in the fake dependency
var pluginContext = context.GetDefaultPluginContext();
// Example: simulate a target entity
var target = new Entity("contact") { Id = Guid.NewGuid() };
target["pfx_contactid"] = "123";
target["pfx_dln"] = "DLN456";
pluginContext.InputParameters["Target"] = target;
// Inject the fake dependency using constructor injection or a service locator
var plugin = new CaspPlugin(fakeService); // You must design your plugin to accept it
// Act
context.ExecutePluginWith(plugin, pluginContext);
// Assert — e.g. verify attribute set based on the fake result
var updated = context.Data[target.LogicalName][target.Id];
Assert.True(updated.Contains("pfx_result"));
Assert.Equal("{\"status\":\"success\"}", updated["pfx_result"]);
}
}
Wednesday, May 7, 2025
Act Arrange 2
Act Arrnage
using Xunit;
using FakeItEasy;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Xrm.Sdk;
public class CaspServiceTests
{
private readonly IDataAccessEnvironmentVariables _envVarMock;
private readonly ISystemConfigurationService _configServiceMock;
private readonly ITraceLogger _loggerMock;
private readonly IHttpClientFactoryWrapper _httpFactoryMock;
private readonly CaspService _service;
public CaspServiceTests()
{
_envVarMock = A.Fake<IDataAccessEnvironmentVariables>();
_configServiceMock = A.Fake<ISystemConfigurationService>();
_loggerMock = A.Fake<ITraceLogger>();
_httpFactoryMock = A.Fake<IHttpClientFactoryWrapper>();
_service = new CaspService(
_envVarMock,
_configServiceMock,
_loggerMock,
_httpFactoryMock
);
}
private HttpClient CreateFakeHttpClient(HttpResponseMessage responseMessage)
{
var fakeHandler = A.Fake<HttpMessageHandler>();
A.CallTo(() => fakeHandler.Send(
A<HttpRequestMessage>._,
A<CancellationToken>._))
.Returns(responseMessage);
return new HttpClient(fakeHandler);
}
[Fact]
public void GetCaspMedicalData_ShouldThrow_WhenUrlIsMissing()
{
// Arrange
A.CallTo(() => _envVarMock
.GetEnvironmentVariableValueByDefinitionSchemaName(A<string>._))
.Returns(null);
// Act & Assert
Assert.Throws<InvalidPluginExecutionException>(() =>
_service.GetCaspMedicalData("123", "DLN456"));
}
[Fact]
public void GetCaspMedicalData_ShouldReturnResponse_WhenSuccessful()
{
// Arrange
var expectedJson = "{\"status\":\"success\"}";
var fakeHttpResponse = new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StringContent(expectedJson, Encoding.UTF8, "application/json")
};
A.CallTo(() => _envVarMock
.GetEnvironmentVariableValueByDefinitionSchemaName(A<string>._))
.Returns(new Entity { ["value"] = "https://fake.url.com" });
A.CallTo(() => _configServiceMock.RetrievePFXSystemConfigRecord())
.Returns(new Entity("pfx_config"));
A.CallTo(() => _httpFactoryMock.CreateClient(A<Entity>._))
.Returns(CreateFakeHttpClient(fakeHttpResponse));
// Act
var result = _service.GetCaspMedicalData("123", "DLN456");
// Assert
Assert.Equal(expectedJson, result);
}
[Fact]
public void GetCaspMedicalData_ShouldThrow_WhenHttpReturnsNotFound()
{
// Arrange
var response = new HttpResponseMessage(HttpStatusCode.NotFound);
A.CallTo(() => _envVarMock
.GetEnvironmentVariableValueByDefinitionSchemaName(A<string>._))
.Returns(new Entity { ["value"] = "https://fake.url.com" });
A.CallTo(() => _configServiceMock.RetrievePFXSystemConfigRecord())
.Returns(new Entity("pfx_config"));
A.CallTo(() => _httpFactoryMock.CreateClient(A<Entity>._))
.Returns(CreateFakeHttpClient(response));
// Act & Assert
Assert.Throws<HttpRequestException>(() =>
_service.GetCaspMedicalData("123", "DLN456"));
}
[Fact]
public void GetCaspMedicalData_ShouldReturnEmpty_WhenInternalServerError()
{
// Arrange
var response = new HttpResponseMessage(HttpStatusCode.InternalServerError);
A.CallTo(() => _envVarMock
.GetEnvironmentVariableValueByDefinitionSchemaName(A<string>._))
.Returns(new Entity { ["value"] = "https://fake.url.com" });
A.CallTo(() => _configServiceMock.RetrievePFXSystemConfigRecord())
.Returns(new Entity("pfx_config"));
A.CallTo(() => _httpFactoryMock.CreateClient(A<Entity>._))
.Returns(CreateFakeHttpClient(response));
// Act
var result = _service.GetCaspMedicalData("123", "DLN456");
// Assert
Assert.Equal(string.Empty, result);
}
[Fact]
public void GetCaspMedicalData_ShouldLogAndThrow_WhenUnhandledExceptionOccurs()
{
// Arrange
A.CallTo(() => _envVarMock
.GetEnvironmentVariableValueByDefinitionSchemaName(A<string>._))
.Returns(new Entity { ["value"] = "https://fake.url.com" });
A.CallTo(() => _configServiceMock.RetrievePFXSystemConfigRecord())
.Returns(new Entity("pfx_config"));
A.CallTo(() => _httpFactoryMock.CreateClient(A<Entity>._))
.Throws(new Exception("Unexpected failure"));
// Act & Assert
Assert.Throws<Exception>(() =>
_service.GetCaspMedicalData("123", "DLN456"));
A.CallTo(() => _loggerMock
.Error(A<string>._, A<string>._, A<Exception>._))
.MustHaveHappenedOnceExactly();
}
}
Sunday, March 23, 2025
Activity Party
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using System;
using System.Collections.Generic;
public class RetrieveActivityParty
{
private readonly IOrganizationService _service;
public RetrieveActivityParty(IOrganizationService service)
{
_service = service;
}
public void GetActivityParties(Guid activityId)
{
QueryExpression query = new QueryExpression("activityparty")
{
ColumnSet = new ColumnSet("partyid", "participationtypemask")
};
query.Criteria.AddCondition("activityid", ConditionOperator.Equal, activityId);
EntityCollection results = _service.RetrieveMultiple(query);
foreach (Entity activityParty in results.Entities)
{
EntityReference party = activityParty.GetAttributeValue<EntityReference>("partyid");
int participationType = activityParty.GetAttributeValue<OptionSetValue>("participationtypemask")?.Value ?? 0;
Console.WriteLine($"Party ID: {party?.Id}, Type: {party?.LogicalName}, Participation Type: {participationType}");
}
}
}
Monday, March 10, 2025
Slpit-string
using System;
using System.Text.RegularExpressions;
class Program
{
static void Main()
{
string url = "https://example.com/a-guid/b-guid/c-guid/d.anyextension";
if (TryExtractFields(url, out string fieldA, out string fieldBC))
{
Console.WriteLine($"a: {fieldA}");
Console.WriteLine($"b/c: {fieldBC}");
}
else
{
Console.WriteLine("Invalid URL format.");
}
}
static bool TryExtractFields(string url, out string fieldA, out string fieldBC)
{
fieldA = string.Empty;
fieldBC = string.Empty;
// Regex to match: https://{domain}/{guid}/{guid}/{guid}/filename.anyextension
Regex regex = new Regex(@"^https://[^/]+/([0-9a-fA-F-]{36})/([0-9a-fA-F-]{36})/([0-9a-fA-F-]{36})/[^/]+\.[a-zA-Z0-9]+$");
Match match = regex.Match(url);
if (match.Success)
{
fieldA = match.Groups[1].Value; // Extract GUID 'a'
fieldBC = $"{match.Groups[2].Value}/{match.Groups[3].Value}"; // Extract 'b/c' as "b-guid/c-guid"
return true;
}
return false;
}
}
Friday, July 22, 2022
Tools of Trade - 2
VS code Plugins
Azure
Azure Account
Azure API Management Extension for Visual Studio Code
Azure App Service for Visual Studio Code
Azure Application Insights
Azure CLI Tools
Azure Databases for VS Code
Azure Functions for Visual Studio Code
Azure Logic Apps for Visual Studio Code
Azure Pipelines for VS Code
Azure Resource Manager (ARM) Tools for Visual Studio Code
Azure Storage for Visual Studio Code
Bicep VS Code extension
C# for Visual Studio Code (powered by OmniSharp)
C# Snippets for Visual Studio Code
Git Extension Pack
Node npm
Power Platform Extension
PowerShell Language Support for Visual Studio Code
REST Client
Start git-bash
XML Language Support by Red Hat
Software
Firefox/Chrome
Level Up for Dyanmcis/D365 Power Pane
FireFox - Multi Account container
Postman
XrmToolBox
AzureData Explorer
NotePad += /Sublime Text
Git for Windows
Fiddler Classic
Visual Studio Code
Ligthshot exe
Irfan View
NRemoteNG
Onenote
Drwa.io
Notion
VS2019/2022
Azure
Azure Data Studio
Azure Bus Explorer /https://github.com/paolosalvatori/ServiceBusExplorer
Azure Data Explorer
SSMS (SQL Server Management Tools) /Bids
Data Sync Studio
Kings way soft
Node.js
Power Shell
Zoom
Microsoft Teams
Tools
Hangfire
Swagger /Swagger UI
Azure Batch
Thursday, June 18, 2020
Tools Of Trade
- Naming Conventions c#
- Open source
- https://opensourcelibs.com/libs/dynamics-crm
- Git
- Fiddler
- Postman
- Hangfire
- Collaboration
- Microsoft Teams
- Microsoft SharePoint
- Slack
- Xrm tool Box
- SPKL
- https://www.xrmtoolbox.com/
- https://github.com/paolosalvatori/ServiceBusExplorer
- https://azure.microsoft.com/en-us/features/storage-explorer/
- Azure
- http://portal.azure.com/
- Azure bus
- Queues
- Topics
- Azure Blob Storage
- Containers
- File shares
- Web API
- App Insights
- Deployment Slots
- Azure SQL
- Azure VM
- Azure Batch
- Azure Scheduler Jobs
- Azure Key Vaults
- Secrets
- Certificates
- Self Signed Certificates
- Azure App Registration
- S2S comunication
- CI/CD
- Json Viewer
- Web
- CRM
- PCF Controls
- Logic Apps
- Flows
- Power Platform
- Model Driven Apps
- Canvas Apps
- Azure Functions
- Data
- Data sync studio
- Data Export Service
- SSIS
- Kingsway soft
- Azure Synapse
- Screenshot
- Note making
- One note
- Code Tools
- Visual Studio
- Notepad++
- Sublime Text
- Visual studio code
- Addons
- Azure Account
- Azure App Service
- Azure functions
- Powershell
- GittHistory
- Python
- Simple React snippets
- Dynamics 365 – Developer Toolkit
- Dependency Injection
- Data Mapping
- Unit Testing
- Fake Xrm Easy
- UI Testing
- BDD
- easypro
- Js
- TypeScript
- Npm
- Rollup.js
- @types/xrm
- XrmDefinitelyTyped
- React
- Browser Tools
- Dynamics 365 Power Pane
- Level up for Dynamics 365/Power Apps
- Data Mocking
- CRM Tools
- XrmToolbox
- Levelup-for-Dynamics-CRM
- CRM REST Builder from Jason Lattimer
- PowerShell - With the CRM Web API
- Scribe, KingswaySoft or CozyRoc
- Kaskela Solutions (Workflow Elements)
- Dynamics 365 Workflow Tools" from Demian Raschkovan.
- Jason Lattimer's CRM Workflow Utilities.
- CRM REST Builder from Jason Lattimer
- Ribbon Workbench by Scott Durow
Wednesday, February 22, 2017
MSCRM Links
- Dynamics CRM & 365 Developer Extensions
- JavaScript snippets for Dynamics 365/CRM 2011/2013/2015/2016
- https://github.com/jlattimer/CRMVSCodeJSSnippets/wiki/Included-Snippets
- Personal View Editor For Microsoft Dynamics CRM
- https://mscrmworkflowutilities.codeplex.com/
- https://crmemailworkflowutilities.codeplex.com/
- https://crm2011internalemail.codeplex.com/
- https://crmemailworkflowutilities.codeplex.com/
- https://crmdatetimeworkflowutilities.codeplex.com/
- https://crmstringworkflowutilities.codeplex.com/
- https://crm2011distributewf.codeplex.com/
- https://crmemailworkflowutilities.codeplex.com/
- https://crmstringworkflowutilities.codeplex.com/
- https://crmnumericworkflowutilities.codeplex.com/
- https://crmemailworkflowutilities.codeplex.com/
- https://crm2013auditundo.codeplex.com/
- https://crm2013quicknavigation.codeplex.com/
- https://crmlinks.wordpress.com/category/tools/
- https://crmcodegenerator.codeplex.com/documentation
- http://www.gapconsulting.co.uk/our-solutions/free-tools/workflow-essentials
- http://manipulationlibrary.codeplex.com/
Friday, May 20, 2016
MSCRM Addons /Codeplex
- https://mscrmworkflowutilities.codeplex.com/
- https://crmemailworkflowutilities.codeplex.com/
- https://crm2011internalemail.codeplex.com/
- https://crmemailworkflowutilities.codeplex.com/
- https://crmdatetimeworkflowutilities.codeplex.com/
- https://crmstringworkflowutilities.codeplex.com/
- https://crm2011distributewf.codeplex.com/
- https://crmemailworkflowutilities.codeplex.com/
- https://crmstringworkflowutilities.codeplex.com/
- https://crmnumericworkflowutilities.codeplex.com/
- https://crmemailworkflowutilities.codeplex.com/
- https://crm2013auditundo.codeplex.com/
- https://crm2013quicknavigation.codeplex.com/
- https://crmlinks.wordpress.com/category/tools/
- https://crmcodegenerator.codeplex.com/documentation
- http://www.gapconsulting.co.uk/our-solutions/free-tools/workflow-essentials
- http://manipulationlibrary.codeplex.com/
- https://processjsext.codeplex.com/
- https://alertjs.codeplex.com/
- https://notifyjs.codeplex.com/
- https://processjsext.codeplex.com/
- http://personalvieweditor.codeplex.com/
- http://xrmsvctoolkit.codeplex.com/
- https://xrmservicetoolkit.codeplex.com/
- https://crmazureattachments.codeplex.com/
- https://kaskelasolutions.com/
- https://msdyncrmworkflowtools.codeplex.com/
- https://crmemailworkflowutilities.codeplex.com/
- https://crmazureattachments.codeplex.com/
- https://msdyncrmworkflowtools.codeplex.com/
- http://crmdiagtool2011.codeplex.com/
- http://www.develop1.net/public/rwb/ribbonworkbench.aspx
- https://crmrestbuilder.codeplex.com/
Saturday, June 2, 2012
Accn Ques
Accn ques | |
Links
http://blogs.msdn.com/b/ericlippert/archive/2012/01/23/anonymous-types-unify-within-an-assembly.aspx
http://blogs.msdn.com/b/ericlippert/archive/2010/12/20/why-are-anonymous-types-generic.aspx
http://blogs.msdn.com/b/abhinaba/archive/2005/10/05/477238.aspx