Skip to content

Instantly share code, notes, and snippets.

[Test]
public void ShouldThrowExceptionIfOpenTaskExists()
{
Entity contact = new Entity()
{
LogicalName = "contact",
Id = Guid.NewGuid()
};
ParameterCollection parameters = new ParameterCollection();
@tswann
tswann / Setup.cs
Last active December 13, 2015 18:18
[SetUp]
public void Setup()
{
this.PipelineContextMock.Setup(p => p.UserId).Returns(Guid.NewGuid);
this.PipelineContextMock.Setup(p => p.PrimaryEntityName).Returns("contact");
this.PipelineContextMock.Setup(p => p.Stage).Returns(STAGE_PREVALIDATION);
}
protected void ExecutePreValidateContactDelete(LocalPluginContext localContext)
{
if (localContext == null)
{
throw new ArgumentNullException("localContext");
}
_service = localContext.OrganizationService;
EntityReference contact = (EntityReference)localContext.PluginExecutionContext.InputParameters["Target"];
@tswann
tswann / PluginTestBase.cs
Created February 14, 2013 16:34
A simple base class for unit testing of CRM plugins.
using System;
using System.Collections.Generic;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Metadata;
using Moq;
namespace X1bplan.PluginTesting.Plugins.Tests.Helpers
{
public abstract class PluginTestBase
@tswann
tswann / Create Entity.cs
Created November 1, 2012 16:15
Example of creating a custom Dynamics CRM entity using the Xrm SDK.
CreateEntityRequest createrequest = new CreateEntityRequest
{
//Define the entity
Entity = new EntityMetadata
{
SchemaName = _customEntityName,
DisplayName = new Label("Bank Account", 1033),
DisplayCollectionName = new Label("Bank Accounts", 1033),
Description = new Label("An entity to store information about customer bank accounts", 1033),
@tswann
tswann / gist:3763266
Created September 21, 2012 19:05
POST
> curl http://localhost:51307/api/tasks -X POST -d "id=2&subject=test&description=blah" -v
> POST /api/tasks HTTP/1.1
> User-Agent: curl/7.23.1 (x86_64-pc-win32) libcurl/7.23.1 OpenSSL/0.9.8r zlib/1.2.5
> Host: localhost:51307
> Accept: */*
> Content-Length: 34
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 34 out of 34 bytes
@tswann
tswann / gist:3763228
Created September 21, 2012 18:57
DELETE
> curl http://localhost:51307/api/tasks/2 -X DELETE -v
> DELETE /api/tasks/2 HTTP/1.1
> User-Agent: curl/7.23.1 (x86_64-pc-win32) libcurl/7.23.1 OpenSSL/0.9.8r zlib/1.2.5
> Host: localhost:51307
> Accept: */*
>
< HTTP/1.1 200 OK
< Cache-Control: no-cache
< Pragma: no-cache
@tswann
tswann / gist:3763163
Created September 21, 2012 18:43
GET (xml)
> curl http://localhost:51307/api/tasks -H "Accept: application/xml"
<ArrayOfTask xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/TaskMana
ger.Models"><Task><Description>Some interestingish text</Description><Id>1</Id><Subject>Test</Subject></Task><Task><Desc
ription>Some more text</Description><Id>2</Id><Subject>Test 2</Subject></Task></ArrayOfTask>
@tswann
tswann / gist:3763084
Created September 21, 2012 18:26
GET (id)
> curl http://localhost:51307/api/tasks/1 -i
HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/json; charset=utf-8
Expires: -1
Server: Microsoft-IIS/8.0
X-AspNet-Version: 4.0.30319
X-SourceFiles: =?UTF-8?B?RDpcU09VUkNFXHBsdXJhbHNpZ2h0XG12YzRcVGFza01hbmFnZXJcVGFza01hbmFnZXJcYXBpXHRhc2tzXDE=?=
@tswann
tswann / gist:3763065
Created September 21, 2012 18:21
GET
> curl http://localhost:51307/api/tasks -v
> GET /api/tasks HTTP/1.1
> User-Agent: curl/7.23.1 (x86_64-pc-win32) libcurl/7.23.1 OpenSSL/0.9.8r zlib/1.2.5
> Host: localhost:51307
> Accept: */*
>
< HTTP/1.1 200 OK
< Cache-Control: no-cache
< Pragma: no-cache