public override void FormEmptyBulkFile()
        {
            PrimaryZone = new Bucket[NumberOfBuckets];

            RecordPointer recordPointer;
            BucketPointer bucketPointer;

            for (int i = 0; i < NumberOfBuckets; i++)
            {
                bucketPointer = new BucketPointer(Factor)
                {
                    Synonyms     = null,
                    Prev         = null,
                    Next         = null,
                    BlankRecords = Factor
                };
                for (int j = 0; j < Factor; j++)
                {
                    recordPointer = new RecordPointer()
                    {
                        Person = new Person()
                        {
                            Id       = 0,
                            FullName = null,
                            Adress   = null,
                            Age      = 0
                        },
                        Status     = Status.empty,
                        NextRecord = null
                    };
                    bucketPointer.Records[j] = recordPointer;
                }
                PrimaryZone[i] = bucketPointer;
            }
        }
            protected override void Test(IOrganizationService service)
            {
                //Test framework does not support the FetchXmlToQueryExpression so we fake the expected API result for the specified fetchXml.
                var fakedFetchQuery = new Microsoft.Xrm.Sdk.Query.QueryExpression()
                {
                    EntityName = "new_transactiondatarecord",
                    ColumnSet  = new Microsoft.Xrm.Sdk.Query.ColumnSet(new string[] { "new_transactiondatarecordid" }),
                    Criteria   = new Microsoft.Xrm.Sdk.Query.FilterExpression
                    {
                        FilterOperator = Microsoft.Xrm.Sdk.Query.LogicalOperator.And,
                        Conditions     =
                        {
                            new Microsoft.Xrm.Sdk.Query.ConditionExpression("new_datafield1", Microsoft.Xrm.Sdk.Query.ConditionOperator.Equal, "TestValue")
                        }
                    }
                };

                service = new OrganizationServiceBuilder()
                          .WithFakeExecute((s, r) => {
                    if (r.RequestName == "FetchXmlToQueryExpression")
                    {
                        FetchXmlToQueryExpressionResponse resp = new FetchXmlToQueryExpressionResponse();
                        resp.Results.Add("Query", fakedFetchQuery);
                        return(resp);
                    }
                    return(s.Execute(r));
                })
                          .Build();

                var executionContext   = GetExecutionContext(service);
                var serializer         = new DefaultSerializer();
                var transactionPointer = new RecordPointer <Guid>(Ids.ExistingTransaction.LogicalName, Ids.ExistingTransaction.EntityId);

                var transactionServiceFactory = Container.Resolve <ITransactionServiceFactory>();
                var transactionService        = transactionServiceFactory.CreateTransactionService(executionContext, false);

                var transaction = transactionService.LoadTransaction(executionContext, transactionPointer);

                var evaluatorType = new EvaluatorType.DataReccordQueryMatchEvaluator(
                    Ids.DataRecordQueryEvaluator.ToRecordPointer(), "TestEvaluator",
                    "S3.D365.Transactions",
                    "CCLLC.BTF.Process.CDS.EvaluatorType.DataReccordQueryMatchEvaluator");



                string parameterJson = "{\"FetchXml\":\"<fetch><entity name='new_transactiondatarecord'><filter type='and'><condition value='TestValue' attribute='new_datafield1' operator='eq'/></filter></entity></fetch>\"}";

                var parameters = serializer.CreateParamters(parameterJson);

                var result = evaluatorType.Evaluate(executionContext, parameters, transaction);

                Assert.AreEqual(true, result.Passed);
            }
            protected override void Test(IOrganizationService service)
            {
                service = new OrganizationServiceBuilder()
                          .WithFakeExecute((s, r) => {
                    if (r.RequestName == "new_Action")
                    {
                        Assert.AreEqual(Ids.ExistingDataRecord.EntityId, (r["Target"] as EntityReference).Id);
                        Assert.AreEqual(Ids.ExistingTransaction.EntityId, (r["Transaction"] as EntityReference).Id);
                        OrganizationResponse resp = new OrganizationResponse();
                        resp.Results["IsTrue"]    = false;
                        resp.Results["Message"]   = "Action did not succeed.";
                        return(resp);
                    }
                    return(s.Execute(r));
                })
                          .Build();

                var executionContext   = GetExecutionContext(service);
                var serializer         = new DefaultSerializer();
                var transactionPointer = new RecordPointer <Guid>(Ids.ExistingTransaction.LogicalName, Ids.ExistingTransaction.EntityId);

                var transactionServiceFactory = Container.Resolve <ITransactionServiceFactory>();
                var transactionService        = transactionServiceFactory.CreateTransactionService(executionContext, false);

                var transaction = transactionService.LoadTransaction(executionContext, transactionPointer);


                var evaluatorType = new EvaluatorType.DataRecordActionEvaluator(
                    Ids.DataActionEvaluator.ToRecordPointer(),
                    "TestEvaluator",
                    "S3.D365.Transactions",
                    "CCLLC.BTF.Process.CDS.EvaluatorType.DataReccordActionEvaluator");

                string parameterJson = "{\"ActionName\":\"new_Action\"}";

                var parameters = serializer.CreateParamters(parameterJson);

                var result = evaluatorType.Evaluate(executionContext, parameters, transaction);

                Assert.AreEqual(false, result.Passed);
                Assert.AreEqual("Action did not succeed.", result.Message);
            }
Exemple #4
0
        internal void GetAvailableTransactionTypeHandler(ICDSPluginExecutionContext executionContext)
        {
            var req = executionContext.CreateOrganizationRequest <ccllc_BTF_GetAvailableTransactionTypesRequest>();

            if (string.IsNullOrEmpty(req.ContextRecordType))
            {
                throw new ArgumentNullException("ContextRecordType cannot be null.");
            }
            if (string.IsNullOrEmpty(req.ContextRecordId))
            {
                throw new ArgumentNullException("ContextRecordId cannot be null.");
            }

            if (!Guid.TryParse(req.ContextRecordId, out Guid recordId))
            {
                throw new ArgumentException("ContextRecordId cannot be converted to a GUID.");
            }

            var contextRecordId = new RecordPointer <Guid>(req.ContextRecordType, recordId);

            var userId     = req.UserId ?? new EntityReference("systemuser", executionContext.InitiatingUserId);
            var systemUser = new SystemUser(userId.LogicalName, userId.Id, userId.Name);

            var platformManager = Container.Resolve <IPlatformService>();
            var session         = platformManager.GenerateSession(executionContext, systemUser);

            var contextFactory     = Container.Resolve <ITransactionContextFactory>();
            var transactionContext = contextFactory.CreateTransactionContext(executionContext, contextRecordId);


            var serviceFactory = Container.Resolve <ITransactionServiceFactory>();
            var service        = serviceFactory.CreateTransactionService(executionContext);

            var available = service.GetAvaialbleTransactionTypes(executionContext, session, transactionContext);

            executionContext.OutputParameters["TransactionTypes"] = available.Serialize();
        }
Exemple #5
0
        internal void InitiateTransactionHandler(ICDSPluginExecutionContext executionContext)
        {
            var req = (executionContext.CreateOrganizationRequest <ccllc_BTF_InitiateTransactionRequest>());

            if (string.IsNullOrEmpty(req.ContextRecordType))
            {
                throw new ArgumentNullException("ContextRecordType cannot be null.");
            }
            if (string.IsNullOrEmpty(req.ContextRecordId))
            {
                throw new ArgumentNullException("ContextRecordId cannot be null.");
            }

            if (!Guid.TryParse(req.ContextRecordId, out Guid recordId))
            {
                throw new ArgumentException("ContextRecordId cannot be converted to a GUID.");
            }

            var contextRecordId   = new RecordPointer <Guid>(req.ContextRecordType, recordId);
            var transactionTypeId = req.TransactionTypeId ?? throw new NullReferenceException("TransactionTypeId cannot be null");
            var userId            = req.UserId ?? new EntityReference("systemuser", executionContext.InitiatingUserId);

            var systemUser = new SystemUser(userId.LogicalName, userId.Id, userId.Name);

            var platformService = Container.Resolve <IPlatformService>();

            var session = platformService.GenerateSession(executionContext, systemUser);

            var contextFactory     = Container.Resolve <ITransactionContextFactory>();
            var transactionContext = contextFactory.CreateTransactionContext(executionContext, contextRecordId);

            var serviceFactory = Container.Resolve <ITransactionServiceFactory>();
            var service        = serviceFactory.CreateTransactionService(executionContext);

            var transactionType = service.GetAvaialbleTransactionTypes(executionContext, session, transactionContext).Where(r => r.Id == transactionTypeId.Id).FirstOrDefault();

            if (transactionType == null)
            {
                throw TransactionException.BuildException(TransactionException.ErrorCode.TransactionTypeNotFound);
            }

            var transaction = service.NewTransaction(executionContext, session, transactionContext, transactionType);

            IUIPointer uiPointer = null;

            if (transaction.CurrentStep.Type.IsUIStep)
            {
                uiPointer = transaction.CurrentStep.GetUIPointer(executionContext, transaction);
            }

            if (uiPointer == null)
            {
                // When current step is not a UI step, navigate the process forward which will execute process steps
                // until a UI step is found or the process is blocked by a validation issue.
                var step = transaction.NavigateForward(session);
                if (step.Type.IsUIStep)
                {
                    uiPointer = step.GetUIPointer(executionContext, transaction);
                }
            }

            if (uiPointer == null)
            {
                // At this point something is wrong so navigate the user to the transaction error form.
                uiPointer = new UIPointer
                {
                    UIDefinition = "TransactionError",
                    UIRecordId   = transaction.Id,
                    UIRecordType = "ccllc_transaction",
                    UIType       = eUIStepTypeEnum.DataForm
                };
            }

            executionContext.Trace("Adding UI Pointer to output parameters.");
            executionContext.OutputParameters["UIPointer"] = uiPointer.Serialize();
        }