예제 #1
0
        private static void ApplyUpdate(ContactAggregateUpdate update, ContactProfile contact)
        {
            if (!string.IsNullOrEmpty(update.NewTitle))
                contact.Title = update.NewTitle;
            //if (!string.IsNullOrEmpty(update.NewFullName))
            //    contact.FullName = update.NewFullName;
            if (update.RemovedAvatars != null)
                update.RemovedAvatars.ToList().ForEach(avatar => contact.AvatarUris.Remove(avatar));
            if (update.RemovedHandles != null)
                update.RemovedHandles.ToList().ForEach(handle => contact.Handles.Remove(handle));
            //if(update.RemovedProviders != null)
            //    update.RemovedProviders.ToList().ForEach(provider=> contact.Providers.Remove(provider));
            if (update.RemovedTags != null)
                update.RemovedTags.ToList().ForEach(tag => contact.Tags.Remove(tag));
            if (update.RemovedOrganizations != null)
                update.RemovedOrganizations.ToList().ForEach(org => contact.Organizations.Remove(org));
            if (update.RemovedRelationships != null)
                update.RemovedRelationships.ToList().ForEach(org => contact.Relationships.Remove(org));

            if (update.AddedAvatars != null)
                contact.AvatarUris.AddRange(update.AddedAvatars);
            if (update.AddedHandles != null)
                contact.Handles.AddRange(update.AddedHandles.Select(h => h.ToContactHandle()));
            //if(update.AddedProviders != null)
            //    contact.Providers.AddRange(update.AddedProviders);
            if (update.AddedTags != null)
                contact.Tags.AddRange(update.AddedTags);
            if (update.AddedOrganizations != null)
                update.AddedOrganizations.ToList().ForEach(org => contact.Organizations.Add(org));
            if (update.AddedRelationships != null)
                update.AddedRelationships.ToList().ForEach(org => contact.Relationships.Add(org));
        }
예제 #2
0
 private void IndexHandles(ContactAggregateUpdate update, ContactProfile contact)
 {
     if (update.RemovedHandles != null)
         DeleteHandleIndex(update.RemovedHandles, contact);
     if (update.AddedHandles != null)
         AddHandleIndex(update, contact);
 }
예제 #3
0
 public ContactAggregateUpdateSummary(int eventId, ContactAggregateUpdate source)
 {
     EventId = eventId;
     Id = source.Id;
     Version = source.Version;
     IsDeleted = source.IsDeleted;
     NewTitle = source.NewTitle;
     AddedAvatars = source.AddedAvatars;
     RemovedAvatars = source.RemovedAvatars;
 }
        public void RemovingContact()
        {
            var contactA = GenerateContact("PrimaryAccount", "Alex Albert", "*****@*****.**", "*****@*****.**");
            var contactB = GenerateContact("PrimaryAccount", "Barry Bonds", "*****@*****.**", "*****@*****.**");
            var contactC = GenerateContact("PrimaryAccount", "Charlie Campbell", "*****@*****.**", "*****@*****.**");

            var contactBDeletion = contactB.Clone();
            contactBDeletion.IsDeleted = true;

            var expected = new ContactAggregateUpdate
            {
                Version = 2,
                IsDeleted = true,
            };

            new UserContactRemovedScenario()
               .Given(s => s.Given_a_populated_UserContacts_instance(contactA, contactB, contactC))
               .When(s => s.When_a_ContactSummary_is_removed(contactBDeletion))
               .Then(s => s.Then_Snapshot_has_only(expected))
               .BDDfy();
        }
예제 #5
0
        public ContactLookup Add(ContactAggregateUpdate update)
        {
            ContactProfile contact;
            if (_contactsById.TryGetValue(update.Id, out contact))
            {
                if (update.IsDeleted)
                {
                    Remove(update, contact);
                    return this;
                }
                ApplyUpdate(update, contact);
            }
            else
            {
                contact = new ContactProfile(update.Id);
                ApplyUpdate(update, contact);
                _contactsById[contact.Id] = contact;
            }
            IndexHandles(update, contact);

            return this;
        }
예제 #6
0
 private void AddHandleIndex(ContactAggregateUpdate update, ContactProfile contact)
 {
     var normalizedHandles = update.AddedHandles
         .Select(h => h.ToContactHandle())
         .SelectMany(h => h.NormalizedHandle())
         .Where(h=>!string.IsNullOrWhiteSpace(h));
     foreach (var handle in normalizedHandles)
     {
         List<IContactProfile> lookup;
         if (!_contactsByKey.TryGetValue(handle, out lookup))
         {
             lookup = new List<IContactProfile>();
             Trace.WriteLine("---Adding Key [" + handle + "]");
             _contactsByKey[handle] = lookup;
         }
         else
         {
             Trace.WriteLine(string.Format("Found duplicate key : '{0}'", handle));
         }
         lookup.Add(contact);
     }
 }
예제 #7
0
 private void Remove(ContactAggregateUpdate update, ContactProfile contact)
 {
     _contactsById.Remove(update.Id);
     DeleteHandleIndex(contact.Handles, contact);
 }
 private static void IsSummaryEqualToUpdate(IAccountContactSummary summary, ContactAggregateUpdate update)
 {
     CollectionAssert.AreEqual(summary.AvatarUris, update.AddedAvatars);
     Assert.AreEqual(summary.Provider, update.AddedProviders.Single().ProviderName);
     Assert.AreEqual(summary.AccountId, update.AddedProviders.Single().AccountId);
     Assert.AreEqual(summary.ProviderId, update.AddedProviders.Single().ContactId);
     CollectionAssert.AreEqual(summary.Tags, update.AddedTags);
     Assert.AreEqual(summary.Title, update.NewTitle);
 }
예제 #9
0
 private void AddHandleIndex(ContactAggregateUpdate update, ContactProfile contact)
 {
     var normalizedHandles = update.AddedHandles
         .Select(h=>h.ToContactHandle())
         .SelectMany(h=>h.NormalizedHandle());
     foreach (var handle in normalizedHandles)
     {
         List<IContactProfile> lookup;
         if (!_contactsByKey.TryGetValue(handle, out lookup))
         {
             lookup = new List<IContactProfile>();
             Trace.WriteLine("---Adding Key [" + handle + "]");
             _contactsByKey[handle] = lookup;
         }
         lookup.Add(contact);
     }
 }
        public void UpdatingContactAggregateWithMatchingContact()
        {
            var initialContact = new StubContactSummary
            {
                Provider = "StubProvider",
                AccountId = "*****@*****.**",
                ProviderId = "*****@*****.**",
                Title = "Jonny Doe",
                Handles =
                {
                    new ContactEmailAddress("*****@*****.**", "home"),
                }
            };
            var matchingContact = new StubContactSummary
            {
                Provider = "StubProvider",
                AccountId = "*****@*****.**",
                ProviderId = "*****@*****.**",
                Handles =
                {
                    new ContactEmailAddress("*****@*****.**", "other"),
                    new ContactPhoneNumber("+44 7 1234 56778", "mobile"),
                }
            };

            var expected = new ContactAggregateUpdate
            {
                Version = 2,
                NewTitle = initialContact.Title,
                AddedProviders = new[]
                {
                    new ContactProviderSummary(initialContact.Provider, initialContact.AccountId,
                        initialContact.ProviderId),
                    new ContactProviderSummary(matchingContact.Provider, matchingContact.AccountId,
                        matchingContact.ProviderId),
                },
                AddedHandles = initialContact.Handles
                    .Concat(matchingContact.Handles.Skip(1))
                    .Select(h => new ContactHandleRecord(h))
                    .ToArray()
            };

            new UserContactUpdateSingleContactAggregateScenario()
               .Given(s => s.Given_a_UserContacts_instance())
               .When(s => s.When_a_ContactSummary_is_added(initialContact))
               .When(s => s.When_a_ContactSummary_is_added(matchingContact))
               .Then(s => s.Then_Snapshot_has_only(expected))
               .BDDfy();
        }
            public void Then_Snapshot_has_only(ContactAggregateUpdate expected)
            {
                var snapshot = _userContacts.GetChangesSnapshot();
                var actual = snapshot.Single();

                //Assert.AreEqual(expected.Id);
                Assert.AreEqual(expected.Version, actual.Version);
                Assert.AreEqual(expected.NewTitle, actual.NewTitle);
                CollectionAssert.AreEqual(expected.AddedAvatars, actual.AddedAvatars);
                CollectionAssert.AreEqual(expected.RemovedAvatars, actual.RemovedAvatars);

                CollectionAssert.AreEqual(expected.AddedTags, actual.AddedTags);
                CollectionAssert.AreEqual(expected.RemovedTags, actual.RemovedTags);

                CollectionAssert.AreEqual(expected.AddedProviders, actual.AddedProviders, ContactProviderSummaryComparer.Instance);
                CollectionAssert.AreEqual(expected.RemovedProviders, actual.RemovedProviders, ContactProviderSummaryComparer.Instance);

                CollectionAssert.AreEqual(expected.AddedHandles, actual.AddedHandles);
                CollectionAssert.AreEqual(expected.RemovedHandles, actual.RemovedHandles);
            }
        public void Merging_multiple_contacts()
        {
            var accId = "ABC";
            var barx = new StubContactSummary
            {
                Provider = "Google",
                AccountId = accId,
                Title = "Campbell, Erynne",
                ProviderId = "http://www.google.com/m8/feeds/contacts/lee.ryan.campbell%40gmail.com/base/37cc52308c94e30f",
                Handles =
                {
                    new ContactEmailAddress("*****@*****.**", "work"),
                    new ContactEmailAddress("*****@*****.**", "work"),
                }
            };
            var old = new StubContactSummary
            {
                Provider = "Google",
                AccountId = accId,
                Title = "Erynne Campbell",
                ProviderId = "http://www.google.com/m8/feeds/contacts/lee.ryan.campbell%40gmail.com/base/aa",
                Handles =
                {
                    new ContactEmailAddress("*****@*****.**", "Obsolete"),
                    new ContactPhoneNumber("+61417910632", "mobile"),
                    new ContactPhoneNumber("+447554257819", "mobile"),
                }
            };
            var current = new StubContactSummary
            {
                Provider = "Google",
                AccountId = accId,
                Title = "Erynne Campbell",
                ProviderId = "http://www.google.com/m8/feeds/contacts/lee.ryan.campbell%40gmail.com/base/78a2b08a3e7700",
                Handles =
                {
                    new ContactEmailAddress("*****@*****.**", "Obsolete"),                    
                }
            };

            var expected = new ContactAggregateUpdate()
            {
                //Id = ??
                Version = 3,
                NewTitle = "Erynne Campbell",
                IsDeleted = false,
                AddedProviders = new ContactProviderSummary[]
                {
                    new ContactProviderSummary{
                        AccountId = accId,
                        ContactId = "http://www.google.com/m8/feeds/contacts/lee.ryan.campbell%40gmail.com/base/37cc52308c94e30f",
                        ProviderName = "Google"
     
                    },
                    new ContactProviderSummary{
                        AccountId = accId,
                        ContactId =  "http://www.google.com/m8/feeds/contacts/lee.ryan.campbell%40gmail.com/base/aa",
                        ProviderName = "Google"
                    },
                    new ContactProviderSummary{
                        AccountId = accId,
                        ContactId =  "http://www.google.com/m8/feeds/contacts/lee.ryan.campbell%40gmail.com/base/78a2b08a3e7700",
                        ProviderName = "Google"
                    }
               },
                AddedHandles = new ContactHandle[]
               {
                   new ContactEmailAddress("*****@*****.**", "work"),
                   new ContactEmailAddress("*****@*****.**", "work"),
                   new ContactEmailAddress("*****@*****.**", "Obsolete"),
                   new ContactPhoneNumber("+61417910632", "mobile"),
                   new ContactPhoneNumber("+447554257819", "mobile"),
                   new ContactEmailAddress("*****@*****.**", "Obsolete"),                    
               }.Select(h => new ContactHandleRecord(h))
               .ToArray()
            };

            new UserContactUpdateSingleContactAggregateScenario()
               .Given(s => s.Given_a_UserContacts_instance())
               .When(s => s.When_a_ContactSummary_is_added(barx))
               .When(s => s.When_a_ContactSummary_is_added(old))
               .When(s => s.When_a_ContactSummary_is_added(current))
               .Then(s => s.Then_Snapshot_has_only(expected))
               .BDDfy();
        }