示例#1
0
 public UpdateContactFacetsService(IXdbContextFactory xdbContextFactory, IContactManagerService contactManager, IList <IContactFacetUpdater> facetUpdaters)
 {
     Assert.ArgumentNotNull(xdbContextFactory, nameof(xdbContextFactory));
     Assert.ArgumentNotNull(contactManager, nameof(contactManager));
     Assert.ArgumentNotNull(facetUpdaters, nameof(facetUpdaters));
     Assert.ArgumentCondition(facetUpdaters.Any(), nameof(facetUpdaters), $"{nameof(facetUpdaters)} must not be empty");
     this.xdbContextFactory = xdbContextFactory;
     this.contactManager    = contactManager;
     this.facetUpdaters     = facetUpdaters;
 }
示例#2
0
        public void UpdateContactFacets_ShouldUpdateTracker(ITracker tracker, Contact contact, Sitecore.XConnect.Contact xdbContact, IXdbContextFactory xdbContextFactory, IXdbContext xdbContext, IContactManagerService contactManager, IContactFacetUpdater facetUpdater, string source, string identifier)
        {
            // Arrange
            contact.Identifiers.Returns(new List <ContactIdentifier>
            {
                new ContactIdentifier(source, identifier, ContactIdentificationLevel.Known)
            }.AsReadOnly());
            tracker.Contact.Returns(contact);
            xdbContext.GetAsync <Sitecore.XConnect.Contact>(Arg.Any <IdentifiedContactReference>(), Arg.Any <ContactExpandOptions>()).Returns(Task.FromResult(xdbContact));
            xdbContextFactory.CreateContext().Returns(xdbContext);
            var userProfile = Substitute.For <Sitecore.Security.UserProfile>();

            facetUpdater.SetFacets(userProfile, xdbContact, xdbContext).Returns(true);
            var facetsService = new UpdateContactFacetsService(xdbContextFactory, contactManager, new List <IContactFacetUpdater> {
                facetUpdater
            });

            // Act
            using (new TrackerSwitcher(tracker))
            {
                facetsService.UpdateContactFacets(userProfile);
            }

            // Assert
            contactManager.Received(1).SaveContact();
            contactManager.Received(1).ReloadContact();
        }