예제 #1
0
        public void Should_Override_Execution_Mock()
        {
            var context = new XrmFakedContext();
            var service = context.GetFakedOrganizationService();

            var e = new Entity("Contact")
            {
                Id = Guid.NewGuid()
            };

            context.Initialize(new[] { e });
            context.AddExecutionMock <RetrieveEntityRequest>(RetrieveEntityMock);
            context.AddExecutionMock <RetrieveEntityRequest>(AnotherRetrieveEntityMock);

            var inputs = new ParameterCollection
            {
                { "Target", e }
            };

            context.ExecutePluginWith <CustomMockPlugin>(inputs, new ParameterCollection(), new EntityImageCollection(), new EntityImageCollection());

            Assert.Equal("Another", (string)e["response"]);
            var ex = Record.Exception(() => context.RemoveExecutionMock <RetrieveEntityRequest>());

            Assert.Null(ex);
        }
        public void ExternalLookup_Data()
        {
            // Verify that a lookup external to schema doesn't add anything.
            var fakedContext = new XrmFakedContext();

            fakedContext.InitializeMetadata(typeof(CrmEarlyBound.CrmServiceContext).Assembly);
            Entity AccountWithExternalLookup = new Entity("account", Guid.NewGuid());

            AccountWithExternalLookup["createdby"] = new EntityReference("systemuser", Guid.NewGuid());

            fakedContext.Initialize(AccountWithExternalLookup);
            fakedContext.AddExecutionMock <RetrieveEntityRequest>(req =>
            {
                var entityMetadata         = fakedContext.GetEntityMetadataByName(SupportMethods.AccountLogicalName);
                entityMetadata.DisplayName = new Label(SupportMethods.AccountDisplayName, 1033);

                var response = new RetrieveEntityResponse()
                {
                    Results = new ParameterCollection
                    {
                        { "EntityMetadata", entityMetadata }
                    }
                };
                return(response);
            });

            IOrganizationService fakedService = fakedContext.GetOrganizationService();

            DataBuilder DataBuilder = new DataBuilder(fakedService);

            DataBuilder.AppendData("<fetch><entity name='account'><attribute name='accountid'/><attribute name='createdby'/></entity></fetch>");

            Assert.IsTrue(DataBuilder.BuildDataXML().SelectSingleNode("entities/entity[@name='contact']") == null);
        }
예제 #3
0
        public void AppendDataUsingDictionariesLikePowerShell_Works()
        {
            // StringType           description                        knowledgearticle
            var fakedContext = new XrmFakedContext();

            fakedContext.InitializeMetadata(typeof(CrmEarlyBound.CrmServiceContext).Assembly);
            fakedContext.Initialize(SupportMethods.GetStringTypeEntity());
            fakedContext.AddExecutionMock <RetrieveEntityRequest>(req =>
            {
                var entityMetadata         = fakedContext.GetEntityMetadataByName(SupportMethods.KnowledgeArticleLogicalName);
                entityMetadata.DisplayName = new Label(SupportMethods.KnowledgeArticleDisplayName, 1033);
                var response = new RetrieveEntityResponse()
                {
                    Results = new ParameterCollection
                    {
                        { "EntityMetadata", entityMetadata }
                    }
                };
                return(response);
            });

            IOrganizationService fakedService = fakedContext.GetOrganizationService();

            DataBuilder DataBuilder = new DataBuilder(fakedService);

            DataBuilder.AppendData(SupportMethods.KnowledgeArticleLogicalName, SupportMethods.GetStringTypePowerShellObjects());
            Assert.AreEqual(
                DataBuilder.BuildDataXML().InnerXml,
                SupportMethods.GetStringTypeExpectedData());
        }
예제 #4
0
        public void UniqueidentifierType()
        {
            // UniqueidentifierType stageid                            knowledgearticle
            var fakedContext = new XrmFakedContext();

            fakedContext.InitializeMetadata(typeof(CrmEarlyBound.CrmServiceContext).Assembly);
            fakedContext.Initialize(SupportMethods.GetUniqueIdentifierTypeEntity());
            fakedContext.AddExecutionMock <RetrieveEntityRequest>(req =>
            {
                var entityMetadata         = fakedContext.GetEntityMetadataByName(SupportMethods.KnowledgeArticleLogicalName);
                entityMetadata.DisplayName = new Label(SupportMethods.KnowledgeArticleDisplayName, 1033);
                entityMetadata.Attributes.First(a => a.LogicalName == "stageid").SetSealedPropertyValue("AttributeType", Sdk.Metadata.AttributeTypeCode.Uniqueidentifier);

                var response = new RetrieveEntityResponse()
                {
                    Results = new ParameterCollection
                    {
                        { "EntityMetadata", entityMetadata }
                    }
                };
                return(response);
            });

            IOrganizationService fakedService = fakedContext.GetOrganizationService();

            DataBuilder DataBuilder = new DataBuilder(fakedService);

            DataBuilder.AppendData(SupportMethods.GetUniqueIdentifierTypeFetch());
            Assert.AreEqual(
                DataBuilder.BuildDataXML().InnerXml,
                SupportMethods.GetUniqueIdentifierTypeExpectedData());
        }
        public void MissingMetadata_Throws()
        {
            var fakedContext = new XrmFakedContext();

            fakedContext.InitializeMetadata(typeof(CrmEarlyBound.CrmServiceContext).Assembly);
            fakedContext.Initialize(SupportMethods.GetCustomerTypeEntity());
            fakedContext.AddExecutionMock <RetrieveEntityRequest>(req =>
            {
                var entityMetadata = fakedContext.GetEntityMetadataByName(String.Empty);
                var response       = new RetrieveEntityResponse()
                {
                    Results = new ParameterCollection
                    {
                        { "EntityMetadata", entityMetadata }
                    }
                };
                return(response);
            });

            IOrganizationService fakedService = new Client.Services.OrganizationService(new Client.CrmConnection()); // fakedContext.GetOrganizationService();

            DataBuilder DataBuilder = new DataBuilder(fakedService);

            var ex = Assert.ThrowsException <Exception>(() => DataBuilder.AppendData(SupportMethods.GetCustomerTypeFetch()));
        }
예제 #6
0
        public void Should_Override_Execution_Mock()
        {
            var context = new XrmFakedContext();
            var service = context.GetFakedOrganizationService();

            var e = new Entity("Contact") { Id = Guid.NewGuid() };
            context.Initialize(new[] { e });
            context.AddExecutionMock<RetrieveEntityRequest>(RetrieveEntityMock);
            context.AddExecutionMock<RetrieveEntityRequest>(AnotherRetrieveEntityMock);

            var inputs = new ParameterCollection
            {
                {"Target", e }
            };

            context.ExecutePluginWith<CustomMockPlugin>(inputs, new ParameterCollection(), new EntityImageCollection(), new EntityImageCollection());

            Assert.Equal("Another", (string)e["response"]);
            Assert.DoesNotThrow(() => context.RemoveExecutionMock<RetrieveEntityRequest>());
        }
        public void NoM2MData_ReturnsValidSchemaXML()
        {
            var fakedContext = new XrmFakedContext();

            fakedContext.InitializeMetadata(typeof(CrmEarlyBound.CrmServiceContext).Assembly);

            fakedContext.Initialize(SupportMethods.Getm2mRelationshipTypeEntities());

            fakedContext.AddRelationship("systemuserroles_association", new XrmFakedRelationship
            {
                IntersectEntity    = "systemuserroles",
                Entity1LogicalName = "systemuser",
                Entity1Attribute   = "systemuserid",
                Entity2LogicalName = "role",
                Entity2Attribute   = "roleid"
            });

            var AssociateRequest = SupportMethods.Getm2mRelationshipTypeAssociateRequest();
            IOrganizationService fakedService = fakedContext.GetOrganizationService();

            fakedService.Execute(AssociateRequest);

            fakedContext.AddExecutionMock <RetrieveEntityRequest>(req =>
            {
                var entityMetadata = fakedContext.GetEntityMetadataByName(SupportMethods.UserLogicalName);

                entityMetadata.DisplayName = new Label(SupportMethods.UserDisplayName, 1033);
                entityMetadata.SetSealedPropertyValue("PrimaryNameAttribute", "fullname");
                entityMetadata.Attributes.First(a => a.LogicalName == "systemuserid").SetSealedPropertyValue("DisplayName", new Label("User", 1033));
                entityMetadata.ManyToManyRelationships.First(m => m.SchemaName == "systemuserroles_association").SetSealedPropertyValue("IntersectEntityName", "systemuserroles");
                entityMetadata.ManyToManyRelationships.First(m => m.SchemaName == "systemuserroles_association").SetSealedPropertyValue("Entity2LogicalName", "role");
                entityMetadata.ManyToManyRelationships.First(m => m.SchemaName == "systemuserroles_association").SetSealedPropertyValue("Entity2IntersectAttribute", "roleid");

                var response = new RetrieveEntityResponse()
                {
                    Results = new ParameterCollection
                    {
                        { "EntityMetadata", entityMetadata }
                    }
                };
                return(response);
            });

            DataBuilder DataBuilder = new DataBuilder(fakedService);

            DataBuilder.AppendData("<fetch><entity name='systemuser'><attribute name='systemuserid'/><link-entity name='systemuserroles' from='systemuserid' to='systemuserid' intersect='true'><link-entity name='role' from='roleid' to='roleid'/><attribute name='roleid'/></link-entity><filter><condition attribute='systemuserid' operator='eq' value='00e7b0b9-1ace-e711-a970-000d3a192315'/></filter></entity></fetch>");

            Assert.AreEqual(
                DataBuilder.BuildSchemaXML().InnerXml,
                "<entities />");
        }
        public void ReflexiveM2MRelationship_Schema()
        {
            XrmFakedContext fakedContext = SupportMethods.SetupPrimitiveFakedService(
                SupportMethods.AgentScriptActionLogicalName,
                SupportMethods.AgentScriptActionDisplayName,
                SupportMethods.Getm2mReflexiveRelationshipTypeEntities());

            fakedContext.AddRelationship("msdyusd_subactioncalls", new XrmFakedRelationship
            {
                IntersectEntity    = "msdyusd_subactioncalls",
                Entity1LogicalName = "msdyusd_agentscriptaction",
                Entity1Attribute   = "msdyusd_agentscriptactionidone",
                Entity2LogicalName = "msdyusd_agentscriptaction",
                Entity2Attribute   = "msdyusd_agentscriptactionidtwo"
            });

            fakedContext.AddExecutionMock <RetrieveEntityRequest>(req =>
            {
                var entityMetadata = fakedContext.GetEntityMetadataByName(SupportMethods.AgentScriptActionLogicalName);

                entityMetadata.DisplayName = new Label(SupportMethods.AgentScriptActionDisplayName, 1033);
                entityMetadata.SetSealedPropertyValue("PrimaryNameAttribute", "msdyusd_name");
                entityMetadata.Attributes.First(a => a.LogicalName == "msdyusd_agentscriptactionid").SetSealedPropertyValue("DisplayName", new Label("Agent Script Action", 1033));
                entityMetadata.ManyToManyRelationships.First(m => m.SchemaName == "msdyusd_subactioncalls").SetSealedPropertyValue("IntersectEntityName", "msdyusd_subactioncalls");
                entityMetadata.ManyToManyRelationships.First(m => m.SchemaName == "msdyusd_subactioncalls").SetSealedPropertyValue("Entity1LogicalName", "msdyusd_agentscriptaction");
                entityMetadata.ManyToManyRelationships.First(m => m.SchemaName == "msdyusd_subactioncalls").SetSealedPropertyValue("Entity2LogicalName", "msdyusd_agentscriptaction");
                entityMetadata.ManyToManyRelationships.First(m => m.SchemaName == "msdyusd_subactioncalls").SetSealedPropertyValue("Entity2IntersectAttribute", "msdyusd_agentscriptactionidtwo");

                var response = new RetrieveEntityResponse()
                {
                    Results = new ParameterCollection
                    {
                        { "EntityMetadata", entityMetadata }
                    }
                };
                return(response);
            });

            IOrganizationService fakedService = fakedContext.GetOrganizationService();

            SupportMethods.Getm2mReflexiveRelationshipTypeAssociateRequests().ToList <AssociateRequest>().ForEach(r => fakedService.Execute(r));


            DataBuilder DataBuilder = new DataBuilder(fakedService);

            DataBuilder.AppendData(SupportMethods.Getm2mReflexiveRelationshipTypeFetch());

            Assert.AreEqual(DataBuilder.BuildSchemaXML().InnerXml, SupportMethods.Getm2mReflexiveRelationshipTypeExpectedSchema());
        }
예제 #9
0
        private void SetupContext(XrmFakedContext context)
        {
            context.AddExecutionMock <RetrieveEntityRequest>(req =>
            {
                var entityMetadata = new EntityMetadata();

                var property = entityMetadata
                               .GetType()
                               .GetProperty("Attributes");

                var subjectLabel = new StringAttributeMetadata
                {
                    LogicalName = "subject",
                    DisplayName = new Label
                    {
                        UserLocalizedLabel = new LocalizedLabel
                        {
                            LanguageCode = 1033,
                            Label        = "Subject Label"
                        }
                    }
                };

                var descriptionLabel = new StringAttributeMetadata
                {
                    LogicalName = "description",
                    DisplayName = new Label
                    {
                        UserLocalizedLabel = new LocalizedLabel
                        {
                            LanguageCode = 1033,
                            Label        = "Description Label"
                        }
                    }
                };

                var attributes = new AttributeMetadata[] { subjectLabel, descriptionLabel };
                property.GetSetMethod(true).Invoke(entityMetadata, new object[] { attributes });

                return(new RetrieveEntityResponse
                {
                    Results = new ParameterCollection
                    {
                        { "EntityMetadata", entityMetadata }
                    }
                });
            });
        }
예제 #10
0
        public void PartyListType()
        {
            // PartyListType        customers                          msdyn_approval
            XrmFakedContext fakedContext = SupportMethods.SetupPrimitiveFakedService(
                SupportMethods.ApprovalLogicalName,
                SupportMethods.ApprovalDisplayName,
                SupportMethods.GetPartyListTypeEntity());

            fakedContext.AddExecutionMock <RetrieveEntityRequest>(req =>
            {
                var logicalName = ((RetrieveEntityRequest)req).LogicalName;
                var displayName = String.Empty;
                switch (logicalName)
                {
                case SupportMethods.ApprovalLogicalName:
                    displayName = SupportMethods.ApprovalDisplayName;
                    break;

                case SupportMethods.ActivityPartyLogicalName:
                    displayName = SupportMethods.ActivityPartyDisplayName;
                    break;

                default:
                    throw new NotImplementedException();
                }
                var entityMetadata = fakedContext.GetEntityMetadataByName(logicalName);

                entityMetadata.DisplayName = new Label(displayName, 1033);
                var response = new RetrieveEntityResponse()
                {
                    Results = new ParameterCollection
                    {
                        { "EntityMetadata", entityMetadata }
                    }
                };
                return(response);
            });

            IOrganizationService fakedService = fakedContext.GetOrganizationService();

            DataBuilder DataBuilder = new DataBuilder(fakedService);

            DataBuilder.AppendData(SupportMethods.GetPartyListTypeFetch());
            Assert.AreEqual(
                DataBuilder.BuildDataXML().InnerXml,
                SupportMethods.GetPartyListTypeExpectedData());
        }
        public void It_Should_Retrieve_Old_Values_From_Audit()
        {
            var context = new XrmFakedContext();
            var service = context.GetFakedOrganizationService();
            var tracing = context.GetFakeTracingService();

            var contact = new Entity
            {
                LogicalName = "contact",
                Id          = Guid.NewGuid(),
                Attributes  = new AttributeCollection
                {
                    { "name", "newName" }
                }
            };

            context.AddExecutionMock <RetrieveRecordChangeHistoryRequest>((OrganizationRequest req) =>
            {
                var auditDetail = new AttributeAuditDetail
                {
                    OldValue = new Entity
                    {
                        LogicalName = "contact",
                        Id          = Guid.NewGuid(),
                        ["name"]    = "oldName"
                    }
                };

                var collection = new AuditDetailCollection();
                collection.AuditDetails.Add(auditDetail);

                return(new RetrieveRecordChangeHistoryResponse
                {
                    Results = new ParameterCollection
                    {
                        { "AuditDetailCollection", collection }
                    }
                });
            });

            var formula = "RetrieveAudit (PrimaryRecord(), \"name\")";
            var result  = new XTLInterpreter(formula, contact, null, service, tracing).Produce();

            Assert.That(result, Is.EqualTo("oldName"));
        }
예제 #12
0
        public void PartyListType()
        {
            // PartyListType        customers                          msdyn_approval
            XrmFakedContext fakedContext = SupportMethods.SetupPrimitiveFakedService(
                SupportMethods.ApprovalLogicalName,
                SupportMethods.ApprovalDisplayName,
                SupportMethods.GetPartyListTypeEntity());

            fakedContext.AddExecutionMock <RetrieveEntityRequest>(req =>
            {
                var logicalName    = ((RetrieveEntityRequest)req).LogicalName;
                var entityMetadata = fakedContext.GetEntityMetadataByName(logicalName);

                entityMetadata.DisplayName = new Label("Approval", 1033);
                entityMetadata.SetSealedPropertyValue("PrimaryNameAttribute", "subject");

                if (entityMetadata.LogicalName == SupportMethods.ApprovalLogicalName)
                {
                    entityMetadata.Attributes.First(a => a.LogicalName == "customers").SetSealedPropertyValue("DisplayName", new Label("Customers", 1033));
                    entityMetadata.Attributes.First(a => a.LogicalName == "customers").SetSealedPropertyValue("AttributeType", Sdk.Metadata.AttributeTypeCode.PartyList);
                    entityMetadata.Attributes.First(a => a.LogicalName == "activityid").SetSealedPropertyValue("DisplayName", new Label("Approval", 1033));
                }

                var response = new RetrieveEntityResponse()
                {
                    Results = new ParameterCollection
                    {
                        { "EntityMetadata", entityMetadata }
                    }
                };
                return(response);
            });

            IOrganizationService fakedService = fakedContext.GetOrganizationService();

            DataBuilder DataBuilder = new DataBuilder(fakedService);

            DataBuilder.AppendData(SupportMethods.GetPartyListTypeFetch());
            Assert.AreEqual(
                DataBuilder.BuildSchemaXML().InnerXml,
                SupportMethods.GetPartyListTypeExpectedSchema());
        }
        public static XrmFakedContext SetupPrimitiveFakedService(string LogicalName, string DisplayName, Entity[] Entity)
        {
            var fakedContext = new XrmFakedContext();

            fakedContext.InitializeMetadata(typeof(CrmEarlyBound.CrmServiceContext).Assembly);
            fakedContext.Initialize(Entity);
            fakedContext.AddExecutionMock <RetrieveEntityRequest>(req =>
            {
                var entityMetadata         = fakedContext.GetEntityMetadataByName(LogicalName);
                entityMetadata.DisplayName = new Label(DisplayName, 1033);
                var response = new RetrieveEntityResponse()
                {
                    Results = new ParameterCollection
                    {
                        { "EntityMetadata", entityMetadata }
                    }
                };
                return(response);
            });
            return(fakedContext);
        }
예제 #14
0
        public void MultiValueIdentifierSchema()
        {
            var fakedContext = new XrmFakedContext();

            fakedContext.InitializeMetadata(typeof(CrmEarlyBound.CrmServiceContext).Assembly);
            fakedContext.Initialize(SupportMethods.GetMultiValueIdentifierEntity());
            fakedContext.AddExecutionMock <RetrieveEntityRequest>(req =>
            {
                var entityMetadata         = fakedContext.GetEntityMetadataByName(SupportMethods.ContactLogicalName);
                entityMetadata.DisplayName = new Label(SupportMethods.ContactDisplayName, 1033);
                entityMetadata.SetSealedPropertyValue("PrimaryNameAttribute", "fullname");

                entityMetadata.Attributes.First(a => a.LogicalName == "firstname").SetSealedPropertyValue("DisplayName", new Label("First Name", 1033));
                entityMetadata.Attributes.First(a => a.LogicalName == "fullname").SetSealedPropertyValue("DisplayName", new Label("Full Name", 1033));
                entityMetadata.Attributes.First(a => a.LogicalName == "lastname").SetSealedPropertyValue("DisplayName", new Label("Last Name", 1033));
                entityMetadata.Attributes.First(a => a.LogicalName == "birthdate").SetSealedPropertyValue("DisplayName", new Label("Birthday", 1033));
                entityMetadata.Attributes.First(a => a.LogicalName == "emailaddress1").SetSealedPropertyValue("DisplayName", new Label("Email", 1033));
                entityMetadata.Attributes.First(a => a.LogicalName == "contactid").SetSealedPropertyValue("DisplayName", new Label("Contact", 1033));

                var response = new RetrieveEntityResponse()
                {
                    Results = new ParameterCollection
                    {
                        { "EntityMetadata", entityMetadata }
                    }
                };
                return(response);
            });

            IOrganizationService fakedService = fakedContext.GetOrganizationService();

            DataBuilder DataBuilder = new DataBuilder(fakedService);

            DataBuilder.AppendData(SupportMethods.GetMultiValueIdentifierFetch());
            DataBuilder.SetIdentifier(SupportMethods.ContactLogicalName, new String[] { "firstname", "lastname", "birthdate" });
            Assert.AreEqual(
                DataBuilder.BuildSchemaXML().InnerXml,
                SupportMethods.GetMultiValueIdentifierEntityExpectedSchema());
        }
        public void UnsupportedTypeCode_SkipsField()
        {
            XrmFakedContext fakedContext = SupportMethods.SetupPrimitiveFakedService(
                SupportMethods.IncidentLogicalName,
                SupportMethods.IncidentDisplayName,
                SupportMethods.GetCustomerTypeEntity());

            fakedContext.AddExecutionMock <RetrieveEntityRequest>(req =>
            {
                var entityMetadata         = fakedContext.GetEntityMetadataByName(SupportMethods.IncidentLogicalName);
                entityMetadata.DisplayName = new Label(SupportMethods.IncidentDisplayName, 1033);
                entityMetadata.SetSealedPropertyValue("PrimaryNameAttribute", "title");

                entityMetadata.Attributes.First(a => a.LogicalName == "customerid").SetSealedPropertyValue("DisplayName", new Label("Customer", 1033));
                entityMetadata.Attributes.First(a => a.LogicalName == "customerid").SetSealedPropertyValue("AttributeType", Sdk.Metadata.AttributeTypeCode.CalendarRules);
                entityMetadata.Attributes.First(a => a.LogicalName == "customerid").SetSealedPropertyValue("Targets", new String[] { "account", "contact" });
                entityMetadata.Attributes.First(a => a.LogicalName == "incidentid").SetSealedPropertyValue("DisplayName", new Label("Case", 1033));

                var response = new RetrieveEntityResponse()
                {
                    Results = new ParameterCollection
                    {
                        { "EntityMetadata", entityMetadata }
                    }
                };
                return(response);
            });

            IOrganizationService fakedService = fakedContext.GetOrganizationService();

            DataBuilder DataBuilder = new DataBuilder(fakedService);

            DataBuilder.AppendData(SupportMethods.GetCustomerTypeFetch());

            var XML = DataBuilder.BuildDataXML();

            Assert.AreEqual(1, XML.SelectSingleNode("//records/record").ChildNodes.Count);
            Assert.AreEqual("incidentid", XML.SelectSingleNode("//records/record/field/@name").Value);
        }
예제 #16
0
        public void BooleanType()
        {
            XrmFakedContext fakedContext = SupportMethods.SetupPrimitiveFakedService(
                SupportMethods.ThemeLogicalName,
                SupportMethods.ThemeDisplayName,
                SupportMethods.GetBooleanTypeEntity());

            fakedContext.AddExecutionMock <RetrieveEntityRequest>(req =>
            {
                var entityMetadata         = fakedContext.GetEntityMetadataByName(SupportMethods.ThemeLogicalName);
                entityMetadata.DisplayName = new Label(SupportMethods.ThemeDisplayName, 1033);
                entityMetadata.SetSealedPropertyValue("PrimaryNameAttribute", "name");

                entityMetadata.Attributes.First(a => a.LogicalName == "isdefaulttheme").SetSealedPropertyValue("DisplayName", new Label("Default Theme", 1033));
                entityMetadata.Attributes.First(a => a.LogicalName == "themeid").SetSealedPropertyValue("DisplayName", new Label("Theme", 1033));

                var response = new RetrieveEntityResponse()
                {
                    Results = new ParameterCollection
                    {
                        { "EntityMetadata", entityMetadata }
                    }
                };
                return(response);
            });

            IOrganizationService fakedService = fakedContext.GetOrganizationService();

            DataBuilder DataBuilder = new DataBuilder(fakedService);

            DataBuilder.AppendData(SupportMethods.GetBooleanTypeFetch_TopIsOne());

            String DataBuilderXML = DataBuilder.BuildSchemaXML().InnerXml;
            String RealXml        = SupportMethods.GetBooleanTypeExpectedSchema();

            Assert.AreEqual(
                DataBuilder.BuildSchemaXML().InnerXml,
                SupportMethods.GetBooleanTypeExpectedSchema());
        }
예제 #17
0
        public void CustomerType()
        {
            // CustomerType         customerid                         incident
            XrmFakedContext fakedContext = SupportMethods.SetupPrimitiveFakedService(
                SupportMethods.IncidentLogicalName,
                SupportMethods.IncidentDisplayName,
                SupportMethods.GetCustomerTypeEntity());

            fakedContext.AddExecutionMock <RetrieveEntityRequest>(req =>
            {
                var entityMetadata         = fakedContext.GetEntityMetadataByName(SupportMethods.IncidentLogicalName);
                entityMetadata.DisplayName = new Label(SupportMethods.IncidentDisplayName, 1033);
                entityMetadata.SetSealedPropertyValue("PrimaryNameAttribute", "title");

                entityMetadata.Attributes.First(a => a.LogicalName == "customerid").SetSealedPropertyValue("DisplayName", new Label("Customer", 1033));
                entityMetadata.Attributes.First(a => a.LogicalName == "customerid").SetSealedPropertyValue("AttributeType", Sdk.Metadata.AttributeTypeCode.Customer);
                entityMetadata.Attributes.First(a => a.LogicalName == "customerid").SetSealedPropertyValue("Targets", new String[] { "account", "contact" });
                entityMetadata.Attributes.First(a => a.LogicalName == "incidentid").SetSealedPropertyValue("DisplayName", new Label("Case", 1033));

                var response = new RetrieveEntityResponse()
                {
                    Results = new ParameterCollection
                    {
                        { "EntityMetadata", entityMetadata }
                    }
                };
                return(response);
            });

            IOrganizationService fakedService = fakedContext.GetOrganizationService();

            DataBuilder DataBuilder = new DataBuilder(fakedService);

            DataBuilder.AppendData(SupportMethods.GetCustomerTypeFetch());
            Assert.AreEqual(
                DataBuilder.BuildSchemaXML().InnerXml,
                SupportMethods.GetCustomerTypeExpectedSchema());
        }
        public void InvalidAttributeTypeCode_Throws()
        {
            XrmFakedContext fakedContext = SupportMethods.SetupPrimitiveFakedService(
                SupportMethods.IncidentLogicalName,
                SupportMethods.IncidentDisplayName,
                SupportMethods.GetCustomerTypeEntity());

            fakedContext.AddExecutionMock <RetrieveEntityRequest>(req =>
            {
                var entityMetadata         = fakedContext.GetEntityMetadataByName(SupportMethods.IncidentLogicalName);
                entityMetadata.DisplayName = new Label(SupportMethods.IncidentDisplayName, 1033);
                entityMetadata.SetSealedPropertyValue("PrimaryNameAttribute", "title");

                entityMetadata.Attributes.First(a => a.LogicalName == "customerid").SetSealedPropertyValue("DisplayName", new Label("Customer", 1033));
                entityMetadata.Attributes.First(a => a.LogicalName == "customerid").SetSealedPropertyValue("AttributeType", (Sdk.Metadata.AttributeTypeCode) 21);
                entityMetadata.Attributes.First(a => a.LogicalName == "customerid").SetSealedPropertyValue("Targets", new String[] { "account", "contact" });
                entityMetadata.Attributes.First(a => a.LogicalName == "incidentid").SetSealedPropertyValue("DisplayName", new Label("Case", 1033));

                var response = new RetrieveEntityResponse()
                {
                    Results = new ParameterCollection
                    {
                        { "EntityMetadata", entityMetadata }
                    }
                };
                return(response);
            });

            IOrganizationService fakedService = fakedContext.GetOrganizationService();

            DataBuilder DataBuilder = new DataBuilder(fakedService);

            DataBuilder.AppendData(SupportMethods.GetCustomerTypeFetch());

            var ex = Assert.ThrowsException <Exception>(() => DataBuilder.BuildSchemaXML());

            Assert.AreEqual(ex.Message, "GetFieldNodeType: Unknown Field Node Type - incident:customerid - LookupType:21");
        }
예제 #19
0
        public void Should_Execute_Mock_For_OrganizationRequests()
        {
            var context = new XrmFakedContext();
            var service = context.GetFakedOrganizationService();

            var e = new Entity("Contact")
            {
                Id = Guid.NewGuid()
            };

            context.Initialize(new[] { e });
            context.AddExecutionMock <RetrieveEntityRequest>(RetrieveEntityMock);

            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.RemoveExecutionMock <RetrieveEntityRequest>());
        }
예제 #20
0
        public void UniqueidentifierType()
        {
            // UniqueidentifierType stageid                            knowledgearticle
            XrmFakedContext fakedContext = SupportMethods.SetupPrimitiveFakedService(
                SupportMethods.KnowledgeArticleLogicalName,
                SupportMethods.KnowledgeArticleDisplayName,
                SupportMethods.GetUniqueIdentifierTypeEntity());

            fakedContext.AddExecutionMock <RetrieveEntityRequest>(req =>
            {
                var entityMetadata         = fakedContext.GetEntityMetadataByName(SupportMethods.KnowledgeArticleLogicalName);
                entityMetadata.DisplayName = new Label(SupportMethods.KnowledgeArticleDisplayName, 1033);
                entityMetadata.SetSealedPropertyValue("PrimaryNameAttribute", "title");

                entityMetadata.Attributes.First(a => a.LogicalName == "stageid").SetSealedPropertyValue("DisplayName", new Label("Stage Id", 1033));
                entityMetadata.Attributes.First(a => a.LogicalName == "stageid").SetSealedPropertyValue("AttributeType", Sdk.Metadata.AttributeTypeCode.Uniqueidentifier);
                entityMetadata.Attributes.First(a => a.LogicalName == "knowledgearticleid").SetSealedPropertyValue("DisplayName", new Label("Knowledge Article", 1033));

                var response = new RetrieveEntityResponse()
                {
                    Results = new ParameterCollection
                    {
                        { "EntityMetadata", entityMetadata }
                    }
                };
                return(response);
            });

            IOrganizationService fakedService = fakedContext.GetOrganizationService();

            DataBuilder DataBuilder = new DataBuilder(fakedService);

            DataBuilder.AppendData(SupportMethods.GetUniqueIdentifierTypeFetch());
            Assert.AreEqual(
                DataBuilder.BuildSchemaXML().InnerXml,
                SupportMethods.GetUniqueIdentifierTypeExpectedSchema());
        }
예제 #21
0
        public void DoubleType()
        {
            // DoubleType           msdyn_quantity                     msdyn_purchaseorderproduct
            XrmFakedContext fakedContext = SupportMethods.SetupPrimitiveFakedService(
                SupportMethods.PurchaseOrderProductLogicalName,
                SupportMethods.PurchaseOrderProductDisplayName,
                SupportMethods.GetDoubleTypeEntity());

            fakedContext.AddExecutionMock <RetrieveEntityRequest>(req =>
            {
                var entityMetadata         = fakedContext.GetEntityMetadataByName(SupportMethods.PurchaseOrderProductLogicalName);
                entityMetadata.DisplayName = new Label(SupportMethods.PurchaseOrderProductDisplayName, 1033);
                entityMetadata.SetSealedPropertyValue("PrimaryNameAttribute", "msdyn_name");

                entityMetadata.Attributes.First(a => a.LogicalName == "msdyn_quantity").SetSealedPropertyValue("DisplayName", new Label("Quantity", 1033));
                entityMetadata.Attributes.First(a => a.LogicalName == "msdyn_quantity").SetSealedPropertyValue("IsCustomAttribute", true);
                entityMetadata.Attributes.First(a => a.LogicalName == "msdyn_purchaseorderproductid").SetSealedPropertyValue("DisplayName", new Label("Purchase Order Product", 1033));

                var response = new RetrieveEntityResponse()
                {
                    Results = new ParameterCollection
                    {
                        { "EntityMetadata", entityMetadata }
                    }
                };
                return(response);
            });

            IOrganizationService fakedService = fakedContext.GetOrganizationService();

            DataBuilder DataBuilder = new DataBuilder(fakedService);

            DataBuilder.AppendData(SupportMethods.GetDoubleTypeFetch());
            Assert.AreEqual(
                DataBuilder.BuildSchemaXML().InnerXml,
                SupportMethods.GetDoubleTypeExpectedSchema());
        }
예제 #22
0
        public void MoneyType()
        {
            // MoneyType            totaltax                           invoice
            XrmFakedContext fakedContext = SupportMethods.SetupPrimitiveFakedService(
                SupportMethods.InvoiceLogicalName,
                SupportMethods.InvoiceDisplayName,
                SupportMethods.GetMoneyTypeEntity());

            fakedContext.AddExecutionMock <RetrieveEntityRequest>(req =>
            {
                var entityMetadata         = fakedContext.GetEntityMetadataByName(SupportMethods.InvoiceLogicalName);
                entityMetadata.DisplayName = new Label(SupportMethods.InvoiceDisplayName, 1033);
                entityMetadata.SetSealedPropertyValue("PrimaryNameAttribute", "name");

                entityMetadata.Attributes.First(a => a.LogicalName == "totaltax").SetSealedPropertyValue("DisplayName", new Label("Total Tax", 1033));
                entityMetadata.Attributes.First(a => a.LogicalName == "invoiceid").SetSealedPropertyValue("DisplayName", new Label("Invoice", 1033));

                var response = new RetrieveEntityResponse()
                {
                    Results = new ParameterCollection
                    {
                        { "EntityMetadata", entityMetadata }
                    }
                };
                return(response);
            });

            IOrganizationService fakedService = fakedContext.GetOrganizationService();

            DataBuilder DataBuilder = new DataBuilder(fakedService);

            DataBuilder.AppendData(SupportMethods.GetMoneyTypeFetch());
            Assert.AreEqual(
                DataBuilder.BuildSchemaXML().InnerXml,
                SupportMethods.GetMoneyTypeExpectedSchema());
        }
예제 #23
0
        public void SingleEntity_AllPluginsDisabled()
        {
            var fakedContext = new XrmFakedContext();

            fakedContext.InitializeMetadata(typeof(CrmEarlyBound.CrmServiceContext).Assembly);
            fakedContext.Initialize(SupportMethods.GetSingleEntity_AllPluginsDisabledEntity());
            fakedContext.AddExecutionMock <RetrieveEntityRequest>(req =>
            {
                var entityMetadata         = fakedContext.GetEntityMetadataByName(SupportMethods.AccountLogicalName);
                entityMetadata.DisplayName = new Label(SupportMethods.AccountDisplayName, 1033);
                entityMetadata.SetSealedPropertyValue("PrimaryNameAttribute", "name");

                entityMetadata.Attributes.First(a => a.LogicalName == "name").SetSealedPropertyValue("DisplayName", new Label("Account Name", 1033));
                entityMetadata.Attributes.First(a => a.LogicalName == "accountid").SetSealedPropertyValue("DisplayName", new Label("Account", 1033));
                entityMetadata.Attributes.First(a => a.LogicalName == "accountid").SetSealedPropertyValue("AttributeType", AttributeTypeCode.Uniqueidentifier);

                var response = new RetrieveEntityResponse()
                {
                    Results = new ParameterCollection
                    {
                        { "EntityMetadata", entityMetadata }
                    }
                };
                return(response);
            });

            IOrganizationService fakedService = fakedContext.GetOrganizationService();

            DataBuilder DataBuilder = new DataBuilder(fakedService);

            DataBuilder.SetPluginsDisabled(true);
            DataBuilder.AppendData(SupportMethods.GetSingleEntity_AllPluginsDisabledFetch());
            Assert.AreEqual(
                DataBuilder.BuildSchemaXML().InnerXml,
                SupportMethods.GetSingleEntity_AllPluginsDisabledEntityExpectedSchema());
        }
        public void InternalLookup_Data()
        {
            // Verify that a lookup to a schema already existing DOES add a record
            var fakedContext = new XrmFakedContext();

            fakedContext.InitializeMetadata(typeof(CrmEarlyBound.CrmServiceContext).Assembly);

            Guid   targetGuid = Guid.NewGuid();
            Entity AccountWithExternalLookup = new Entity("account", Guid.NewGuid());

            AccountWithExternalLookup["createdby"] = new EntityReference("systemuser", targetGuid);

            Entity SystemUser = new Entity("systemuser", Guid.NewGuid());

            SystemUser["firstname"] = "Andrew";
            SystemUser["lastname"]  = "Vogel";

            fakedContext.Initialize(new List <Entity>()
            {
                AccountWithExternalLookup, SystemUser
            });
            fakedContext.AddExecutionMock <RetrieveEntityRequest>(req =>
            {
                var logicalName    = ((RetrieveEntityRequest)req).LogicalName;
                var entityMetadata = fakedContext.GetEntityMetadataByName(logicalName);

                switch (entityMetadata.LogicalName)
                {
                case SupportMethods.AccountLogicalName:
                    entityMetadata.DisplayName = new Label(SupportMethods.AccountDisplayName, 1033);
                    entityMetadata.Attributes.First(a => a.LogicalName == "createdby").SetSealedPropertyValue("DisplayName", new Label("Created By", 1033));
                    entityMetadata.Attributes.First(a => a.LogicalName == "createdby").SetSealedPropertyValue("Targets", new String[] { "contact" });
                    entityMetadata.Attributes.First(a => a.LogicalName == "accountid").SetSealedPropertyValue("DisplayName", new Label("Account", 1033));
                    break;

                case SupportMethods.UserLogicalName:
                    entityMetadata.DisplayName = new Label(SupportMethods.UserDisplayName, 1033);
                    entityMetadata.Attributes.First(a => a.LogicalName == "firstname").SetSealedPropertyValue("DisplayName", new Label("First Name", 1033));
                    entityMetadata.Attributes.First(a => a.LogicalName == "lastname").SetSealedPropertyValue("DisplayName", new Label("Last Name", 1033));
                    entityMetadata.Attributes.First(a => a.LogicalName == "systemuserid").SetSealedPropertyValue("DisplayName", new Label("User", 1033));
                    break;

                default:
                    break;
                }

                var response = new RetrieveEntityResponse()
                {
                    Results = new ParameterCollection
                    {
                        { "EntityMetadata", entityMetadata }
                    }
                };
                return(response);
            });

            IOrganizationService fakedService = fakedContext.GetOrganizationService();

            DataBuilder DataBuilder = new DataBuilder(fakedService);

            DataBuilder.AppendData("<fetch><entity name='account'><attribute name='accountid'/><attribute name='createdby'/></entity></fetch>");
            DataBuilder.AppendData("<fetch><entity name='systemuser'><attribute name='systemuserid'/><attribute name='firstname'/><attribute name='lastname'/></entity></fetch>");

            Assert.IsFalse(DataBuilder.BuildDataXML().SelectSingleNode("entities/entity[@name='systemuser']/records/record[@id='" + targetGuid + "']") == null);
        }
예제 #25
0
        public void AllEntities_SomePluginsDisabled_MixedIdentifiers()
        {
            var fakedContext = new XrmFakedContext();

            fakedContext.InitializeMetadata(typeof(CrmEarlyBound.CrmServiceContext).Assembly);
            fakedContext.Initialize(SupportMethods.GetAllEntities_SomePluginsDisabled_MixedIdentifiersEntity());
            fakedContext.AddExecutionMock <RetrieveEntityRequest>(req =>
            {
                var logicalName    = ((RetrieveEntityRequest)req).LogicalName;
                var entityMetadata = fakedContext.GetEntityMetadataByName(logicalName);

                switch (entityMetadata.LogicalName)
                {
                case SupportMethods.ApprovalLogicalName:
                    entityMetadata.DisplayName = new Label(SupportMethods.ApprovalDisplayName, 1033);
                    entityMetadata.SetSealedPropertyValue("PrimaryNameAttribute", "subject");
                    entityMetadata.Attributes.First(a => a.LogicalName == "activityid").SetSealedPropertyValue("DisplayName", new Label("Activity", 1033));
                    entityMetadata.Attributes.First(a => a.LogicalName == "customers").SetSealedPropertyValue("DisplayName", new Label("Customers", 1033));
                    entityMetadata.Attributes.First(a => a.LogicalName == "customers").SetSealedPropertyValue("AttributeType", Sdk.Metadata.AttributeTypeCode.PartyList);
                    break;

                case SupportMethods.IncidentLogicalName:
                    entityMetadata.DisplayName = new Label(SupportMethods.IncidentDisplayName, 1033);
                    entityMetadata.SetSealedPropertyValue("PrimaryNameAttribute", "title");
                    entityMetadata.Attributes.First(a => a.LogicalName == "incidentid").SetSealedPropertyValue("DisplayName", new Label("Case", 1033));
                    entityMetadata.Attributes.First(a => a.LogicalName == "customerid").SetSealedPropertyValue("DisplayName", new Label("Customer", 1033));
                    entityMetadata.Attributes.First(a => a.LogicalName == "customerid").SetSealedPropertyValue("AttributeType", Sdk.Metadata.AttributeTypeCode.Customer);
                    entityMetadata.Attributes.First(a => a.LogicalName == "customerid").SetSealedPropertyValue("Targets", new String[] { "account", "contact" });
                    break;

                case SupportMethods.InvoiceLogicalName:
                    entityMetadata.DisplayName = new Label(SupportMethods.InvoiceDisplayName, 1033);
                    entityMetadata.SetSealedPropertyValue("PrimaryNameAttribute", "name");
                    entityMetadata.Attributes.First(a => a.LogicalName == "invoiceid").SetSealedPropertyValue("DisplayName", new Label("Invoice", 1033));
                    entityMetadata.Attributes.First(a => a.LogicalName == "totaltax").SetSealedPropertyValue("DisplayName", new Label("Total Tax", 1033));
                    break;

                case SupportMethods.KnowledgeArticleLogicalName:
                    entityMetadata.DisplayName = new Label(SupportMethods.KnowledgeArticleDisplayName, 1033);
                    entityMetadata.SetSealedPropertyValue("PrimaryNameAttribute", "title");
                    entityMetadata.Attributes.First(a => a.LogicalName == "keywords").SetSealedPropertyValue("DisplayName", new Label("Keywords", 1033));
                    entityMetadata.Attributes.First(a => a.LogicalName == "keywords").SetSealedPropertyValue("AttributeType", Sdk.Metadata.AttributeTypeCode.Memo);
                    entityMetadata.Attributes.First(a => a.LogicalName == "knowledgearticleid").SetSealedPropertyValue("DisplayName", new Label("Knowledge Article", 1033));
                    entityMetadata.Attributes.First(a => a.LogicalName == "publishon").SetSealedPropertyValue("DisplayName", new Label("Publish On", 1033));
                    entityMetadata.Attributes.First(a => a.LogicalName == "expirationstateid").SetSealedPropertyValue("DisplayName", new Label("Expiration State Id", 1033));
                    entityMetadata.Attributes.First(a => a.LogicalName == "previousarticlecontentid").SetSealedPropertyValue("DisplayName", new Label("Previous Article Content ID", 1033));
                    entityMetadata.Attributes.First(a => a.LogicalName == "previousarticlecontentid").SetSealedPropertyValue("Targets", new String[] { "knowledgearticle" });
                    entityMetadata.Attributes.First(a => a.LogicalName == "ownerid").SetSealedPropertyValue("DisplayName", new Label("Owner", 1033));
                    entityMetadata.Attributes.First(a => a.LogicalName == "ownerid").SetSealedPropertyValue("AttributeType", Sdk.Metadata.AttributeTypeCode.Owner);
                    entityMetadata.Attributes.First(a => a.LogicalName == "expiredreviewoptions").SetSealedPropertyValue("DisplayName", new Label("Expired Review Options", 1033));
                    entityMetadata.Attributes.First(a => a.LogicalName == "statecode").SetSealedPropertyValue("DisplayName", new Label("Status", 1033));
                    entityMetadata.Attributes.First(a => a.LogicalName == "statuscode").SetSealedPropertyValue("DisplayName", new Label("Status Reason", 1033));
                    entityMetadata.Attributes.First(a => a.LogicalName == "stageid").SetSealedPropertyValue("DisplayName", new Label("Stage Id", 1033));
                    entityMetadata.Attributes.First(a => a.LogicalName == "stageid").SetSealedPropertyValue("AttributeType", Sdk.Metadata.AttributeTypeCode.Uniqueidentifier);
                    entityMetadata.Attributes.First(a => a.LogicalName == "description").SetSealedPropertyValue("DisplayName", new Label("Short Description", 1033));
                    entityMetadata.Attributes.First(a => a.LogicalName == "articlepublicnumber").SetSealedPropertyValue("DisplayName", new Label("Article Public Number", 1033));
                    break;

                case SupportMethods.PurchaseOrderProductLogicalName:
                    entityMetadata.DisplayName = new Label(SupportMethods.PurchaseOrderProductDisplayName, 1033);
                    entityMetadata.SetSealedPropertyValue("PrimaryNameAttribute", "msdyn_name");
                    entityMetadata.Attributes.First(a => a.LogicalName == "msdyn_quantity").SetSealedPropertyValue("DisplayName", new Label("Quantity", 1033));
                    entityMetadata.Attributes.First(a => a.LogicalName == "msdyn_quantity").SetSealedPropertyValue("IsCustomAttribute", true);
                    entityMetadata.Attributes.First(a => a.LogicalName == "msdyn_purchaseorderproductid").SetSealedPropertyValue("DisplayName", new Label("Purchase Order Product", 1033));
                    break;

                case SupportMethods.ResourceRequirementDetailLogicalName:
                    entityMetadata.DisplayName = new Label(SupportMethods.ResourceRequirementDetailDisplayName, 1033);
                    entityMetadata.SetSealedPropertyValue("PrimaryNameAttribute", "msdyn_name");
                    entityMetadata.Attributes.First(a => a.LogicalName == "msdyn_hours").SetSealedPropertyValue("DisplayName", new Label("Hours", 1033));
                    entityMetadata.Attributes.First(a => a.LogicalName == "msdyn_hours").SetSealedPropertyValue("IsCustomAttribute", true);
                    entityMetadata.Attributes.First(a => a.LogicalName == "msdyn_resourcerequirementdetailid").SetSealedPropertyValue("DisplayName", new Label("Resource Requirement Detail", 1033));
                    break;

                case SupportMethods.ThemeLogicalName:
                    entityMetadata.DisplayName = new Label(SupportMethods.ThemeDisplayName, 1033);
                    entityMetadata.SetSealedPropertyValue("PrimaryNameAttribute", "name");
                    entityMetadata.Attributes.First(a => a.LogicalName == "themeid").SetSealedPropertyValue("DisplayName", new Label("Theme", 1033));
                    entityMetadata.Attributes.First(a => a.LogicalName == "isdefaulttheme").SetSealedPropertyValue("DisplayName", new Label("Default Theme", 1033));
                    break;

                default:
                    break;
                }

                var response = new RetrieveEntityResponse()
                {
                    Results = new ParameterCollection
                    {
                        { "EntityMetadata", entityMetadata }
                    }
                };
                return(response);
            });

            IOrganizationService fakedService = fakedContext.GetOrganizationService();

            DataBuilder DataBuilder = new DataBuilder(fakedService);

            DataBuilder.AppendData(SupportMethods.GetAllEntities_SomePluginsDisabled_MixedIdentifiersThemeFetch());
            DataBuilder.AppendData(SupportMethods.GetAllEntities_SomePluginsDisabled_MixedIdentifiersIncidentFetch());
            DataBuilder.SetPluginsDisabled("incident", true);
            DataBuilder.AppendData(SupportMethods.GetAllEntities_SomePluginsDisabled_MixedIdentifiersKnowledgeArticleFetch());
            DataBuilder.SetIdentifier(SupportMethods.KnowledgeArticleLogicalName, "articlepublicnumber");
            DataBuilder.SetPluginsDisabled("knowledgearticle", true);
            DataBuilder.AppendData(SupportMethods.GetAllEntities_SomePluginsDisabled_MixedIdentifiersResourceRequirementDetailFetch());
            DataBuilder.AppendData(SupportMethods.GetAllEntities_SomePluginsDisabled_MixedIdentifiersPurchaseOrderProductFetch());
            DataBuilder.AppendData(SupportMethods.GetAllEntities_SomePluginsDisabled_MixedIdentifiersInvoiceFetch());
            DataBuilder.AppendData(SupportMethods.GetAllEntities_SomePluginsDisabled_MixedIdentifiersApprovalFetch());
            Assert.AreEqual(
                DataBuilder.BuildSchemaXML().InnerXml,
                SupportMethods.GetAllEntities_SomePluginsDisabled_MixedIdentifiersExpectedSchema());
        }
예제 #26
0
        public void MultipleSourcesOfMetadata_DataImported()
        {
            var fakedContext = new XrmFakedContext();

            fakedContext.InitializeMetadata(typeof(CrmEarlyBound.CrmServiceContext).Assembly);

            Guid   targetGuid = Guid.Parse("f0205357-124a-4b5a-9163-5cca2b3d3e8d");
            Entity AccountWithExternalLookup = new Entity("account", Guid.Parse("832193cb-f381-47c0-b059-662bdfcf1261"));

            AccountWithExternalLookup["createdby"] = new EntityReference("systemuser", targetGuid);

            Entity SystemUser = new Entity("systemuser", Guid.Parse("16b8a7ea-7d3f-4856-85a1-59f98ffcfafe"));

            SystemUser["firstname"] = "Andrew";
            SystemUser["lastname"]  = "Vogel";

            fakedContext.Initialize(new List <Entity>()
            {
                AccountWithExternalLookup, SystemUser
            });
            fakedContext.AddExecutionMock <RetrieveEntityRequest>(req =>
            {
                var logicalName    = ((RetrieveEntityRequest)req).LogicalName;
                var entityMetadata = fakedContext.GetEntityMetadataByName(logicalName);

                switch (entityMetadata.LogicalName)
                {
                case SupportMethods.AccountLogicalName:
                    entityMetadata.DisplayName = new Label(SupportMethods.AccountDisplayName, 1033);
                    entityMetadata.Attributes.First(a => a.LogicalName == "createdby").SetSealedPropertyValue("DisplayName", new Label("Created By", 1033));
                    entityMetadata.Attributes.First(a => a.LogicalName == "createdby").SetSealedPropertyValue("Targets", new String[] { "contact" });
                    entityMetadata.Attributes.First(a => a.LogicalName == "accountid").SetSealedPropertyValue("DisplayName", new Label("Account", 1033));
                    break;

                case SupportMethods.UserLogicalName:
                    entityMetadata.DisplayName = new Label(SupportMethods.UserDisplayName, 1033);
                    entityMetadata.Attributes.First(a => a.LogicalName == "firstname").SetSealedPropertyValue("DisplayName", new Label("First Name", 1033));
                    entityMetadata.Attributes.First(a => a.LogicalName == "lastname").SetSealedPropertyValue("DisplayName", new Label("Last Name", 1033));
                    entityMetadata.Attributes.First(a => a.LogicalName == "systemuserid").SetSealedPropertyValue("DisplayName", new Label("User", 1033));
                    entityMetadata.ManyToManyRelationships.First(m => m.SchemaName == "systemuserroles_association").SetSealedPropertyValue("IntersectEntityName", "systemuserroles");
                    entityMetadata.ManyToManyRelationships.First(m => m.SchemaName == "systemuserroles_association").SetSealedPropertyValue("Entity2LogicalName", "role");
                    entityMetadata.ManyToManyRelationships.First(m => m.SchemaName == "systemuserroles_association").SetSealedPropertyValue("Entity2IntersectAttribute", "roleid");
                    break;

                case SupportMethods.ThemeLogicalName:
                    entityMetadata.DisplayName = new Label(SupportMethods.ThemeDisplayName, 1033);
                    break;

                case SupportMethods.IncidentLogicalName:
                    entityMetadata.DisplayName = new Label(SupportMethods.IncidentDisplayName, 1033);
                    break;

                case SupportMethods.ResourceRequirementDetailLogicalName:
                    entityMetadata.DisplayName = new Label(SupportMethods.ResourceRequirementDetailDisplayName, 1033);
                    break;

                case SupportMethods.PurchaseOrderProductLogicalName:
                    entityMetadata.DisplayName = new Label(SupportMethods.PurchaseOrderProductDisplayName, 1033);
                    break;

                case SupportMethods.InvoiceLogicalName:
                    entityMetadata.DisplayName = new Label(SupportMethods.InvoiceDisplayName, 1033);
                    break;

                case SupportMethods.ApprovalLogicalName:
                    entityMetadata.DisplayName = new Label(SupportMethods.ApprovalDisplayName, 1033);
                    break;

                case SupportMethods.SecurityRoleLogicalName:
                    entityMetadata.DisplayName = new Label(SupportMethods.SecurityRoleDisplayName, 1033);
                    break;

                default:
                    break;
                }

                var response = new RetrieveEntityResponse()
                {
                    Results = new ParameterCollection
                    {
                        { "EntityMetadata", entityMetadata }
                    }
                };
                return(response);
            });

            IOrganizationService fakedService = fakedContext.GetOrganizationService();

            DataBuilder db = new DataBuilder(fakedService);

            db.AppendData("<fetch><entity name='account'><attribute name='accountid'/><attribute name='createdby'/></entity></fetch>");

            db.AppendData(SupportMethods.GetBooleanTypeExpectedData(), SupportMethods.GetBooleanTypeExpectedSchema());
            db.AppendData(SupportMethods.GetCustomerTypeExpectedData(), SupportMethods.GetCustomerTypeExpectedSchema());
            db.AppendData(SupportMethods.GetDateTimeTypeExpectedData(), SupportMethods.GetDateTimeTypeExpectedSchema());
            db.AppendData(SupportMethods.GetDecimalTypeExpectedData(), SupportMethods.GetDecimalTypeExpectedSchema());
            db.AppendData(SupportMethods.GetDoubleTypeExpectedData(), SupportMethods.GetDoubleTypeExpectedSchema());
            db.AppendData(SupportMethods.GetIntegerTypeExpectedData(), SupportMethods.GetIntegerTypeExpectedSchema());
            db.AppendData(SupportMethods.GetLookupTypeExpectedData(), SupportMethods.GetLookupTypeExpectedSchema());
            db.AppendData(SupportMethods.GetMemoTypeExpectedData(), SupportMethods.GetMemoTypeExpectedSchema());
            db.AppendData(SupportMethods.GetMoneyTypeExpectedData(), SupportMethods.GetMoneyTypeExpectedSchema());
            db.AppendData(SupportMethods.GetOwnerTypeExpectedData(), SupportMethods.GetOwnerTypeExpectedSchema());
            db.AppendData(SupportMethods.GetPartyListTypeExpectedData(), SupportMethods.GetPartyListTypeExpectedSchema());
            db.AppendData(SupportMethods.GetPicklistTypeExpectedData(), SupportMethods.GetPicklistTypeExpectedSchema());
            db.AppendData(SupportMethods.GetStateTypeExpectedData(), SupportMethods.GetStateTypeExpectedSchema());
            db.AppendData(SupportMethods.GetStatusTypeExpectedData(), SupportMethods.GetStatusTypeExpectedSchema());
            db.AppendData(SupportMethods.GetStringTypeExpectedData(), SupportMethods.GetStringTypeExpectedSchema());
            db.AppendData(SupportMethods.GetUniqueIdentifierTypeExpectedData(), SupportMethods.GetUniqueIdentifierTypeExpectedSchema());
            db.AppendData(SupportMethods.Getm2mRelationshipTypeExpectedData(), SupportMethods.Getm2mRelationshipTypeExpectedSchema());

            db.AppendData("<fetch><entity name='systemuser'><attribute name='systemuserid'/><attribute name='firstname'/><attribute name='lastname'/></entity></fetch>");

            db.SetIdentifier("systemuser", "systemuserid");

            Assert.AreEqual(
                db.BuildDataXML().InnerXml,
                SupportMethods.LoadXmlFile("../../lib/Configurations/MultipleSourcesOfMetadata_data.xml"));
        }
예제 #27
0
        public void MultipleSourcesOfMetadata_SchemaImported()
        {
            var fakedContext = new XrmFakedContext();

            fakedContext.InitializeMetadata(typeof(CrmEarlyBound.CrmServiceContext).Assembly);

            Guid   targetGuid = Guid.Parse("f0205357-124a-4b5a-9163-5cca2b3d3e8d");
            Entity AccountWithExternalLookup = new Entity("account", Guid.Parse("832193cb-f381-47c0-b059-662bdfcf1261"));

            AccountWithExternalLookup["createdby"] = new EntityReference("systemuser", targetGuid);

            Entity SystemUser = new Entity("systemuser", Guid.Parse("16b8a7ea-7d3f-4856-85a1-59f98ffcfafe"));

            SystemUser["firstname"] = "Andrew";
            SystemUser["lastname"]  = "Vogel";

            fakedContext.Initialize(new List <Entity>()
            {
                AccountWithExternalLookup, SystemUser
            });
            fakedContext.AddExecutionMock <RetrieveEntityRequest>(req =>
            {
                var logicalName    = ((RetrieveEntityRequest)req).LogicalName;
                var entityMetadata = fakedContext.GetEntityMetadataByName(logicalName);

                switch (entityMetadata.LogicalName)
                {
                case SupportMethods.AccountLogicalName:
                    entityMetadata.DisplayName = new Label(SupportMethods.AccountDisplayName, 1033);
                    entityMetadata.Attributes.First(a => a.LogicalName == "createdby").SetSealedPropertyValue("DisplayName", new Label("Created By", 1033));
                    entityMetadata.Attributes.First(a => a.LogicalName == "createdby").SetSealedPropertyValue("Targets", new String[] { "contact" });
                    entityMetadata.Attributes.First(a => a.LogicalName == "accountid").SetSealedPropertyValue("DisplayName", new Label("Account", 1033));
                    break;

                case SupportMethods.UserLogicalName:
                    entityMetadata.DisplayName = new Label(SupportMethods.UserDisplayName, 1033);
                    entityMetadata.Attributes.First(a => a.LogicalName == "firstname").SetSealedPropertyValue("DisplayName", new Label("First Name", 1033));
                    entityMetadata.Attributes.First(a => a.LogicalName == "lastname").SetSealedPropertyValue("DisplayName", new Label("Last Name", 1033));
                    entityMetadata.Attributes.First(a => a.LogicalName == "systemuserid").SetSealedPropertyValue("DisplayName", new Label("User", 1033));
                    entityMetadata.ManyToManyRelationships.First(m => m.SchemaName == "systemuserroles_association").SetSealedPropertyValue("IntersectEntityName", "systemuserroles");
                    entityMetadata.ManyToManyRelationships.First(m => m.SchemaName == "systemuserroles_association").SetSealedPropertyValue("Entity2LogicalName", "role");
                    entityMetadata.ManyToManyRelationships.First(m => m.SchemaName == "systemuserroles_association").SetSealedPropertyValue("Entity2IntersectAttribute", "roleid");
                    break;

                case SupportMethods.ThemeLogicalName:
                    entityMetadata.DisplayName = new Label(SupportMethods.ThemeDisplayName, 1033);
                    entityMetadata.SetSealedPropertyValue("PrimaryNameAttribute", "name");
                    entityMetadata.Attributes.First(a => a.LogicalName == "themeid").SetSealedPropertyValue("DisplayName", new Label("Theme", 1033));
                    entityMetadata.Attributes.First(a => a.LogicalName == "isdefaulttheme").SetSealedPropertyValue("DisplayName", new Label("Default Theme", 1033));
                    break;

                case SupportMethods.IncidentLogicalName:
                    entityMetadata.DisplayName = new Label(SupportMethods.IncidentDisplayName, 1033);
                    entityMetadata.SetSealedPropertyValue("PrimaryNameAttribute", "title");
                    entityMetadata.Attributes.First(a => a.LogicalName == "incidentid").SetSealedPropertyValue("DisplayName", new Label("Case", 1033));
                    entityMetadata.Attributes.First(a => a.LogicalName == "customerid").SetSealedPropertyValue("DisplayName", new Label("Customer", 1033));
                    entityMetadata.Attributes.First(a => a.LogicalName == "customerid").SetSealedPropertyValue("AttributeType", Sdk.Metadata.AttributeTypeCode.Customer);
                    entityMetadata.Attributes.First(a => a.LogicalName == "customerid").SetSealedPropertyValue("Targets", new String[] { "account", "contact" });
                    break;

                case SupportMethods.ResourceRequirementDetailLogicalName:
                    entityMetadata.DisplayName = new Label(SupportMethods.ResourceRequirementDetailDisplayName, 1033);
                    entityMetadata.SetSealedPropertyValue("PrimaryNameAttribute", "msdyn_name");
                    entityMetadata.Attributes.First(a => a.LogicalName == "msdyn_hours").SetSealedPropertyValue("DisplayName", new Label("Hours", 1033));
                    entityMetadata.Attributes.First(a => a.LogicalName == "msdyn_hours").SetSealedPropertyValue("IsCustomAttribute", true);
                    entityMetadata.Attributes.First(a => a.LogicalName == "msdyn_resourcerequirementdetailid").SetSealedPropertyValue("DisplayName", new Label("Resource Requirement Detail", 1033));
                    break;

                case SupportMethods.PurchaseOrderProductLogicalName:
                    entityMetadata.DisplayName = new Label(SupportMethods.PurchaseOrderProductDisplayName, 1033);
                    entityMetadata.SetSealedPropertyValue("PrimaryNameAttribute", "msdyn_name");
                    entityMetadata.Attributes.First(a => a.LogicalName == "msdyn_quantity").SetSealedPropertyValue("DisplayName", new Label("Quantity", 1033));
                    entityMetadata.Attributes.First(a => a.LogicalName == "msdyn_quantity").SetSealedPropertyValue("IsCustomAttribute", true);
                    entityMetadata.Attributes.First(a => a.LogicalName == "msdyn_purchaseorderproductid").SetSealedPropertyValue("DisplayName", new Label("Purchase Order Product", 1033));
                    break;

                case SupportMethods.InvoiceLogicalName:
                    entityMetadata.DisplayName = new Label(SupportMethods.InvoiceDisplayName, 1033);
                    entityMetadata.SetSealedPropertyValue("PrimaryNameAttribute", "name");
                    entityMetadata.Attributes.First(a => a.LogicalName == "invoiceid").SetSealedPropertyValue("DisplayName", new Label("Invoice", 1033));
                    entityMetadata.Attributes.First(a => a.LogicalName == "totaltax").SetSealedPropertyValue("DisplayName", new Label("Total Tax", 1033));
                    break;

                case SupportMethods.ApprovalLogicalName:
                    entityMetadata.DisplayName = new Label(SupportMethods.ApprovalDisplayName, 1033);
                    entityMetadata.SetSealedPropertyValue("PrimaryNameAttribute", "subject");
                    entityMetadata.Attributes.First(a => a.LogicalName == "activityid").SetSealedPropertyValue("DisplayName", new Label("Activity", 1033));
                    entityMetadata.Attributes.First(a => a.LogicalName == "customers").SetSealedPropertyValue("DisplayName", new Label("Customers", 1033));
                    entityMetadata.Attributes.First(a => a.LogicalName == "customers").SetSealedPropertyValue("AttributeType", Sdk.Metadata.AttributeTypeCode.PartyList);
                    break;

                case SupportMethods.SecurityRoleLogicalName:
                    entityMetadata.DisplayName = new Label(SupportMethods.SecurityRoleDisplayName, 1033);
                    entityMetadata.Attributes.First(a => a.LogicalName == "roleid").SetSealedPropertyValue("DisplayName", new Label("Role", 1033));
                    break;

                case SupportMethods.KnowledgeArticleLogicalName:
                    entityMetadata.DisplayName = new Label(SupportMethods.KnowledgeArticleDisplayName, 1033);
                    entityMetadata.SetSealedPropertyValue("PrimaryNameAttribute", "title");
                    entityMetadata.Attributes.First(a => a.LogicalName == "keywords").SetSealedPropertyValue("DisplayName", new Label("Keywords", 1033));
                    entityMetadata.Attributes.First(a => a.LogicalName == "keywords").SetSealedPropertyValue("AttributeType", Sdk.Metadata.AttributeTypeCode.Memo);
                    entityMetadata.Attributes.First(a => a.LogicalName == "knowledgearticleid").SetSealedPropertyValue("DisplayName", new Label("Knowledge Article", 1033));
                    entityMetadata.Attributes.First(a => a.LogicalName == "publishon").SetSealedPropertyValue("DisplayName", new Label("Publish On", 1033));
                    entityMetadata.Attributes.First(a => a.LogicalName == "expirationstateid").SetSealedPropertyValue("DisplayName", new Label("Expiration State Id", 1033));
                    entityMetadata.Attributes.First(a => a.LogicalName == "previousarticlecontentid").SetSealedPropertyValue("DisplayName", new Label("Previous Article Content ID", 1033));
                    entityMetadata.Attributes.First(a => a.LogicalName == "previousarticlecontentid").SetSealedPropertyValue("Targets", new String[] { "knowledgearticle" });
                    entityMetadata.Attributes.First(a => a.LogicalName == "ownerid").SetSealedPropertyValue("DisplayName", new Label("Owner", 1033));
                    entityMetadata.Attributes.First(a => a.LogicalName == "ownerid").SetSealedPropertyValue("AttributeType", Sdk.Metadata.AttributeTypeCode.Owner);
                    entityMetadata.Attributes.First(a => a.LogicalName == "expiredreviewoptions").SetSealedPropertyValue("DisplayName", new Label("Expired Review Options", 1033));
                    entityMetadata.Attributes.First(a => a.LogicalName == "statecode").SetSealedPropertyValue("DisplayName", new Label("Status", 1033));
                    entityMetadata.Attributes.First(a => a.LogicalName == "statuscode").SetSealedPropertyValue("DisplayName", new Label("Status Reason", 1033));
                    entityMetadata.Attributes.First(a => a.LogicalName == "stageid").SetSealedPropertyValue("DisplayName", new Label("Stage Id", 1033));
                    entityMetadata.Attributes.First(a => a.LogicalName == "stageid").SetSealedPropertyValue("AttributeType", Sdk.Metadata.AttributeTypeCode.Uniqueidentifier);
                    entityMetadata.Attributes.First(a => a.LogicalName == "description").SetSealedPropertyValue("DisplayName", new Label("Short Description", 1033));
                    entityMetadata.Attributes.First(a => a.LogicalName == "articlepublicnumber").SetSealedPropertyValue("DisplayName", new Label("Article Public Number", 1033));
                    break;

                default:
                    break;
                }

                var response = new RetrieveEntityResponse()
                {
                    Results = new ParameterCollection
                    {
                        { "EntityMetadata", entityMetadata }
                    }
                };
                return(response);
            });

            IOrganizationService fakedService = fakedContext.GetOrganizationService();

            DataBuilder db = new DataBuilder(fakedService);

            db.AppendData("<fetch><entity name='account'><attribute name='accountid'/><attribute name='createdby'/></entity></fetch>");

            db.AppendData(SupportMethods.GetBooleanTypeExpectedData(), SupportMethods.GetBooleanTypeExpectedSchema());
            db.AppendData(SupportMethods.GetCustomerTypeExpectedData(), SupportMethods.GetCustomerTypeExpectedSchema());
            db.AppendData(SupportMethods.GetDateTimeTypeExpectedData(), SupportMethods.GetDateTimeTypeExpectedSchema());
            db.AppendData(SupportMethods.GetDecimalTypeExpectedData(), SupportMethods.GetDecimalTypeExpectedSchema());
            db.AppendData(SupportMethods.GetDoubleTypeExpectedData(), SupportMethods.GetDoubleTypeExpectedSchema());
            db.AppendData(SupportMethods.GetIntegerTypeExpectedData(), SupportMethods.GetIntegerTypeExpectedSchema());
            db.AppendData(SupportMethods.GetLookupTypeExpectedData(), SupportMethods.GetLookupTypeExpectedSchema());
            db.AppendData(SupportMethods.GetMemoTypeExpectedData(), SupportMethods.GetMemoTypeExpectedSchema());
            db.AppendData(SupportMethods.GetMoneyTypeExpectedData(), SupportMethods.GetMoneyTypeExpectedSchema());
            db.AppendData(SupportMethods.GetOwnerTypeExpectedData(), SupportMethods.GetOwnerTypeExpectedSchema());
            db.AppendData(SupportMethods.GetPartyListTypeExpectedData(), SupportMethods.GetPartyListTypeExpectedSchema());
            db.AppendData(SupportMethods.GetPicklistTypeExpectedData(), SupportMethods.GetPicklistTypeExpectedSchema());
            db.AppendData(SupportMethods.GetStateTypeExpectedData(), SupportMethods.GetStateTypeExpectedSchema());
            db.AppendData(SupportMethods.GetStatusTypeExpectedData(), SupportMethods.GetStatusTypeExpectedSchema());
            db.AppendData(SupportMethods.GetStringTypeExpectedData(), SupportMethods.GetStringTypeExpectedSchema());
            db.AppendData(SupportMethods.GetUniqueIdentifierTypeExpectedData(), SupportMethods.GetUniqueIdentifierTypeExpectedSchema());
            db.AppendData(SupportMethods.Getm2mRelationshipTypeExpectedData(), SupportMethods.Getm2mRelationshipTypeExpectedSchema());

            db.AppendData("<fetch><entity name='systemuser'><attribute name='systemuserid'/><attribute name='firstname'/><attribute name='lastname'/></entity></fetch>");

            db.SetIdentifier("systemuser", "systemuserid");

            Assert.AreEqual(
                db.BuildSchemaXML().InnerXml,
                SupportMethods.LoadXmlFile("../../lib/Configurations/MultipleSourcesOfMetadata_schema.xml"));
        }