public static void Should_Populate_EntityReference_Name_When_Metadata_Is_Provided() { var userMetadata = new EntityMetadata() { LogicalName = "systemuser" }; userMetadata.SetSealedPropertyValue("PrimaryNameAttribute", "fullname"); var user = new Entity() { LogicalName = "systemuser", Id = Guid.NewGuid() }; user["fullname"] = "Fake XrmEasy"; var context = new XrmFakedContext(); context.InitializeMetadata(userMetadata); context.Initialize(user); context.CallerId = user.ToEntityReference(); var account = new Entity() { LogicalName = "account" }; var service = context.GetOrganizationService(); var accountId = service.Create(account); account = service.Retrieve("account", accountId, new ColumnSet(true)); Assert.Equal("Fake XrmEasy", account.GetAttributeValue <EntityReference>("ownerid").Name); }
public void Upsert_Creates_Record_When_It_Does_Not_Exist_Using_Alternate_Key() { var context = new XrmFakedContext(); context.ProxyTypesAssembly = Assembly.GetExecutingAssembly(); context.InitializeMetadata(Assembly.GetExecutingAssembly()); var service = context.GetOrganizationService(); var metadata = context.GetEntityMetadataByName("contact"); metadata.SetFieldValue("_keys", new EntityKeyMetadata[] { new EntityKeyMetadata() { KeyAttributes = new string[] { "firstname" } } }); context.SetEntityMetadata(metadata); var contact = new Contact() { FirstName = "FakeXrm", LastName = "Easy" }; contact.KeyAttributes.Add("firstname", contact.FirstName); var request = new UpsertRequest() { Target = contact }; var response = (UpsertResponse)service.Execute(request); Assert.Equal(true, response.RecordCreated); }
public static void When_retrieve_attribute_request_is_called_correctly_attribute_is_returned() { var ctx = new XrmFakedContext(); var service = ctx.GetOrganizationService(); var entityMetadata = new EntityMetadata() { LogicalName = "account" }; var nameAttribute = new StringAttributeMetadata() { LogicalName = "name", RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.ApplicationRequired) }; entityMetadata.SetAttributeCollection(new[] { nameAttribute }); ctx.InitializeMetadata(entityMetadata); RetrieveAttributeRequest req = new RetrieveAttributeRequest() { EntityLogicalName = "account", LogicalName = "name" }; var response = service.Execute(req) as RetrieveAttributeResponse; Assert.NotNull(response.AttributeMetadata); Assert.Equal(AttributeRequiredLevel.ApplicationRequired, response.AttributeMetadata.RequiredLevel.Value); Assert.Equal("name", response.AttributeMetadata.LogicalName); }
public void translated_fields_should_change() { // Arrange var context = new XrmFakedContext(); var pluginContext = context.GetDefaultPluginContext(); var metadata = GetMockedMultiLanguageMetadata(); context.InitializeMetadata(metadata); var preImageTheme = new opc_theme { opc_islocalizable = true, opc_name = $"{Prefix}Technology|Technologee", opc_nameenglish = "Technology", opc_namefrench = "Technologee" }; var targetTheme = new opc_theme { opc_namefrench = "Technologie" }; var previous = preImageTheme.opc_name; pluginContext.PreEntityImages.Add("PreImage", preImageTheme); pluginContext.InputParameters.Add(InputParameter.Target, targetTheme); pluginContext.MessageName = PluginMessage.Update; // Act context.ExecutePluginWith <MultiLanguagePlugin>(pluginContext); // Assert var expected = $"{Prefix}{string.Join(Separator, new[] { preImageTheme.opc_nameenglish, targetTheme.opc_namefrench })}"; targetTheme.opc_name.Should().NotBe(previous); targetTheme.opc_name.Should().Be(expected); }
public void AndOr() { var context = new XrmFakedContext(); context.InitializeMetadata(Assembly.GetExecutingAssembly()); var org = context.GetOrganizationService(); var metadata = new AttributeMetadataCache(org); var fetch = @" <fetch> <entity name='contact'> <attribute name='firstname' /> <attribute name='lastname' /> <filter> <condition attribute='firstname' operator='eq' value='Mark' /> <filter type='or'> <condition attribute='lastname' operator='eq' value='Carrington' /> <condition attribute='lastname' operator='eq' value='Twain' /> </filter> </filter> </entity> </fetch>"; var converted = FetchXml2Sql.Convert(org, metadata, fetch, new FetchXml2SqlOptions(), out _); Assert.AreEqual("SELECT firstname, lastname FROM contact WHERE firstname = 'Mark' AND (lastname = 'Carrington' OR lastname = 'Twain')", NormalizeWhitespace(converted)); }
public FakeXrmEasyTestsBase() { _context = new XrmFakedContext(); _context.InitializeMetadata(Assembly.GetExecutingAssembly()); _service = _context.GetOrganizationService(); _dataSource = new DataSource { Name = "uat", Connection = _service, Metadata = new AttributeMetadataCache(_service), TableSizeCache = new StubTableSizeCache() }; _context2 = new XrmFakedContext(); _context2.InitializeMetadata(Assembly.GetExecutingAssembly()); _service2 = _context2.GetOrganizationService(); _dataSource2 = new DataSource { Name = "prod", Connection = _service2, Metadata = new AttributeMetadataCache(_service2), TableSizeCache = new StubTableSizeCache() }; _dataSources = new[] { _dataSource, _dataSource2 }.ToDictionary(ds => ds.Name); _localDataSource = new Dictionary <string, DataSource> { ["local"] = _dataSource }; SetPrimaryIdAttributes(_context); SetPrimaryIdAttributes(_context2); }
public void When_updating_an_entity_by_alternate_key_the_context_should_reflect_changes() { var context = new XrmFakedContext(); var service = context.GetOrganizationService(); var accountMetadata = new Microsoft.Xrm.Sdk.Metadata.EntityMetadata(); accountMetadata.LogicalName = Account.EntityLogicalName; var alternateKeyMetadata = new Microsoft.Xrm.Sdk.Metadata.EntityKeyMetadata(); alternateKeyMetadata.KeyAttributes = new string[] { "AccountNumber" }; accountMetadata.SetFieldValue("_keys", new Microsoft.Xrm.Sdk.Metadata.EntityKeyMetadata[] { alternateKeyMetadata }); context.InitializeMetadata(accountMetadata); var e = new Entity("account"); e["AccountNumber"] = 9000; e["name"] = "Before update"; var guid = service.Create(e); Assert.Equal(context.Data["account"][guid]["name"], "Before update"); //now update the name e = new Entity("account", "AccountNumber", 9000); e["name"] = "After update"; service.Update(e); Assert.Equal(context.Data["account"][guid]["name"], "After update"); }
public void JoinFilter() { var context = new XrmFakedContext(); context.InitializeMetadata(Assembly.GetExecutingAssembly()); var org = context.GetOrganizationService(); var metadata = new AttributeMetadataCache(org); var fetch = @" <fetch> <entity name='contact'> <attribute name='firstname' /> <attribute name='lastname' /> <link-entity name='account' from='accountid' to='parentcustomerid'> <attribute name='name' /> <filter> <condition attribute='name' operator='eq' value='data8' /> </filter> </link-entity> <filter> <condition attribute='firstname' operator='eq' value='Mark' /> </filter> </entity> </fetch>"; var converted = FetchXml2Sql.Convert(org, metadata, fetch, new FetchXml2SqlOptions(), out _); Assert.AreEqual("SELECT contact.firstname, contact.lastname, account.name FROM contact INNER JOIN account ON contact.parentcustomerid = account.accountid AND account.name = 'data8' WHERE contact.firstname = 'Mark'", NormalizeWhitespace(converted)); }
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())); }
public void NextXYearsConversion() { var context = new XrmFakedContext(); context.InitializeMetadata(Assembly.GetExecutingAssembly()); var org = context.GetOrganizationService(); var metadata = new AttributeMetadataCache(org); var fetch = @" <fetch> <entity name='contact'> <attribute name='firstname' /> <attribute name='lastname' /> <filter> <condition attribute='createdon' operator='next-x-years' value='2' /> </filter> </entity> </fetch>"; var converted = FetchXml2Sql.Convert(org, metadata, fetch, new FetchXml2SqlOptions { PreserveFetchXmlOperatorsAsFunctions = false }, out _); Assert.AreEqual($"SELECT firstname, lastname FROM contact WHERE createdon >= '{DateTime.Now:s}' AND createdon < '{DateTime.Today.AddDays(1).AddYears(2):s}'", NormalizeWhitespace(converted)); }
public void EqBusinessId() { var context = new XrmFakedContext(); context.InitializeMetadata(Assembly.GetExecutingAssembly()); context.AddFakeMessageExecutor <WhoAmIRequest>(new WhoAmIHandler()); var org = context.GetOrganizationService(); var metadata = new AttributeMetadataCache(org); var fetch = @" <fetch> <entity name='contact'> <attribute name='firstname' /> <attribute name='lastname' /> <filter> <condition attribute='parentcustomerid' operator='eq-businessid' /> </filter> </entity> </fetch>"; var converted = FetchXml2Sql.Convert(org, metadata, fetch, new FetchXml2SqlOptions { PreserveFetchXmlOperatorsAsFunctions = false }, out _); Assert.AreEqual($"SELECT firstname, lastname FROM contact WHERE parentcustomerid = '{WhoAmIHandler.BusinessUnitId:D}'", NormalizeWhitespace(converted)); }
public void ParameterConversion() { var context = new XrmFakedContext(); context.InitializeMetadata(Assembly.GetExecutingAssembly()); var org = context.GetOrganizationService(); var metadata = new AttributeMetadataCache(org); var fetch = @" <fetch> <entity name='contact'> <attribute name='firstname' /> <attribute name='lastname' /> <filter> <condition attribute='firstname' operator='eq' value='Mark' /> </filter> </entity> </fetch>"; var converted = FetchXml2Sql.Convert(org, metadata, fetch, new FetchXml2SqlOptions { UseParametersForLiterals = true }, out var parameters); Assert.AreEqual("SELECT firstname, lastname FROM contact WHERE firstname = @firstname", NormalizeWhitespace(converted)); Assert.AreEqual("Mark", parameters["@firstname"]); }
public static void Should_Retrieve_A_Correct_Entity_By_Alternate_Key() { var fakedContext = new XrmFakedContext(); var accountMetadata = new Microsoft.Xrm.Sdk.Metadata.EntityMetadata(); accountMetadata.LogicalName = Account.EntityLogicalName; var alternateKeyMetadata = new Microsoft.Xrm.Sdk.Metadata.EntityKeyMetadata(); alternateKeyMetadata.KeyAttributes = new string[] { "alternateKey" }; accountMetadata.SetFieldValue("_keys", new Microsoft.Xrm.Sdk.Metadata.EntityKeyMetadata[] { alternateKeyMetadata }); fakedContext.InitializeMetadata(accountMetadata); var account = new Entity(Account.EntityLogicalName); account.Id = Guid.NewGuid(); account.Attributes.Add("alternateKey", "key"); fakedContext.Initialize(account); var fakedService = fakedContext.GetOrganizationService(); var request = new RetrieveRequest { Target = new EntityReference(Account.EntityLogicalName, "alternateKey", "key"), ColumnSet = new ColumnSet(allColumns: true) }; var retrievedAccount = (RetrieveResponse)fakedService.Execute(request); Assert.Equal(account.Id, retrievedAccount.Entity.Id); }
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); }
public FakeXrmEasyTestsBase() { _context = new XrmFakedContext(); _context.InitializeMetadata(Assembly.GetExecutingAssembly()); _service = _context.GetOrganizationService(); }
public static IOrganizationService Initialize() { var fakedContext = new XrmFakedContext(); fakedContext.InitializeMetadata(typeof(CrmEarlyBound.WebResource).Assembly); return(fakedContext.GetOrganizationService()); }
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 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()); }
public void When_delete_is_invoked_with_an_existing_entity_by_alternate_key_that_entity_is_delete_from_the_context() { var context = new XrmFakedContext(); var accountMetadata = new Microsoft.Xrm.Sdk.Metadata.EntityMetadata(); accountMetadata.LogicalName = Account.EntityLogicalName; var alternateKeyMetadata = new Microsoft.Xrm.Sdk.Metadata.EntityKeyMetadata(); alternateKeyMetadata.KeyAttributes = new string[] { "AccountNumber" }; accountMetadata.SetFieldValue("_keys", new Microsoft.Xrm.Sdk.Metadata.EntityKeyMetadata[] { alternateKeyMetadata }); context.InitializeMetadata(accountMetadata); //Initialize the context with a single entity var account = new Entity("account"); account.Id = Guid.NewGuid(); account.Attributes.Add("AccountNumber", 9000); context.Initialize(account); var service = context.GetOrganizationService(); var delete = new DeleteRequest { Target = new EntityReference("account", "AccountNumber", 9000) }; service.Execute(delete); Assert.True(context.Data["account"].Count == 0); }
public void Should_also_update_entity_metadata_when_not_using_global_option_set() { var label = "dummy label"; var attributeName = "statuscode"; var ctx = new XrmFakedContext(); var entityMetadata = new EntityMetadata() { LogicalName = "contact" }; StatusAttributeMetadata enumAttribute = new StatusAttributeMetadata() { LogicalName = attributeName }; entityMetadata.SetAttributeCollection(new List <AttributeMetadata>() { enumAttribute }); ctx.InitializeMetadata(entityMetadata); var req = new InsertOptionValueRequest() { EntityLogicalName = Contact.EntityLogicalName, AttributeLogicalName = attributeName, Label = new Label(label, 0) }; var service = ctx.GetOrganizationService(); service.Execute(req); //Check the optionsetmetadata was updated var key = $"{Contact.EntityLogicalName}#{attributeName}"; Assert.True(ctx.OptionSetValuesMetadata.ContainsKey(key)); var option = ctx.OptionSetValuesMetadata[key].Options.FirstOrDefault(); Assert.Equal(label, option.Label.LocalizedLabels[0].Label); // Get a list of Option Set values for the Status Reason fields from its metadata RetrieveAttributeRequest attReq = new RetrieveAttributeRequest { EntityLogicalName = "contact", LogicalName = "statuscode", RetrieveAsIfPublished = true }; RetrieveAttributeResponse attResponse = (RetrieveAttributeResponse)service.Execute(attReq); StatusAttributeMetadata statusAttributeMetadata = (StatusAttributeMetadata)attResponse.AttributeMetadata; Assert.NotNull(statusAttributeMetadata.OptionSet); Assert.NotNull(statusAttributeMetadata.OptionSet.Options); Assert.Equal(1, statusAttributeMetadata.OptionSet.Options.Count(o => o.Label.LocalizedLabels[0].Label == label)); }
public FakeXrmEasyTestsBase() { _context = new XrmFakedContext(); _context.InitializeMetadata(Assembly.GetExecutingAssembly()); _context.AddFakeMessageExecutor <WhoAmIRequest>(new WhoAmIHandler()); _service = _context.GetOrganizationService(); }
private void InitialiseFakeXrm() { xrmContextPlugin = new XrmFakedPluginExecutionContext(); xrmContext = new XrmFakedContext(); var assemblyEntities = System.Reflection.Assembly.GetAssembly(typeof(Account)); xrmContext.InitializeMetadata(assemblyEntities); xrmContext.ProxyTypesAssembly = assemblyEntities; }
public void Should_throw_exception_if_logical_name_is_null_during_initialisation() { var ctx = new XrmFakedContext(); var entityMetadata = new EntityMetadata() { }; Assert.Throws <Exception>(() => ctx.InitializeMetadata(new List <EntityMetadata>() { entityMetadata })); }
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 AutocompleteTests() { var context = new XrmFakedContext(); context.InitializeMetadata(Assembly.GetExecutingAssembly()); var org = context.GetOrganizationService(); var metadata = new AttributeMetadataCache(org); var a = metadata["account"]; var c = metadata["contact"]; var n = metadata["new_customentity"]; _autocomplete = new Autocomplete(new[] { a, c, n }, metadata); }
public void An_entity_which_references_another_existent_entity_by_alternate_key_can_be_updated_when_validate_is_true() { var context = new XrmFakedContext(); context.ValidateReferences = true; IOrganizationService service = context.GetOrganizationService(); var accountMetadata = new Microsoft.Xrm.Sdk.Metadata.EntityMetadata(); accountMetadata.LogicalName = Account.EntityLogicalName; var alternateKeyMetadata = new Microsoft.Xrm.Sdk.Metadata.EntityKeyMetadata(); alternateKeyMetadata.KeyAttributes = new string[] { "alternateKey" }; accountMetadata.SetFieldValue("_keys", new Microsoft.Xrm.Sdk.Metadata.EntityKeyMetadata[] { alternateKeyMetadata }); context.InitializeMetadata(accountMetadata); var account = new Entity(Account.EntityLogicalName); account.Id = Guid.NewGuid(); account.Attributes.Add("alternateKey", "keyValue"); var account2 = new Entity(Account.EntityLogicalName); account2.Id = Guid.NewGuid(); account2.Attributes.Add("alternateKey", "keyValue2"); Entity otherEntity = new Entity("otherEntity"); otherEntity.Id = Guid.NewGuid(); otherEntity["new_accountId"] = new EntityReference("account", "alternateKey", "keyValue"); context.Initialize(new List <Entity>() { account, account2, otherEntity }); var entityToUpdate = new Entity("otherEntity") { Id = otherEntity.Id, ["new_accountId"] = new EntityReference("account", "alternateKey", "keyValue2") }; service.Update(entityToUpdate); Entity otherEntityInContext = service.Retrieve("otherEntity", otherEntity.Id, new ColumnSet(true)); Assert.Equal(((EntityReference)otherEntityInContext["new_accountId"]).Id, account2.Id); }
public void Should_throw_exception_if_entity_name_is_duplicated_during_initialisation() { var ctx = new XrmFakedContext(); var entityMetadata = new EntityMetadata() { LogicalName = "account" }; Assert.Throws <Exception>(() => ctx.InitializeMetadata(new List <EntityMetadata>() { entityMetadata, entityMetadata })); }
public static void When_using_proxy_types_assembly_the_attribute_metadata_is_inferred_from_injected_metadata_as_a_fallback() { var fakedContext = new XrmFakedContext(); fakedContext.ProxyTypesAssembly = Assembly.GetExecutingAssembly(); var contact1 = new Entity("contact") { Id = Guid.NewGuid() }; contact1["injectedAttribute"] = "Contact 1"; var contact2 = new Entity("contact") { Id = Guid.NewGuid() }; contact2["injectedAttribute"] = "Contact 2"; fakedContext.Initialize(new List <Entity>() { contact1, contact2 }); var contactMetadata = new EntityMetadata() { LogicalName = "contact" }; var injectedAttribute = new StringAttributeMetadata() { LogicalName = "injectedAttribute" }; contactMetadata.SetAttribute(injectedAttribute); fakedContext.InitializeMetadata(contactMetadata); var guid = Guid.NewGuid(); //Empty contecxt (no Initialize), but we should be able to query any typed entity without an entity not found exception var service = fakedContext.GetOrganizationService(); using (XrmServiceContext ctx = new XrmServiceContext(service)) { var contact = (from c in ctx.CreateQuery <Contact>() where c["injectedAttribute"].Equals("Contact 1") select c).ToList(); Assert.True(contact.Count == 1); } }
public void It_Should_Join_Non_Text_values() { var context = new XrmFakedContext(); var service = context.GetFakedOrganizationService(); var tracing = context.GetFakeTracingService(); var regardingObject = new Entity { LogicalName = "account", Id = Guid.NewGuid(), ["name"] = "Test" }; var email = new Entity { LogicalName = "email", Id = Guid.NewGuid(), Attributes = new AttributeCollection { { "subject", "TestSubject" }, { "oss_optionset", new OptionSetValue(1) }, { "regardingobjectid", regardingObject.ToEntityReference() } } }; var metadata = new EntityMetadata { LogicalName = "email" }; var field = typeof(EntityMetadata).GetField("_attributes", BindingFlags.NonPublic | BindingFlags.Instance); field.SetValue(metadata, new AttributeMetadata[] { new PicklistAttributeMetadata { LogicalName = "oss_optionset", OptionSet = new OptionSetMetadata { Options = { new OptionMetadata { Value = 1, Label = new Label("Value1", 1031) } } } } }); context.InitializeMetadata(metadata); context.Initialize(new[] { regardingObject }); var formula = "Join(\" \", [ Value(\"subject\"), Value(\"oss_optionset\", { optionSetLcid: 1031 }), Value(\"regardingobjectid.name\") ], true)"; var result = new XTLInterpreter(formula, email, null, service, tracing).Produce(); Assert.That(result, Is.EqualTo("TestSubject Value1 Test")); }
public void Should_store_a_clone_after_initialisation() { var ctx = new XrmFakedContext(); var entityMetadata = new EntityMetadata() { LogicalName = "account" }; ctx.InitializeMetadata(new List <EntityMetadata>() { entityMetadata }); var metadatas = ctx.CreateMetadataQuery().ToList(); Assert.True(metadatas[0] != entityMetadata); }