Ejemplo n.º 1
0
        /// <summary>
        /// Updates the First or Last Name of the contact to match the given case
        /// </summary>
        /// <param name="service">The service.</param>
        /// <param name="name">The name.</param>
        public static void MakeNameMatchCase(IOrganizationService service, string name)
        {
            using (var context = new CrmContext(service))
            {
                var contacts = (from c in context.ContactSet
                                where c.FirstName == name || c.LastName == name
                                select new Contact {Id = c.Id, FirstName = c.FirstName, LastName = c.LastName}).ToList();

                foreach (var contact in contacts.Where(c => StringsAreEqualButCaseIsNot(c.FirstName, name)))
                {
                    contact.FirstName = name;
                    context.UpdateObject(contact);
                }

                foreach (var contact in contacts.Where(c => StringsAreEqualButCaseIsNot(c.LastName, name)))
                {
                    contact.LastName = name;
                    context.UpdateObject(contact);
                }

                context.SaveChanges();
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// The actual test to perform.  The IOrganization Service passed in is either a local CRM service, or a real connection
 /// Depending on the UnitTestSettings's UseLocalCrm App Setting
 /// </summary>
 /// <param name="service">The service.</param>
 protected override void Test(IOrganizationService service)
 {
     using (var context = new CrmContext(service))
     {
         var account = context.AccountSet.FirstOrDefault(c => c.Name == Ids.Account.Entity.Name);
         Assert.IsNotNull(account);
         Assert.IsNotNull(account.AccountNumber, "Account Number should have been populated by Builder");
         account = context.AccountSet.FirstOrDefault(c => c.Name == "Jane Doe");
         Assert.IsNull(account, "Jane Doe was not added and the query should have returned null");
     }
 }