public void GetStoreByUserTest()
        {
            _fakedContext.ProxyTypesAssembly = Assembly.GetAssembly(typeof(CrmEarlyBound.Contact));
            var user   = new EntityReference("systemuser", _ownerId);
            var inputs = new Dictionary <string, object>()
            {
                { "User", user }
            };
            var store = _fakedContext.ExecuteCodeActivity <GetUsersStoreActivity>(inputs);

            Assert.AreEqual(((EntityReference)store["Store"]).Id, _storeId);
            Assert.AreEqual(((EntityReference)store["Login"]).Id, _externalLoginId);
        }
        public void RetrieveSecurityRole_IslnRole()
        {
            fakedContext.ProxyTypesAssembly = Assembly.GetAssembly(typeof(CrmEarlyBound.Queue));
            var inputs = new Dictionary <string, object>()
            {
                { "DeptBaseSecurityRoleName", "System Administrator" }
            };

            fakedContext.CallerId = new EntityReference("systemuser", u2Id);
            var result   = fakedContext.ExecuteCodeActivity <ExecutingUserInDepartmentActivity>(inputs);
            var expected = true;

            Assert.AreEqual(expected, (bool)result["IsInRole"]);
        }
Exemple #3
0
        public void Random_Has_Correct_Length()
        {
            //Arrange
            XrmFakedWorkflowContext workflowContext = new XrmFakedWorkflowContext();

            var inputs = new Dictionary <string, object>
            {
                { "Length", 8 },
                { "IncludeUpperCaseLetters", true },
                { "IncludeLowerCaseLetters", true },
                { "IncludeNumbers", true },
                { "IncludeSpecialCharacters", true },
                { "AllowedCharacters", null }
            };

            XrmFakedContext xrmFakedContext = new XrmFakedContext();

            const int expected = 8;

            //Act
            var result = xrmFakedContext.ExecuteCodeActivity <Random>(workflowContext, inputs);

            //Assert
            Assert.AreEqual(expected, result["RandomString"].ToString().Length);
        }
Exemple #4
0
        public void Random_Only_Uses_LowerCase_And_UpperCase()
        {
            //Arrange
            XrmFakedWorkflowContext workflowContext = new XrmFakedWorkflowContext();

            const string allowedCharacters = LowerCaseLetters + UpperCaseLetters;

            var inputs = new Dictionary <string, object>
            {
                { "Length", 5 },
                { "IncludeUpperCaseLetters", true },
                { "IncludeLowerCaseLetters", true },
                { "IncludeNumbers", false },
                { "IncludeSpecialCharacters", false },
                { "AllowedCharacters", null }
            };

            XrmFakedContext xrmFakedContext = new XrmFakedContext();

            //Act
            var result = xrmFakedContext.ExecuteCodeActivity <Random>(workflowContext, inputs);

            //Assert
            bool valid = result["RandomString"].ToString().All(c => allowedCharacters.Contains(c));

            Assert.IsTrue(valid);
        }
Exemple #5
0
        public void AddressCreate_Success()
        {
            var fakedContext = new XrmFakedContext();
            //input object does not contain to record id which is mandatory.
            string InputLoad = @"
                 {
                      recordtype: 'contact',
                      recordid: '37e64f21-c035-4e49-a6b6-958cdd3af45e',
                      'address': {
                        'type': 1,
                        'uprn': 3458999,
                        'buildingname': 'Horizon',
                        'buildingnumber': '3',
                        'street': 'Road',
                        'locality': '',
                        'town': '',
                        'postcode': '12345678',
                        'country': 'gbr',
                        'fromcompanieshouse': ''
                      }
                    }

                ";


            //Inputs
            var inputs = new Dictionary <string, object>()
            {
                {
                    "ReqPayload", InputLoad
                },
            };

            Contact fakeContact = new Contact();

            fakeContact.ContactId = new Guid("37e64f21-c035-4e49-a6b6-958cdd3af45e");
            fakeContact.Id        = new Guid("37e64f21-c035-4e49-a6b6-958cdd3af45e");

            defra_country Country = new defra_country();

            Country.defra_isocodealpha3 = "GBR";
            Country.Id = Guid.NewGuid();
            fakedContext.Initialize(new List <Entity>()
            {
                Country, fakeContact
            });
            var result  = fakedContext.ExecuteCodeActivity <AddAddress>(inputs);
            var address = fakedContext.CreateQuery <defra_address>();



            #region ErrorMessagesToCheck

            #endregion

            String          ReturnMessage         = (String)result["ResPayload"];
            AddressResponse AddressResponseObject = Newtonsoft.Json.JsonConvert.DeserializeObject <AddressResponse>(ReturnMessage);
            String          ErrorDetails          = AddressResponseObject.message;
            Assert.IsNotNull(AddressResponseObject.data.addressid);
        }
        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 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"]);
        }
Exemple #8
0
        public void CheckEntityMergeWithValidEntityMerge()
        {
            Guid entityMergeId = Guid.NewGuid();
            var  context       = new XrmFakedContext();

            // create setup contact records
            var contact1Guid = Guid.NewGuid();
            var contact1     = new Entity("contact", contact1Guid);
            var contact2Guid = Guid.NewGuid();
            var contact2     = new Entity("contact", contact2Guid);

            // create setup entity merge records
            var entityMerge = new Entity("tc_entitymerge", entityMergeId);

            entityMerge.Attributes.Add(Attributes.EntityMerge.Master, contact1.ToEntityReference());
            entityMerge.Attributes.Add(Attributes.EntityMerge.Subordinate, contact2.ToEntityReference());

            var inputs = new Dictionary <string, object>()
            {
                { "EntityMerge", entityMerge.ToEntityReference() }
            };

            var entityMerges = new Dictionary <Guid, Entity>();

            entityMerges.Add(entityMergeId, entityMerge);
            context.Data.Add("tc_entitymerge", entityMerges);

            var contacts = new Dictionary <Guid, Entity>();

            contacts.Add(contact1Guid, contact1);
            contacts.Add(contact2Guid, contact2);
            context.Data.Add("contact", contacts);

            var result = context.ExecuteCodeActivity <MergeCustomerActivity>(inputs);
        }
        public void EmailSecurityRole_1_Role_0_Users_0_Existing()
        {
            //Arrange
            XrmFakedWorkflowContext workflowContext = new XrmFakedWorkflowContext();

            Guid   id    = Guid.NewGuid();
            Entity email = new Entity("email")
            {
                Id             = id,
                ["activityid"] = id,
                ["to"]         = new EntityCollection()
            };

            var inputs = new Dictionary <string, object>
            {
                { "EmailToSend", email.ToEntityReference() },
                { "RecipientRole", Guid.NewGuid().ToString() },
                { "SendEmail", false }
            };

            XrmFakedContext xrmFakedContext = new XrmFakedContext();

            xrmFakedContext.Initialize(new List <Entity> {
                email
            });
            const int expected = 0;

            //Act
            var result = xrmFakedContext.ExecuteCodeActivity <EmailSecurityRole>(workflowContext, inputs);

            //Assert
            Assert.AreEqual(expected, result["UsersAdded"]);
        }
        public void When_Passing_Wrong_Service_RequestId_Should_Return_Null_WorkOrder()
        {
            XrmFakedContext fakedContext        = new XrmFakedContext();
            Entity          serviceRequest      = new Entity("incident", Guid.NewGuid());
            Entity          wrongServiceRequest = new Entity("incident", Guid.NewGuid());
            Entity          workOrder           = new Entity("msdyn_workorder", Guid.NewGuid());

            workOrder["msdyn_servicerequest"] = serviceRequest.ToEntityReference();
            workOrder["statuscode"]           = new OptionSetValue((int)StatusCode_WO.Active);
            fakedContext.Initialize(new List <Entity>()
            {
                serviceRequest, workOrder
            });
            var inputs = new Dictionary <string, object>()
            {
                { "ServiceRequestId", wrongServiceRequest.ToEntityReference() }
            };
            var outputParameter = fakedContext.ExecuteCodeActivity <GetWorkOrderRelatedServiceRequest>(inputs);
            var isExists        = (bool)outputParameter["IsExists"];

            Assert.IsFalse(isExists);
            var workOrderId = outputParameter["WorkOrderId"] as EntityReference;

            Assert.IsNull(workOrderId);
        }
Exemple #11
0
        public void ActionGetToken()
        {
            var registro = GetRegistroToken();

            fakedContext.Initialize(new List <Entity>()
            {
                registro
            });
            var inputs = new Dictionary <string, Object> {
                { "TokenConfig", registro.ToEntityReference() }
            };
            var codeActivity = new JwtTokenAction();
            var result1      = fakedContext.ExecuteCodeActivity <JwtTokenAction>(wfContext, inputs, codeActivity);

            Assert.IsTrue((bool)result1["Sucess"], (string)result1["Message"]);
        }
        public void DeleteAttachmentByName_Found_One_Match()
        {
            //Arrange
            XrmFakedWorkflowContext workflowContext = new XrmFakedWorkflowContext();

            Entity note1 = new Entity("annotation")
            {
                Id             = Guid.NewGuid(),
                ["filesize"]   = 5000,
                ["filename"]   = "test.txt",
                ["isdocument"] = true
            };

            var inputs = new Dictionary <string, object>
            {
                { "NoteWithAttachment", note1.ToEntityReference() },
                { "FileName", "test.txt" },
                { "AppendNotice", false }
            };

            XrmFakedContext xrmFakedContext = new XrmFakedContext();

            xrmFakedContext.Initialize(new List <Entity> {
                note1
            });

            const int expected = 1;

            //Act
            var result = xrmFakedContext.ExecuteCodeActivity <DeleteAttachmentByName>(workflowContext, inputs);

            //Assert
            Assert.AreEqual(expected, result["NumberOfAttachmentsDeleted"]);
        }
        public void When_Passing_UserWithMisMatchEmailAddress_NullContactReturned()
        {
            XrmFakedContext fakedContextLocal = new XrmFakedContext();
            var             user = new Entity("systemuser");

            user.Id = new Guid("884A078B-0467-E711-80F5-3863BB3C0660");
            user["internalemailaddress"] = "*****@*****.**";

            var contact = new Entity("contact");

            contact.Id = new Guid("884A078B-0467-E711-80F5-3863BB3C0660");
            contact["emailaddress1"] = "*****@*****.**";

            fakedContextLocal.Initialize(new List <Entity>()
            {
                user, contact
            });
            var inputs = new Dictionary <string, object>()
            {
                { "CurrentUserId", user.ToEntityReference() }
            };
            var outputParameter = fakedContextLocal.ExecuteCodeActivity <GetContactByUser>(inputs);
            var relatedContact  = outputParameter["ContactRelatedToUser"] as EntityReference;

            Assert.IsNull(relatedContact);
        }
        public void Should_assign_target_to_specified_existing_team()
        {
            var ctx = new XrmFakedContext();

            var team = new Team()
            {
                Id = Guid.NewGuid(), Name = "Admin Team"
            };
            var contact = new Contact()
            {
                Id = Guid.NewGuid(), FirstName = "Leo", LastName = "Messi"
            };

            ctx.Initialize(new List <Entity>()
            {
                team, contact
            });

            Dictionary <string, object> inputs = new Dictionary <string, object>()
            {
                { "TeamName", "Admin Team" },
                { "EntityName", "contact" },
                { "EntityId", contact.Id.ToString() }
            };
            var outputs = ctx.ExecuteCodeActivity <AssignToTeamWithName>(inputs);

            Assert.True((bool)outputs["Succeeded"]);

            var contactAfter = ctx.CreateQuery <Contact>().FirstOrDefault();

            Assert.Equal(team.Id, contactAfter.OwnerId.Id);
        }
Exemple #15
0
        public void Metric_Aggregation_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 },
                { "Name", "Hello from TraceTest - 2" },
                { "MetricValue", 456 },
                { "Count", 1 },
                { "Min", 456 },
                { "Max", 456 },
                { "StdDev", 0 }
            };

            XrmFakedContext xrmFakedContext       = new XrmFakedContext();
            var             fakeLogActionExecutor = new FakeLogActionExecutor("lat_ApplicationInsightsLogMetric");

            xrmFakedContext.AddFakeMessageExecutor <OrganizationRequest>(fakeLogActionExecutor);

            var result = xrmFakedContext.ExecuteCodeActivity <LogMetric>(workflowContext, inputs);

            Assert.IsTrue(bool.Parse(result["LogSuccess"].ToString()));
        }
Exemple #16
0
        public void DeleteNote_Delete()
        {
            //Arrange
            XrmFakedWorkflowContext workflowContext = new XrmFakedWorkflowContext();

            Entity note = new Entity("annotation")
            {
                Id = Guid.NewGuid()
            };

            var inputs = new Dictionary <string, object>
            {
                { "NoteToDelete", note.ToEntityReference() }
            };

            XrmFakedContext xrmFakedContext = new XrmFakedContext();

            xrmFakedContext.Initialize(new List <Entity> {
                note
            });

            const bool expected = true;

            //Act
            var result = xrmFakedContext.ExecuteCodeActivity <DeleteNote>(workflowContext, inputs);

            //Assert
            Assert.AreEqual(expected, result["WasNoteDeleted"]);
        }
Exemple #17
0
        public void Metric_Measurement_Test()
        {
            Guid userId = Guid.Parse("9e7ec57b-3a08-4a41-a4d4-354d66f19b65");
            XrmFakedWorkflowContext workflowContext = new XrmFakedWorkflowContext
            {
                WorkflowCategory   = 0,
                InitiatingUserId   = userId,
                UserId             = userId,
                CorrelationId      = Guid.Parse("15cc775b-9ebc-48d1-93a6-b0ce9c920b66"),
                MessageName        = "Update",
                Mode               = 1,
                Depth              = 1,
                OrganizationName   = "test.crm.dynamics.com",
                OperationCreatedOn = DateTime.Now
            };

            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 },
                { "Name", "Hello from TraceTest - 2" },
                { "MetricValue", 456 }
            };

            XrmFakedContext xrmFakedContext       = new XrmFakedContext();
            var             fakeLogActionExecutor = new FakeLogActionExecutor("lat_ApplicationInsightsLogMetric");

            xrmFakedContext.AddFakeMessageExecutor <OrganizationRequest>(fakeLogActionExecutor);

            var result = xrmFakedContext.ExecuteCodeActivity <LogMetric>(workflowContext, inputs);

            Assert.IsTrue(bool.Parse(result["LogSuccess"].ToString()));
        }
Exemple #18
0
        public void Event_Invalid_Measurement_Name_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 },
                { "Name", null },
                { "MeasurementName", "sisznxevfkzibsdtsvfwijucumzedrzauyzzyzqmrrmdwwdqugtiprgvgkmpokcoldnxcmlwywcuernvoobnfogzgjkbnsteycrvafpharlnylyvyigsnskjuwwqjeiudwkibztwzwwotfbaijxcqwwk" },
                { "MeasurementValue", 4622d }
            };

            XrmFakedContext xrmFakedContext       = new XrmFakedContext();
            var             fakeLogActionExecutor = new FakeLogActionExecutor("lat_ApplicationInsightsLogEvent");

            xrmFakedContext.AddFakeMessageExecutor <OrganizationRequest>(fakeLogActionExecutor);

            var result = xrmFakedContext.ExecuteCodeActivity <LogEvent>(workflowContext, inputs);

            Assert.IsFalse(bool.Parse(result["LogSuccess"].ToString()));
        }
Exemple #19
0
        public void Event_Float_Value_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 },
                { "Name", "Test Log Event" },
                { "MeasurementName", "test" },
                { "MeasurementValue", 1.00000f }
            };

            XrmFakedContext xrmFakedContext       = new XrmFakedContext();
            var             fakeLogActionExecutor = new FakeLogActionExecutor("lat_ApplicationInsightsLogEvent");

            xrmFakedContext.AddFakeMessageExecutor <OrganizationRequest>(fakeLogActionExecutor);

            var result = xrmFakedContext.ExecuteCodeActivity <LogEvent>(workflowContext, inputs);

            Assert.IsTrue(bool.Parse(result["LogSuccess"].ToString()));
        }
        public void UpdateNoteTitle_Set_Null_Title()
        {
            //Arrange
            XrmFakedWorkflowContext workflowContext = new XrmFakedWorkflowContext();

            Entity note = new Entity("annotation")
            {
                Id = Guid.NewGuid()
            };

            var inputs = new Dictionary <string, object>
            {
                { "NoteToUpdate", note.ToEntityReference() },
                { "NewTitle", null }
            };

            XrmFakedContext xrmFakedContext = new XrmFakedContext();

            xrmFakedContext.Initialize(new List <Entity> {
                note
            });

            const string expected = null;

            //Act
            var result = xrmFakedContext.ExecuteCodeActivity <UpdateNoteTitle>(workflowContext, inputs);

            //Assert
            Assert.AreEqual(expected, result["UpdatedTitle"]);
        }
        public void DeleteAttachment_Not_Document()
        {
            //Arrange
            XrmFakedWorkflowContext workflowContext = new XrmFakedWorkflowContext();

            Entity note1 = new Entity("annotation")
            {
                Id             = Guid.NewGuid(),
                ["isdocument"] = false
            };

            var inputs = new Dictionary <string, object>
            {
                { "NoteWithAttachment", note1.ToEntityReference() },
                { "DeleteSizeMax", 75000 },
                { "DeleteSizeMin", 3000 },
                { "Extensions", "pdf" },
                { "AppendNotice", false }
            };

            XrmFakedContext xrmFakedContext = new XrmFakedContext();

            xrmFakedContext.Initialize(new List <Entity> {
                note1
            });

            const int expected = 0;

            //Act
            var result = xrmFakedContext.ExecuteCodeActivity <DeleteAttachment>(workflowContext, inputs);

            //Assert
            Assert.AreEqual(expected, result["NumberOfAttachmentsDeleted"]);
        }
Exemple #22
0
        public void CheckAttachment_Has_Attachment()
        {
            //Arrange
            XrmFakedWorkflowContext workflowContext = new XrmFakedWorkflowContext();

            Entity note = new Entity("annotation")
            {
                Id = Guid.NewGuid(),
                ["documentbody"] = "412321",
                ["filesize"]     = 1,
                ["filename"]     = "test.txt",
                ["isdocument"]   = true
            };

            var inputs = new Dictionary <string, object>
            {
                { "NoteToCheck", note.ToEntityReference() }
            };

            XrmFakedContext xrmFakedContext = new XrmFakedContext();

            xrmFakedContext.Initialize(new List <Entity> {
                note
            });

            const bool expected = true;

            //Act
            var result = xrmFakedContext.ExecuteCodeActivity <CheckAttachment>(workflowContext, inputs);

            //Assert
            Assert.AreEqual(expected, result["HasAttachment"]);
        }
Exemple #23
0
        public void CheckAttachment_No_Attachment()
        {
            //Arrange
            XrmFakedWorkflowContext workflowContext = new XrmFakedWorkflowContext();

            Entity note = new Entity("annotation")
            {
                Id             = Guid.NewGuid(),
                ["isdocument"] = false,
            };

            var inputs = new Dictionary <string, object>
            {
                { "NoteToCheck", note.ToEntityReference() }
            };

            XrmFakedContext xrmFakedContext = new XrmFakedContext();

            xrmFakedContext.Initialize(note);

            const bool expected = false;

            //Act
            var result = xrmFakedContext.ExecuteCodeActivity <CheckAttachment>(workflowContext, inputs);

            //Assert
            Assert.AreEqual(expected, result["HasAttachment"]);
        }
        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"]);
        }
Exemple #25
0
        public void CheckAttachments_Zero_Attachments()
        {
            //Arrange
            XrmFakedWorkflowContext workflowContext = new XrmFakedWorkflowContext();

            Guid   id    = Guid.NewGuid();
            Entity email = new Entity("email")
            {
                Id             = id,
                ["activityid"] = id
            };

            var inputs = new Dictionary <string, object>
            {
                { "EmailToCheck", new EntityReference("email", email.Id) }
            };

            XrmFakedContext xrmFakedContext = new XrmFakedContext();

            xrmFakedContext.Initialize(new List <Entity> {
                email
            });

            const int  expectedAttachmentCount = 0;
            const bool expectedHasAttachments  = false;

            //Act
            var result = xrmFakedContext.ExecuteCodeActivity <CheckAttachments>(workflowContext, inputs);

            //Assert
            Assert.AreEqual(expectedAttachmentCount, result["AttachmentCount"]);
            Assert.AreEqual(expectedHasAttachments, result["HasAttachments"]);
        }
        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"]);
        }
Exemple #27
0
        public void EmailBusinessUnit_2_Users_Business_Unit_1_Disabled_With_No_Existing_Users()
        {
            //Arrange
            XrmFakedWorkflowContext workflowContext = new XrmFakedWorkflowContext();

            Guid   id    = Guid.NewGuid();
            Entity email = new Entity("email")
            {
                Id             = id,
                ["activityid"] = id,
                ["to"]         = new EntityCollection()
            };

            Entity businessUnit = new Entity("businessunit")
            {
                Id = Guid.NewGuid()
            };

            Entity user1 = new Entity("systemuser")
            {
                Id = Guid.NewGuid(),
                ["internalemailaddress"] = "*****@*****.**",
                ["businessunitid"]       = businessUnit.Id,
                ["accessmode"]           = 1,
                ["isdisabled"]           = false
            };

            Entity user2 = new Entity("systemuser")
            {
                Id = Guid.NewGuid(),
                ["internalemailaddress"] = "*****@*****.**",
                ["businessunitid"]       = businessUnit.Id,
                ["accessmode"]           = 1,
                ["isdisabled"]           = true
            };

            var inputs = new Dictionary <string, object>
            {
                { "EmailToSend", email.ToEntityReference() },
                { "RecipientBusinessUnit", businessUnit.ToEntityReference() },
                { "IncludeChildren", false },
                { "SendEmail", false }
            };

            XrmFakedContext xrmFakedContext = new XrmFakedContext();

            xrmFakedContext.Initialize(new List <Entity> {
                email, businessUnit, user1, user2
            });

            const int expected = 1;

            //Act
            var result = xrmFakedContext.ExecuteCodeActivity <EmailBusinessUnit>(workflowContext, inputs);

            //Assert
            Assert.AreEqual(expected, result["UsersAdded"]);
        }
        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_Passing_WrongUser_NullContactReturned()
        {
            var userId = new EntityReference
            {
                Id          = new Guid("A97F07A5-0004-419D-A930-B2828EE2FEAD"),
                Name        = "Steave",
                LogicalName = "systemuser"
            };


            var inputs = new Dictionary <string, object>()
            {
                { "CurrentUserId", userId }
            };
            var outputParameter = fakedContext.ExecuteCodeActivity <GetContactByUser>(inputs);
            var relatedContact  = outputParameter["ContactRelatedToUser"] as EntityReference;

            Assert.IsNull(relatedContact);
        }
        public void RetrieveParentRecord()
        {
            fakedContext.ProxyTypesAssembly = Assembly.GetAssembly(typeof(CrmEarlyBound.Queue));
            var inputs = new Dictionary <string, object>()
            {
                { "Expression", "incident||incident_customer_contacts;contact||contact_customer_accounts;account" }
            };

            //fakedContext.CallerId = new EntityReference("systemuser", u2Id);
            fakedContext.ExecuteCodeActivity <RetrieveParentRecordActivity>(inputs);
        }