public void ExecuteWorkflowOnEntityTest()
        {
            OrganizationRequest orgReq = null;
            Guid respId = Guid.NewGuid();
            MExecuteWorkflowResponse exwResp = new MExecuteWorkflowResponse();

            exwResp.IdGet = () => { return(respId); };
            MRetrieveMultipleResponse rtvresp = new MRetrieveMultipleResponse();
            EntityCollection          entcoll = new EntityCollection();

            entcoll.Entities.Add(new Entity());
            rtvresp.EntityCollectionGet = () => { return(entcoll); };
            BCrmServiceClient.AddResponse(typeof(ExecuteWorkflowRequest), exwResp);
            BCrmServiceClient.AddResponse(typeof(RetrieveMultipleRequest), rtvresp);
            BCrmServiceClient.MockCrmCommandExecute();
            MCrmServiceClient.AllInstances.GetDataByKeyFromResultsSetDictionaryOfStringObjectString <Guid>((objwbsvcaction, dict, str) =>
            {
                if (str == "parentworkflowid")
                {
                    return(Guid.Empty);
                }
                else
                {
                    return((Guid)respId);
                }
            });
            Guid result = crmaction.ExecuteWorkflowOnEntity("workflow1", respId);

            Assert.AreEqual(respId, result);
            orgReq = BCrmServiceClient.GetRequest(typeof(ExecuteWorkflowRequest));
            Assert.IsNotNull(((ExecuteWorkflowRequest)orgReq).WorkflowId);
        }
        public void GetEntityDataByFetchSearchTest()
        {
            OrganizationRequest orgReq = null;
            Guid respId = Guid.NewGuid();
            MRetrieveMultipleResponse rtrResp = new MRetrieveMultipleResponse();
            EntityCollection          entColl = new EntityCollection();

            entColl.Entities.Add(new Entity());
            rtrResp.EntityCollectionGet = () => { return(entColl); };
            MFetchXmlToQueryExpressionResponse ftcrsp = new MFetchXmlToQueryExpressionResponse();

            ftcrsp.QueryGet = () => { return(new QueryExpression()); };
            BCrmServiceClient.AddResponse(typeof(FetchXmlToQueryExpressionRequest), ftcrsp);
            BCrmServiceClient.AddResponse(typeof(RetrieveMultipleRequest), rtrResp);
            BCrmServiceClient.MockCrmCommandExecute();
            string fetch = "<fetch mapping='logical'>";

            fetch += "<entity name='account'><all-attributes/>";
            fetch += "</entity></fetch>";
            Dictionary <string, Dictionary <string, object> > Results = crmaction.GetEntityDataByFetchSearch(fetch);

            Assert.IsNotNull(Results);
            string strCookie;
            bool   blnmoreRecord;

            Results = crmaction.GetEntityDataByFetchSearch(fetch, 1, 1, "", out strCookie, out blnmoreRecord);
            Assert.IsNotNull(Results);
            orgReq = BCrmServiceClient.GetRequest(typeof(RetrieveMultipleRequest));
            Assert.IsNotNull(((RetrieveMultipleRequest)orgReq).Query);
        }
        public void SubmitImportRequestTest()
        {
            Guid respid = Guid.NewGuid();
            OrganizationRequest orgReq = null;
            Guid asncId = Guid.NewGuid();

            MCrmServiceClient.AllInstances.CreateNewRecordStringDictionaryOfStringCrmDataTypeWrapperStringBooleanGuid = (objwbsvcact, dict, str, bln, guid, guid1) =>
            { return(respid); };
            MParseImportResponse prsResponse = new MParseImportResponse();

            prsResponse.AsyncOperationIdGet = () => asncId;
            BCrmServiceClient.AddResponse(typeof(ParseImportRequest), prsResponse);
            BCrmServiceClient.MockCrmCommandExecute();
            Dictionary <string, CrmDataTypeWrapper> newFields = new Dictionary <string, CrmDataTypeWrapper>();

            newFields.Add("name", new CrmDataTypeWrapper("CrudTestAccount", CrmFieldType.String));
            newFields.Add("accountnumber", new CrmDataTypeWrapper("12345", CrmFieldType.String));
            newFields.Add("telephone1", new CrmDataTypeWrapper("555-555-5555", CrmFieldType.String));
            newFields.Add("donotpostalmail", new CrmDataTypeWrapper(true, CrmFieldType.CrmBoolean));
            Guid toupdateId = Guid.NewGuid();

            CrmServiceClient.ImportRequest importRequest = new CrmServiceClient.ImportRequest();
            importRequest.Files.Add(new CrmServiceClient.ImportFileItem());
            DateTime dt     = new DateTime();
            Guid     result = crmaction.SubmitImportRequest(importRequest, dt);

            Assert.AreEqual(respid, result);
            orgReq = BCrmServiceClient.GetRequest(typeof(ImportRecordsImportRequest));
            Assert.IsNotNull(((ImportRecordsImportRequest)orgReq).ImportId);
            orgReq = BCrmServiceClient.GetRequest(typeof(ParseImportRequest));
            Assert.IsNotNull(((ParseImportRequest)orgReq).ImportId);
        }
        public void CreateOrUpdatePickListElementTest()
        {
            OrganizationRequest orgReq = null;
            Guid respId = Guid.NewGuid();
            MRetrieveEntityResponse rtventResp = new MRetrieveEntityResponse();
            MEntityMetadata         entmt      = new MEntityMetadata();

            entmt.IsCustomEntityGet      = () => { return(true); };
            rtventResp.EntityMetadataGet = () => { return(entmt); };
            BCrmServiceClient.AddResponse(typeof(RetrieveEntityRequest), rtventResp);
            BCrmServiceClient.MockCrmCommandExecute();
            List <AttributeData> lst1 = new List <AttributeData>();

            lst1.Add(new AttributeData());
            MDynamicEntityUtility.AllInstances.GetAttributeDataByEntityStringStringArray = (obj, str, arrstr) => { return(lst1); };
            List <LocalizedLabel> lst = new List <LocalizedLabel>();

            lst.Add(new LocalizedLabel());
            BCrmServiceClient.MockGetPickListElementFromMetadataEntity();
            bool result = crmaction.CreateOrUpdatePickListElement("account", "name", lst, 1, true);

            Assert.IsTrue(result);
            orgReq = BCrmServiceClient.GetRequest(typeof(InsertOptionValueRequest));
            Assert.IsNotNull(((InsertOptionValueRequest)orgReq).Value);
        }
        public void ExecuteCrmOrganizationRequestTest()
        {
            OrganizationRequest orgReq = new OrganizationRequest();

            BCrmServiceClient.MockCrmCommandExecute();
            OrganizationResponse orgRes = crmaction.ExecuteCrmOrganizationRequest(orgReq);

            Assert.IsNotNull(orgRes);
        }
        public void InstallSampleDataToCrm()
        {
            Guid respId = Guid.NewGuid();

            BCrmServiceClient.MockCrmCommandExecute();
            Guid result = crmaction.InstallSampleDataToCrm();

            Assert.AreEqual(BCrmServiceClient.GetRequest(typeof(InstallSampleDataRequest)).RequestId.Value, result);
        }
        public void UninstallSampleDataFromCrmTest()
        {
            Guid respId = Guid.NewGuid();

            BCrmServiceClient.MockCrmCommandExecute();
            MCrmServiceClient.AllInstances.IsSampleDataInstalled = (objwbsvcaction) => { return(CrmServiceClient.ImportStatus.Completed); };
            Guid result = crmaction.UninstallSampleDataFromCrm();

            Assert.AreEqual(BCrmServiceClient.GetRequest(typeof(UninstallSampleDataRequest)).RequestId.Value, result);
        }
        public void CloseTroubleTicketTest()
        {
            OrganizationRequest orgReq = null;
            Guid respId = Guid.NewGuid();

            BCrmServiceClient.MockCrmCommandExecute();
            Guid guid = crmaction.CloseTroubleTicket(respId, "", "");

            Assert.IsNotNull(guid);
            orgReq = BCrmServiceClient.GetRequest(typeof(CloseIncidentRequest));
            Assert.IsNotNull(((CloseIncidentRequest)orgReq).IncidentResolution);
        }
        public void GetEntityDisplayNamePluralTest()
        {
            Guid respId = Guid.NewGuid();
            MRetrieveEntityResponse orgResp = new MRetrieveEntityResponse();

            orgResp.EntityMetadataGet = () => { return(new EntityMetadata()); };
            BCrmServiceClient.AddResponse(typeof(RetrieveEntityRequest), orgResp);
            BCrmServiceClient.MockCrmCommandExecute();
            string result = crmaction.GetEntityDisplayNamePlural("account");

            Assert.IsNotNull(result);
        }
        public void SendSingleEmailTest()
        {
            OrganizationRequest orgReq = null;
            Guid respId = Guid.NewGuid();

            BCrmServiceClient.MockCrmCommandExecute();
            bool result = crmaction.SendSingleEmail(respId, "tokn");

            Assert.IsTrue(result);
            orgReq = BCrmServiceClient.GetRequest(typeof(SendEmailRequest));
            Assert.IsNotNull(((SendEmailRequest)orgReq).EmailId);
        }
        public void CloseActivityTest()
        {
            OrganizationRequest orgReq = null;
            Guid respId = Guid.NewGuid();

            BCrmServiceClient.MockCrmCommandExecute();
            BCrmServiceClient.MockGetPickListElementFromMetadataEntity();
            bool bln = crmaction.CloseActivity("", respId);

            Assert.IsTrue(bln);
            orgReq = BCrmServiceClient.GetRequest(typeof(SetStateRequest));
            Assert.IsNotNull(((SetStateRequest)orgReq).State);
        }
        public void DeleteEntityTest()
        {
            OrganizationRequest orgReq = null;

            BCrmServiceClient.MockCrmCommandExecute();
            Guid   toDeleteId   = Guid.NewGuid();
            string entityDelete = "account";
            bool   result       = crmaction.DeleteEntity(entityDelete, toDeleteId);

            Assert.IsTrue(result);
            orgReq = BCrmServiceClient.GetRequest(typeof(DeleteRequest));
            Assert.AreEqual(entityDelete, (((EntityReference)((DeleteRequest)orgReq).Target).LogicalName));
        }
        public void AssignEntityToUserTest()
        {
            OrganizationRequest orgReq = null;
            Guid respId = Guid.NewGuid();

            BCrmServiceClient.MockCrmCommandExecute();
            bool result = crmaction.AssignEntityToUser(respId, "account", respId);

            Assert.IsTrue(result);
            orgReq = BCrmServiceClient.GetRequest(typeof(AssignRequest));
            Assert.IsNotNull(((AssignRequest)orgReq).Assignee);
            Assert.IsNotNull(((AssignRequest)orgReq).Target);
        }
        public void GetEntityMetadata()
        {
            OrganizationRequest     orgReq = null;
            EntityMetadata          EM     = new EntityMetadata();
            MRetrieveEntityResponse resp   = new MRetrieveEntityResponse();

            resp.EntityMetadataGet = () => new EntityMetadata();
            BCrmServiceClient.AddResponse(typeof(RetrieveEntityRequest), resp);
            BCrmServiceClient.MockCrmCommandExecute();
            EM = crmaction.GetEntityMetadata("Account", EntityFilters.Default);
            Assert.IsNotNull(EM);
            orgReq = BCrmServiceClient.GetRequest(typeof(RetrieveEntityRequest));
            Assert.IsNotNull(((RetrieveEntityRequest)orgReq).LogicalName);
        }
        public void GetEntityFormIdListByType()
        {
            OrganizationRequest            orgReq = null;
            List <EntityReference>         lstRef = new List <EntityReference>();
            MRetrieveFilteredFormsResponse resp   = new MRetrieveFilteredFormsResponse();

            resp.SystemFormsGet = () => { return(new EntityReferenceCollection()); };
            BCrmServiceClient.AddResponse(typeof(RetrieveFilteredFormsRequest), resp);
            BCrmServiceClient.MockCrmCommandExecute();
            lstRef = crmaction.GetEntityFormIdListByType("contact", CrmServiceClient.FormTypeId.AppointmentBook);
            Assert.IsNotNull(lstRef);
            orgReq = BCrmServiceClient.GetRequest(typeof(RetrieveFilteredFormsRequest));
            Assert.IsNotNull(((RetrieveFilteredFormsRequest)orgReq).EntityLogicalName);
        }
        public void UpdateStateAndStatusForEntityTest()
        {
            OrganizationRequest orgReq = null;

            BCrmServiceClient.MockCrmCommandExecute();
            BCrmServiceClient.MockGetPickListElementFromMetadataEntity();
            Guid toupdateId = Guid.NewGuid();
            bool result     = crmaction.UpdateStateAndStatusForEntity("account", toupdateId, 1, 1);

            Assert.IsTrue(result);
            result = crmaction.UpdateStateAndStatusForEntity("account", toupdateId, "Completed", "2");
            Assert.IsTrue(result);
            orgReq = BCrmServiceClient.GetRequest(typeof(SetStateRequest));
            Assert.IsNotNull(((SetStateRequest)orgReq).State);
        }
        public void GetEntityAttributeMetadataForAttribute()
        {
            OrganizationRequest        orgReq = null;
            AttributeMetadata          AM     = new AttributeMetadata();
            MRetrieveAttributeResponse resp   = new MRetrieveAttributeResponse();

            BCrmServiceClient.AddResponse(typeof(RetrieveAttributeRequest), resp);
            resp.AttributeMetadataGet = () => new AttributeMetadata();
            BCrmServiceClient.MockCrmCommandExecute();
            AM = crmaction.GetEntityAttributeMetadataForAttribute("contact", "attribute");
            Assert.IsNotNull(AM);
            orgReq = BCrmServiceClient.GetRequest(typeof(RetrieveAttributeRequest));
            Assert.IsNotNull(((RetrieveAttributeRequest)orgReq).LogicalName);
            Assert.IsNotNull(((RetrieveAttributeRequest)orgReq).EntityLogicalName);
        }
        public void ImportDataMapToCrmTest()
        {
            OrganizationRequest orgReq = null;
            Guid respId = Guid.NewGuid();
            MImportMappingsImportMapResponse orgResp = new MImportMappingsImportMapResponse();

            orgResp.ImportMapIdGet = () => { return(respId); };
            BCrmServiceClient.AddResponse(typeof(ImportMappingsImportMapRequest), orgResp);
            BCrmServiceClient.MockCrmCommandExecute();
            Guid result = crmaction.ImportDataMapToCrm("samplexml");

            Assert.AreEqual(respId, result);
            orgReq = BCrmServiceClient.GetRequest(typeof(ImportMappingsImportMapRequest));
            Assert.IsNotNull(((ImportMappingsImportMapRequest)orgReq).MappingsXml);
        }
        public void GetEntityDisplayName()
        {
            OrganizationRequest     orgReq = null;
            MRetrieveEntityResponse resp   = new MRetrieveEntityResponse();

            resp.EntityMetadataGet = () => new EntityMetadata();
            BCrmServiceClient.AddResponse(typeof(RetrieveEntityRequest), resp);
            BCrmServiceClient.MockCrmCommandExecute();
            string entityName  = "account";
            string displayName = crmaction.GetEntityDisplayName(entityName);

            Assert.AreEqual(entityName, displayName);
            orgReq = BCrmServiceClient.GetRequest(typeof(RetrieveEntityRequest));
            Assert.AreEqual(entityName, ((RetrieveEntityRequest)orgReq).LogicalName);
        }
        public void CreateEntityAssociationTest()
        {
            OrganizationRequest orgReq = null;
            Guid respId = Guid.NewGuid();

            BCrmServiceClient.MockCrmCommandExecute();
            bool result = crmaction.CreateEntityAssociation("account", respId, "contact", respId, "somerelation");

            Assert.IsTrue(result);
            orgReq = BCrmServiceClient.GetRequest(typeof(AssociateEntitiesRequest));
            Assert.IsNotNull(((AssociateEntitiesRequest)orgReq).Moniker1);
            Assert.IsNotNull(((AssociateEntitiesRequest)orgReq).Moniker2);
            Assert.AreEqual(((AssociateEntitiesRequest)orgReq).RelationshipName, "somerelation");
            result = crmaction.CreateEntityAssociation("", respId, "", respId, "");
            Assert.IsFalse(result);
        }
        public void ImportSolutionToCrmTest()
        {
            OrganizationRequest orgReq = null;
            Guid respId = Guid.NewGuid();

            BCrmServiceClient.MockCrmCommandExecute();
            //file related moling
            MFile.ExistsString = (str) => { return(true); };
            byte[] fileData = new byte[1000 * 1000 * 3];
            MFile.ReadAllBytesString = (str) => { return(fileData); };
            Guid result = crmaction.ImportSolutionToCrm("solutionpath", out respId);

            Assert.IsNotNull(result);
            orgReq = BCrmServiceClient.GetRequest(typeof(ImportSolutionRequest));
            Assert.IsNotNull(((ImportSolutionRequest)orgReq).CustomizationFile);
        }
        public void CancelSalesOrderTest()
        {
            OrganizationRequest orgReq = null;
            Guid respId = Guid.NewGuid();

            BCrmServiceClient.MockCrmCommandExecute();
            Dictionary <string, CrmDataTypeWrapper> newFields = new Dictionary <string, CrmDataTypeWrapper>();

            newFields.Add("name", new CrmDataTypeWrapper("CrudTestAccount", CrmFieldType.String));
            newFields.Add("accountnumber", new CrmDataTypeWrapper("12345", CrmFieldType.String));
            Guid result = crmaction.CancelSalesOrder(respId, newFields);

            Assert.IsNotNull(result);
            orgReq = BCrmServiceClient.GetRequest(typeof(CancelSalesOrderRequest));
            Assert.IsNotNull(((CancelSalesOrderRequest)orgReq).OrderClose);
        }
        public void CreateNewActivityEntryTest()
        {
            OrganizationRequest orgReq = null;
            Guid            respId     = Guid.NewGuid();
            MCreateResponse orgResp    = new MCreateResponse();

            orgResp.idGet = () => respId;
            BCrmServiceClient.AddResponse(typeof(CreateRequest), orgResp);
            BCrmServiceClient.MockCrmCommandExecute();
            string activityName = "fax";
            Guid   id           = crmaction.CreateNewActivityEntry(activityName, "", respId, "testmail", "", "");

            Assert.AreEqual(respId, id);
            orgReq = BCrmServiceClient.GetRequest(typeof(CreateRequest));
            Assert.AreEqual(activityName, ((CreateRequest)orgReq).Target.LogicalName);
        }
        public void GetEntityTypeCodeTest()
        {
            OrganizationRequest     orgReq      = null;
            MRetrieveEntityResponse retriveResp = new MRetrieveEntityResponse();
            MEntityMetadata         ent         = new MEntityMetadata();

            ent.ObjectTypeCodeGet         = () => { return(1); };
            retriveResp.EntityMetadataGet = () => { return(ent); };
            BCrmServiceClient.AddResponse(typeof(RetrieveEntityRequest), retriveResp);
            BCrmServiceClient.MockCrmCommandExecute();
            string entityName = "account";
            string result     = crmaction.GetEntityTypeCode(entityName);

            Assert.IsNotNull(result);
            orgReq = BCrmServiceClient.GetRequest(typeof(RetrieveEntityRequest));
            Assert.AreEqual(entityName, ((RetrieveEntityRequest)orgReq).LogicalName);
        }
        public void CloseOpportunityTest()
        {
            OrganizationRequest orgReq = null;
            Guid respId = Guid.NewGuid();
            Guid oprtId = Guid.NewGuid();
            Guid actId  = Guid.NewGuid();

            BCrmServiceClient.MockCrmCommandExecute();
            Dictionary <string, CrmDataTypeWrapper> newFields = new Dictionary <string, CrmDataTypeWrapper>();

            newFields.Add("opportunityid", new CrmDataTypeWrapper(oprtId, CrmFieldType.UniqueIdentifier));
            newFields.Add("activityid", new CrmDataTypeWrapper(actId, CrmFieldType.UniqueIdentifier));
            Guid guid = crmaction.CloseOpportunity(respId, newFields);

            Assert.IsNotNull(guid);
            orgReq = BCrmServiceClient.GetRequest(typeof(WinOpportunityRequest));
            Assert.IsNotNull(((WinOpportunityRequest)orgReq).OpportunityClose);
        }
        public void CloseIncidentTest()
        {
            OrganizationRequest orgReq = null;
            Guid respId = Guid.NewGuid();
            Guid incdId = Guid.NewGuid();
            Guid actId  = Guid.NewGuid();

            BCrmServiceClient.MockCrmCommandExecute();
            Dictionary <string, CrmDataTypeWrapper> newFields = new Dictionary <string, CrmDataTypeWrapper>();

            newFields.Add("incidentid", new CrmDataTypeWrapper(incdId, CrmFieldType.UniqueIdentifier));
            newFields.Add("activityid", new CrmDataTypeWrapper(actId, CrmFieldType.UniqueIdentifier));
            Guid guid = crmaction.CloseIncident(respId, newFields);

            Assert.IsNotNull(guid);
            orgReq = BCrmServiceClient.GetRequest(typeof(CloseIncidentRequest));
            Assert.IsNotNull(((CloseIncidentRequest)orgReq).IncidentResolution);
        }
        public void CreateMultiEntityAssociationTest()
        {
            OrganizationRequest orgReq = null;
            Guid accountId             = Guid.NewGuid();
            Guid contactId             = Guid.NewGuid();

            BCrmServiceClient.MockCrmCommandExecute();
            List <Guid> lst = new List <Guid>();

            lst.Add(accountId);
            lst.Add(contactId);
            bool result = crmaction.CreateMultiEntityAssociation("account", contactId, "contact", lst, "some rel");

            Assert.IsTrue(result);
            orgReq = BCrmServiceClient.GetRequest(typeof(AssociateRequest));
            Assert.IsNotNull(((AssociateRequest)orgReq).RelatedEntities);
            Assert.IsNotNull(((AssociateRequest)orgReq).Target);
        }
        public void GetAllEntityMetadata()
        {
            Guid respId = Guid.NewGuid();
            MRetrieveAllEntitiesResponse resp = new MRetrieveAllEntitiesResponse();
            MEntityMetadata mtdata            = new MEntityMetadata();

            mtdata.ObjectTypeCodeGet = () => 1;
            mtdata.LogicalNameGet    = () => "account";
            resp.EntityMetadataGet   = () => new EntityMetadata[1] {
                mtdata
            };
            BCrmServiceClient.AddResponse(typeof(RetrieveAllEntitiesRequest), resp);
            BCrmServiceClient.MockCrmCommandExecute();
            List <EntityMetadata> LM = new List <EntityMetadata>();

            LM = crmaction.GetAllEntityMetadata();
            Assert.IsNotNull(LM);
        }
        public void GetEntityDataByLinkedSearchTest()
        {
            OrganizationRequest orgReq = null;
            Guid respId = Guid.NewGuid();

            MRetrieveMultipleResponse rtrResp = new MRetrieveMultipleResponse();
            EntityCollection          entColl = new EntityCollection();

            entColl.Entities.Add(new Entity());
            rtrResp.EntityCollectionGet = () => { return(entColl); };
            BCrmServiceClient.AddResponse(typeof(RetrieveMultipleRequest), rtrResp);
            BCrmServiceClient.MockCrmCommandExecute();
            Dictionary <string, Dictionary <string, object> > result = crmaction.GetEntityDataByLinkedSearch("account", new Dictionary <string, string>(), "contact", new Dictionary <string, string>(), "", "", "", new CrmServiceClient.LogicalSearchOperator(), new List <string>());

            Assert.IsNotNull(result);
            orgReq = BCrmServiceClient.GetRequest(typeof(RetrieveMultipleRequest));
            Assert.IsNotNull(((RetrieveMultipleRequest)orgReq).Query);
        }
        public void GetAllAttributesForEntity()
        {
            OrganizationRequest        orgReq = null;
            List <AttributeMetadata>   AM     = new List <AttributeMetadata>();
            MRetrieveAttributeResponse resp   = new MRetrieveAttributeResponse();

            resp.AttributeMetadataGet = () => new AttributeMetadata();
            MEntityMetadata metadata = new MEntityMetadata();

            metadata.AttributesGet = () => new AttributeMetadata[1] {
                new AttributeMetadata()
            };
            MMetadataUtility.AllInstances.GetEntityMetadataString = (objMutility, str) => { return(metadata); };
            BCrmServiceClient.AddResponse(typeof(RetrieveAttributeRequest), resp);
            BCrmServiceClient.MockCrmCommandExecute();
            AM = crmaction.GetAllAttributesForEntity("contact");
            Assert.IsNotNull(AM);
        }