public void CreateTemplate_Create() { //Arrange XrmFakedWorkflowContext workflowContext = new XrmFakedWorkflowContext(); var inputs = new Dictionary <string, object> { { "Template", new EntityReference("template", Guid.NewGuid()) }, { "RecordUrl", "https://test.crm.dynamics.com:443/main.aspx?etc=1&id=76ff58d2-ae20-e811-a97e-000d3a367d35&histKey=208282481&newWindow=true&pagetype=entityrecord" } }; XrmFakedContext xrmFakedContext = new XrmFakedContext(); var fakeRetrieveMetadataChangesRequest = new FakeRetrieveMetadataChangesRequestExecutor(); xrmFakedContext.AddFakeMessageExecutor <RetrieveMetadataChangesRequest>(fakeRetrieveMetadataChangesRequest); var fakeInstantiateTemplateRequestExecutor = new FakeInstantiateTemplateRequestExecutor(); xrmFakedContext.AddFakeMessageExecutor <InstantiateTemplateRequest>(fakeInstantiateTemplateRequestExecutor); const string expectedTemplateSubject = "Test Subject"; const string expectedTemplateDescription = "Test Description"; //Act var result = xrmFakedContext.ExecuteCodeActivity <CreateTemplate>(workflowContext, inputs); //Assert Assert.AreEqual(expectedTemplateSubject, result["TemplateSubject"]); Assert.AreEqual(expectedTemplateDescription, result["TemplateDescription"]); }
public void Trace_Null_Severity_Test() { XrmFakedWorkflowContext workflowContext = new XrmFakedWorkflowContext { WorkflowCategory = 0 }; var aiSetup = Configs.GetAiSetup(false, false, false, false, false, false, true); string aiSetupJson = SerializationHelper.SerializeObject <AiSetup>(aiSetup); var inputs = new Dictionary <string, object> { { "AiSetupJson", aiSetupJson }, { "Message", "Hello from TraceTest - 2" }, { "Severity", null } }; XrmFakedContext xrmFakedContext = new XrmFakedContext(); var fakeLogActionExecutor = new FakeLogActionExecutor("lat_ApplicationInsightsLogTrace"); xrmFakedContext.AddFakeMessageExecutor <OrganizationRequest>(fakeLogActionExecutor); var result = xrmFakedContext.ExecuteCodeActivity <LogTrace>(workflowContext, inputs); Assert.IsFalse(bool.Parse(result["LogSuccess"].ToString())); }
public void CopyNote_Copy_To_Same_Record() { //Arrange XrmFakedWorkflowContext workflowContext = new XrmFakedWorkflowContext(); Entity note = new Entity("annotation") { Id = Guid.NewGuid(), ["objectid"] = new EntityReference("account", new Guid("ba166c72-5f7b-e611-80db-fc15b4282d80")) }; var inputs = new Dictionary <string, object> { { "NoteToCopy", note.ToEntityReference() }, { "RecordUrl", "https://test.crm.dynamics.com:443/main.aspx?etc=1&id=ba166c72-5f7b-e611-80db-fc15b4282d80&histKey=694632068&newWindow=true&pagetype=entityrecord" }, { "CopyAttachment", true } }; XrmFakedContext xrmFakedContext = new XrmFakedContext(); xrmFakedContext.Initialize(new List <Entity> { note }); var fakeRetrieveMetadataChangesRequest = new FakeRetrieveMetadataChangesRequestExecutor(); xrmFakedContext.AddFakeMessageExecutor <RetrieveMetadataChangesRequest>(fakeRetrieveMetadataChangesRequest); const bool expected = false; //Act var result = xrmFakedContext.ExecuteCodeActivity <CopyNote>(workflowContext, inputs); //Assert Assert.AreEqual(expected, result["WasNoteCopied"]); }
public void EqBusinessId() { var context = new XrmFakedContext(); context.InitializeMetadata(Assembly.GetExecutingAssembly()); context.AddFakeMessageExecutor <WhoAmIRequest>(new WhoAmIHandler()); var org = context.GetOrganizationService(); var metadata = new AttributeMetadataCache(org); var fetch = @" <fetch> <entity name='contact'> <attribute name='firstname' /> <attribute name='lastname' /> <filter> <condition attribute='parentcustomerid' operator='eq-businessid' /> </filter> </entity> </fetch>"; var converted = FetchXml2Sql.Convert(org, metadata, fetch, new FetchXml2SqlOptions { PreserveFetchXmlOperatorsAsFunctions = false }, out _); Assert.AreEqual($"SELECT firstname, lastname FROM contact WHERE parentcustomerid = '{WhoAmIHandler.BusinessUnitId:D}'", NormalizeWhitespace(converted)); }
public void When_calling_retrieve_entity_with_a_fake_entity_metadata_that_one_is_returned() { var ctx = new XrmFakedContext() { ProxyTypesAssembly = Assembly.GetAssembly(typeof(Account)) }; var service = ctx.GetOrganizationService(); var executor = new RetrieveEntityRequestExecutor(); executor.AddFakeEntityMetadata(Account.EntityLogicalName, new EntityMetadata() { IsCustomizable = new BooleanManagedProperty(true) }); ctx.AddFakeMessageExecutor <RetrieveEntityRequest>(executor); var request = new RetrieveEntityRequest() { EntityFilters = EntityFilters.Entity, LogicalName = Account.EntityLogicalName }; var response = service.Execute(request); Assert.IsType <RetrieveEntityResponse>(response); Assert.True((response as RetrieveEntityResponse).EntityMetadata.IsCustomizable.Value); }
public void EmailQueueMembers_1_Member_Without_Owner_0_Existing_2011() { //Arrange XrmFakedWorkflowContext workflowContext = new XrmFakedWorkflowContext(); Guid id = Guid.NewGuid(); Entity email = new Entity("email") { Id = id, ["activityid"] = id, ["to"] = new EntityCollection() }; Entity queue = new Entity("queue") { Id = Guid.NewGuid(), ["ownerid"] = new EntityReference("systemuser", Guid.NewGuid()) }; Entity systemUser = new Entity("systemuser") { Id = Guid.NewGuid(), ["isdisabled"] = false }; Guid id2 = Guid.NewGuid(); Entity queueMembership = new Entity("queuemembership") { Id = id2, ["queuemembership"] = id2, ["systemuserid"] = systemUser.Id, ["queueid"] = queue.Id }; var inputs = new Dictionary <string, object> { { "EmailToSend", email.ToEntityReference() }, { "RecipientQueue", queue.ToEntityReference() }, { "IncludeOwner", false }, { "SendEmail", false } }; XrmFakedContext xrmFakedContext = new XrmFakedContext(); xrmFakedContext.Initialize(new List <Entity> { email, queue, systemUser, queueMembership }); var fakeRetrieveVersionRequestExecutor = new FakeRetrieveVersionRequestExecutor(true); xrmFakedContext.AddFakeMessageExecutor <RetrieveVersionRequest>(fakeRetrieveVersionRequestExecutor); const int expected = 1; //Act var result = xrmFakedContext.ExecuteCodeActivity <EmailQueueMembers>(workflowContext, inputs); //Assert Assert.AreEqual(expected, result["UsersAdded"]); }
public FakeXrmEasyTestsBase() { _context = new XrmFakedContext(); _context.InitializeMetadata(Assembly.GetExecutingAssembly()); _context.AddFakeMessageExecutor <WhoAmIRequest>(new WhoAmIHandler()); _service = _context.GetOrganizationService(); }
public void EmailQueueMembers_No_Members_Without_Owner_1_Existing() { //Arrange XrmFakedWorkflowContext workflowContext = new XrmFakedWorkflowContext(); Guid id = Guid.NewGuid(); Entity email = new Entity("email") { Id = id, ["activityid"] = id }; Guid id2 = Guid.NewGuid(); Entity activityParty = new Entity("activityparty") { Id = id2, ["activitypartyid"] = id2, ["activityid"] = email.ToEntityReference(), ["partyid"] = new EntityReference("contact", Guid.NewGuid()), ["participationtypemask"] = new OptionSetValue(2) }; EntityCollection to = new EntityCollection(); to.Entities.Add(activityParty); email["to"] = to; Entity queue = new Entity("queue") { Id = Guid.NewGuid(), ["ownerid"] = new EntityReference("systemuser", Guid.NewGuid()) }; var inputs = new Dictionary <string, object> { { "EmailToSend", email.ToEntityReference() }, { "RecipientQueue", queue.ToEntityReference() }, { "IncludeOwner", false }, { "SendEmail", false } }; XrmFakedContext xrmFakedContext = new XrmFakedContext(); xrmFakedContext.Initialize(new List <Entity> { email, activityParty, queue }); var fakeRetrieveVersionRequestExecutor = new FakeRetrieveVersionRequestExecutor(false); xrmFakedContext.AddFakeMessageExecutor <RetrieveVersionRequest>(fakeRetrieveVersionRequestExecutor); const int expected = 1; //Act var result = xrmFakedContext.ExecuteCodeActivity <EmailQueueMembers>(workflowContext, inputs); //Assert Assert.AreEqual(expected, result["UsersAdded"]); }
public void When_calling_retrieve_entity_without_proxy_types_assembly_exception_is_thrown() { var ctx = new XrmFakedContext(); var service = ctx.GetOrganizationService(); var executor = new RetrieveEntityRequestExecutor(); ctx.AddFakeMessageExecutor <RetrieveEntityRequest>(executor); var request = new RetrieveEntityRequest() { LogicalName = Account.EntityLogicalName }; Assert.Throws <Exception>(() => service.Execute(request)); }
public void Should_Override_FakeMessageExecutor() { var context = new XrmFakedContext(); var service = context.GetFakedOrganizationService(); var e = new Entity("Contact") { Id = Guid.NewGuid() }; context.Initialize(new[] { e }); context.AddFakeMessageExecutor<RetrieveEntityRequest>(new FakeRetrieveEntityRequestExecutor()); var inputs = new ParameterCollection { {"Target", e } }; context.ExecutePluginWith<CustomMockPlugin>(inputs, new ParameterCollection(), new EntityImageCollection(), new EntityImageCollection()); Assert.Equal("Successful", (string)e["response"]); Assert.DoesNotThrow(() => context.RemoveFakeMessageExecutor<RetrieveEntityRequest>()); }
public void When_calling_retrieve_entity_with_a_null_or_empty_logicalname_exception_is_thrown() { var ctx = new XrmFakedContext() { ProxyTypesAssembly = Assembly.GetAssembly(typeof(Account)) }; var service = ctx.GetOrganizationService(); var executor = new RetrieveEntityRequestExecutor(); ctx.AddFakeMessageExecutor <RetrieveEntityRequest>(executor); var request = new RetrieveEntityRequest() { LogicalName = "" }; Assert.Throws <Exception>(() => service.Execute(request)); }
public void UpdateViewsInCrmTest() { View view = new View() { name = "Name", description = "Description", fetchXml = "fetch", layoutXml = "layout", id = Guid.NewGuid(), }; Entity existingView = new Entity("savedquery", view.id) { ["name"] = "Name before", ["description"] = "Description before", ["fetchxml"] = "Before fetch", ["layoutxml"] = "Before layout" }; XrmFakedContext context = new XrmFakedContext(); PublishAllXmlRequestHandler publishHandler = new PublishAllXmlRequestHandler(); context.AddFakeMessageExecutor <PublishAllXmlRequest>(publishHandler); context.Initialize(existingView); IOrganizationService service = context.GetOrganizationService(); Program.UpdateViewsInCRM(new List <View>() { view }, service); QueryExpression query = new QueryExpression("savedquery"); query.ColumnSet = new ColumnSet(true); var result = service.RetrieveMultiple(query); Assert.AreEqual(1, result.Entities.Count); Entity updatedView = result.Entities[0]; Assert.AreEqual(view.name, updatedView["name"]); Assert.AreEqual(view.description, updatedView["description"]); Assert.AreEqual(view.fetchXml, updatedView["fetchxml"]); Assert.AreEqual(view.layoutXml, updatedView["layoutxml"]); Assert.AreEqual(true, publishHandler.published); }
public void When_calling_retrieve_entity_with_a_fake_attribute_definition_it_is_returned() { var ctx = new XrmFakedContext() { ProxyTypesAssembly = Assembly.GetAssembly(typeof(Account)) }; var service = ctx.GetOrganizationService(); var executor = new RetrieveEntityRequestExecutor(); executor.AddFakeEntityMetadata(Account.EntityLogicalName, new EntityMetadata() { IsCustomizable = new BooleanManagedProperty(true) }); var stringMetadata = new StringAttributeMetadata() { MaxLength = 200 }; stringMetadata.GetType().GetProperty("IsValidForCreate").SetValue(stringMetadata, new Nullable <bool>(true), null); executor.AddFakeAttributeMetadata(Account.EntityLogicalName, "name", stringMetadata); ctx.AddFakeMessageExecutor <RetrieveEntityRequest>(executor); var request = new RetrieveEntityRequest() { EntityFilters = EntityFilters.Attributes, LogicalName = Account.EntityLogicalName }; var response = service.Execute(request); Assert.IsType <RetrieveEntityResponse>(response); var nameAttribute = (response as RetrieveEntityResponse).EntityMetadata.Attributes .Where(a => a.SchemaName.Equals("name")) .FirstOrDefault(); Assert.True(nameAttribute.IsValidForCreate.Value); }
public void IsSameDay_Not_Same_Day1_User_Local() { //Arrange XrmFakedWorkflowContext workflowContext = new XrmFakedWorkflowContext(); EntityCollection userSettings = new EntityCollection(); Entity userSetting = new Entity("usersettings") { Id = Guid.NewGuid(), ["systemuserid"] = Guid.NewGuid(), ["timezonecode"] = 20 }; userSettings.Entities.Add(userSetting); var inputs = new Dictionary <string, object> { { "FirstDate", new DateTime(2015, 5, 2, 11, 36, 0) }, { "SecondDate", new DateTime(2015, 5, 1, 16, 49, 23) }, { "EvaluateAsUserLocal", true } }; XrmFakedContext xrmFakedContext = new XrmFakedContext(); xrmFakedContext.Initialize(new List <Entity> { userSetting }); xrmFakedContext.CallerId = new EntityReference("systemuser", userSetting.GetAttributeValue <Guid>("systemuserid")); var fakeLocalTimeFromUtcTimeRequestExecutor = new FakeLocalTimeFromUtcTimeRequestExecutor(new DateTime(2015, 5, 2, 5, 36, 0), new DateTime(2015, 5, 1, 11, 49, 23)); xrmFakedContext.AddFakeMessageExecutor <LocalTimeFromUtcTimeRequest>(fakeLocalTimeFromUtcTimeRequestExecutor); const bool expected = false; //Act var result = xrmFakedContext.ExecuteCodeActivity <IsSameDay>(workflowContext, inputs); //Assert Assert.AreEqual(expected, result["SameDay"]); }
public void GetFormattedDateString_2_Digit_24_Hour_Time_Only_User_Local() { //Arrange XrmFakedWorkflowContext workflowContext = new XrmFakedWorkflowContext(); EntityCollection userSettings = new EntityCollection(); Entity userSetting = new Entity("usersettings") { Id = Guid.NewGuid(), ["systemuserid"] = Guid.NewGuid(), ["timezonecode"] = 20 }; userSettings.Entities.Add(userSetting); var inputs = new Dictionary <string, object> { { "DateToUse", new DateTime(2015, 1, 1, 5, 15, 20, DateTimeKind.Utc) }, { "EvaluateAsUserLocal", true }, { "Format", "HH:mm" } }; XrmFakedContext xrmFakedContext = new XrmFakedContext(); xrmFakedContext.Initialize(new List <Entity> { userSetting }); xrmFakedContext.CallerId = new EntityReference("systemuser", userSetting.GetAttributeValue <Guid>("systemuserid")); var fakeLocalTimeFromUtcTimeRequestExecutor = new FakeLocalTimeFromUtcTimeRequestExecutor(); xrmFakedContext.AddFakeMessageExecutor <LocalTimeFromUtcTimeRequest>(fakeLocalTimeFromUtcTimeRequestExecutor); const string expected = "23:15"; //Act var result = xrmFakedContext.ExecuteCodeActivity <GetFormattedDateString>(workflowContext, inputs); //Assert Assert.AreEqual(expected, result["FormattedDateString"]); }
public void GetWeekNumberOfYear_Valid_Week_User_Local1() { //Arrange XrmFakedWorkflowContext workflowContext = new XrmFakedWorkflowContext(); EntityCollection userSettings = new EntityCollection(); Entity userSetting = new Entity("usersettings") { Id = Guid.NewGuid(), ["systemuserid"] = Guid.NewGuid(), ["timezonecode"] = 20 }; userSettings.Entities.Add(userSetting); var inputs = new Dictionary <string, object> { { "DateToUse", new DateTime(2015, 1, 1, 5, 0, 0, DateTimeKind.Utc) }, { "EvaluateAsUserLocal", true } }; XrmFakedContext xrmFakedContext = new XrmFakedContext(); xrmFakedContext.Initialize(new List <Entity> { userSetting }); xrmFakedContext.CallerId = new EntityReference("systemuser", userSetting.GetAttributeValue <Guid>("systemuserid")); var fakeLocalTimeFromUtcTimeRequestExecutor = new FakeLocalTimeFromUtcTimeRequestExecutor(new DateTime(2014, 12, 31, 23, 0, 0)); xrmFakedContext.AddFakeMessageExecutor <LocalTimeFromUtcTimeRequest>(fakeLocalTimeFromUtcTimeRequestExecutor); const int expected = 53; //Act var result = xrmFakedContext.ExecuteCodeActivity <GetWeekNumberOfYear>(workflowContext, inputs); //Assert Assert.AreEqual(expected, result["WeekNumberOfYear"]); }
public void AddsFakeVersionRequest() { var fakedContext = new XrmFakedContext(); var fakedService = fakedContext.GetFakedOrganizationService(); var fakeVersionExecutor = new RetrieveVersionRequestExecutor(); fakedContext.AddFakeMessageExecutor <RetrieveVersionRequest>(fakeVersionExecutor); var fakeVersionRequest = new RetrieveVersionRequest(); var result = (RetrieveVersionResponse)fakedService.Execute(fakeVersionRequest); var version = result.Version; var versionComponents = version.Split('.'); var majorVersion = versionComponents[0]; var minorVersion = versionComponents[1]; #if FAKE_XRM_EASY_9 Assert.True(int.Parse(majorVersion) >= 9); #elif FAKE_XRM_EASY_365 Assert.True(int.Parse(majorVersion) >= 8); if (majorVersion == "8") { Assert.True(int.Parse(minorVersion) >= 2); } #elif FAKE_XRM_EASY_2016 Assert.True(int.Parse(majorVersion) >= 8); Assert.True(int.Parse(minorVersion) >= 0); Assert.True(int.Parse(minorVersion) < 2); #elif FAKE_XRM_EASY_2015 Assert.True(version.StartsWith("7")); #elif FAKE_XRM_EASY_2013 Assert.True(version.StartsWith("6")); #elif FAKE_XRM_EASY Assert.True(version.StartsWith("5")); #endif }
public void SendEmail_Send() { //Arrange XrmFakedWorkflowContext workflowContext = new XrmFakedWorkflowContext(); var inputs = new Dictionary <string, object> { { "EmailToSend", new EntityReference("email", Guid.NewGuid()) } }; XrmFakedContext xrmFakedContext = new XrmFakedContext(); var fakeSendEmailRequestExecutor = new FakeSendEmailRequestExecutor(); xrmFakedContext.AddFakeMessageExecutor <SendEmailRequest>(fakeSendEmailRequestExecutor); const bool expected = true; //Act var result = xrmFakedContext.ExecuteCodeActivity <SendEmail>(workflowContext, inputs); //Assert Assert.AreEqual(expected, result["EmailSent"]); }
private string ConvertFetchToOData(string fetch) { var context = new XrmFakedContext(); // Add basic metadata var relationships = new[] { new OneToManyRelationshipMetadata { SchemaName = "contact_customer_accounts", ReferencedEntity = "account", ReferencedAttribute = "accountid", ReferencingEntity = "contact", ReferencingAttribute = "parentcustomerid" }, new OneToManyRelationshipMetadata { SchemaName = "account_primarycontact", ReferencedEntity = "contact", ReferencedAttribute = "contactid", ReferencingEntity = "account", ReferencingAttribute = "primarycontactid" } }; var entities = new[] { new EntityMetadata { LogicalName = "account", EntitySetName = "accounts" }, new EntityMetadata { LogicalName = "contact", EntitySetName = "contacts" }, new EntityMetadata { LogicalName = "connection", EntitySetName = "connections" }, new EntityMetadata { LogicalName = "webresource", EntitySetName = "webresourceset" }, new EntityMetadata { LogicalName = "stringmap", EntitySetName = "stringmaps" }, new EntityMetadata { LogicalName = "incident", EntitySetName = "incidents" } }; var attributes = new Dictionary <string, AttributeMetadata[]> { ["account"] = new AttributeMetadata[] { new UniqueIdentifierAttributeMetadata { LogicalName = "accountid" }, new StringAttributeMetadata { LogicalName = "name" }, new StringAttributeMetadata { LogicalName = "websiteurl" }, new LookupAttributeMetadata { LogicalName = "primarycontactid", Targets = new[] { "contact" } } }, ["contact"] = new AttributeMetadata[] { new UniqueIdentifierAttributeMetadata { LogicalName = "contactid" }, new StringAttributeMetadata { LogicalName = "firstname" }, new LookupAttributeMetadata { LogicalName = "parentcustomerid", Targets = new[] { "account", "contact" } }, new DateTimeAttributeMetadata { LogicalName = "createdon" } }, ["connection"] = new AttributeMetadata[] { new UniqueIdentifierAttributeMetadata { LogicalName = "connectionid" }, new PicklistAttributeMetadata { LogicalName = "record1objecttypecode" } }, ["incident"] = new AttributeMetadata[] { new UniqueIdentifierAttributeMetadata { LogicalName = "incidentid" } }, ["stringmap"] = new AttributeMetadata[] { new UniqueIdentifierAttributeMetadata { LogicalName = "stringmapid" }, new EntityNameAttributeMetadata { LogicalName = "objecttypecode" }, new StringAttributeMetadata { LogicalName = "attributename" }, new IntegerAttributeMetadata { LogicalName = "attributevalue" }, new StringAttributeMetadata { LogicalName = "value" } }, ["webresource"] = new AttributeMetadata[] { new UniqueIdentifierAttributeMetadata { LogicalName = "webresourceid" }, new StringAttributeMetadata { LogicalName = "name" }, new ManagedPropertyAttributeMetadata { LogicalName = "iscustomizable" } } }; SetSealedProperty(attributes["webresource"].Single(a => a.LogicalName == "iscustomizable"), nameof(ManagedPropertyAttributeMetadata.ValueAttributeTypeCode), AttributeTypeCode.Boolean); SetRelationships(entities, relationships); SetAttributes(entities, attributes); SetSealedProperty(entities.Single(e => e.LogicalName == "incident"), nameof(EntityMetadata.ObjectTypeCode), 112); foreach (var entity in entities) { context.SetEntityMetadata(entity); } context.AddFakeMessageExecutor <RetrieveAllEntitiesRequest>(new RetrieveAllEntitiesRequestExecutor(entities)); var org = context.GetOrganizationService(); var converter = new FetchXmlToWebAPIConverter(new MetadataProvider(org), $"https://example.crm.dynamics.com/api/data/v9.0"); return(converter.ConvertFetchXmlToWebAPI(fetch)); }
public void EmailConnection_1_SystemUser_Disabled_0_Existing() { //Arrange XrmFakedWorkflowContext workflowContext = new XrmFakedWorkflowContext { PrimaryEntityId = Guid.NewGuid() }; Guid id = Guid.NewGuid(); Entity email = new Entity("email") { Id = id, ["activityid"] = id, ["to"] = new EntityCollection() }; Entity systemUser = new Entity("systemuser") { Id = Guid.NewGuid(), ["internalemailaddress"] = "*****@*****.**", ["isdisabled"] = true }; Entity connectionRole = new Entity("connectionrole") { Id = Guid.NewGuid() }; Entity connection = new Entity("connection") { Id = Guid.NewGuid(), ["record1id"] = new EntityReference("systemuser", workflowContext.PrimaryEntityId), ["record1objecttypecode"] = new OptionSetValue(8), ["record2id"] = systemUser.ToEntityReference(), ["record2objecttypecode"] = new OptionSetValue(8), ["record2roleid"] = connectionRole.Id }; var inputs = new Dictionary <string, object> { { "EmailToSend", email.ToEntityReference() }, { "ConnectionRole", connectionRole.ToEntityReference() }, { "IncludeOppositeConnection", false }, { "SendEmail", false } }; XrmFakedContext xrmFakedContext = new XrmFakedContext(); xrmFakedContext.Initialize(new List <Entity> { email, systemUser, connectionRole, connection }); var fakeRetrieveMetadataChangesRequest = new FakeRetrieveMetadataChangesRequestExecutor("systemuser"); xrmFakedContext.AddFakeMessageExecutor <RetrieveMetadataChangesRequest>(fakeRetrieveMetadataChangesRequest); const int expected = 0; //Act var result = xrmFakedContext.ExecuteCodeActivity <EmailConnection>(workflowContext, inputs); //Assert Assert.AreEqual(expected, result["UsersAdded"]); }
public void EmailConnection_1_Account_1_Existing() { //Arrange XrmFakedWorkflowContext workflowContext = new XrmFakedWorkflowContext { PrimaryEntityId = Guid.NewGuid() }; Guid id = Guid.NewGuid(); Entity email = new Entity("email") { Id = id, ["activityid"] = id }; Guid id2 = Guid.NewGuid(); Entity activityParty = new Entity("activityparty") { Id = id2, ["activitypartyid"] = id2, ["activityid"] = email.ToEntityReference(), ["partyid"] = new EntityReference("contact", Guid.NewGuid()), ["participationtypemask"] = new OptionSetValue(2) }; EntityCollection to = new EntityCollection(); to.Entities.Add(activityParty); email["to"] = to; Entity account = new Entity("account") { Id = Guid.NewGuid(), ["emailaddress1"] = "*****@*****.**", ["statecode"] = new OptionSetValue(0) }; Entity connectionRole = new Entity("connectionrole") { Id = Guid.NewGuid() }; Entity connection = new Entity("connection") { Id = Guid.NewGuid(), ["record1id"] = new EntityReference("systemuser", workflowContext.PrimaryEntityId), ["record1objecttypecode"] = new OptionSetValue(8), ["record2id"] = account.ToEntityReference(), ["record2objecttypecode"] = new OptionSetValue(1), ["record2roleid"] = connectionRole.Id }; var inputs = new Dictionary <string, object> { { "EmailToSend", email.ToEntityReference() }, { "ConnectionRole", connectionRole.ToEntityReference() }, { "IncludeOppositeConnection", false }, { "SendEmail", false } }; XrmFakedContext xrmFakedContext = new XrmFakedContext(); xrmFakedContext.Initialize(new List <Entity> { email, account, connectionRole, connection, activityParty }); var fakeRetrieveMetadataChangesRequest = new FakeRetrieveMetadataChangesRequestExecutor("account"); xrmFakedContext.AddFakeMessageExecutor <RetrieveMetadataChangesRequest>(fakeRetrieveMetadataChangesRequest); const int expected = 2; //Act var result = xrmFakedContext.ExecuteCodeActivity <EmailConnection>(workflowContext, inputs); //Assert Assert.AreEqual(expected, result["UsersAdded"]); }