public void UpdateContactFacets_ShouldSubmitToXdb(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 xdbContext.Received().SubmitAsync(); }
private void SetFacets_NoExistingValue_ShouldSetfacet(Contact xdbContact, IXdbContext xdbContext, string profileKey, string value, Func <PersonalInformation, bool> assertValue) { // Arrange var userProfile = Substitute.For <Sitecore.Security.UserProfile>(); userProfile[profileKey] = value; var facetUpdater = new PersonalInformationFacetUpdater(); // Act var changed = facetUpdater.SetFacets(userProfile, xdbContact, xdbContext); // Assert changed.Should().BeTrue(); xdbContext.Received(1).RegisterOperation(Arg.Is <SetFacetOperation <PersonalInformation> >(x => x.FacetReference.FacetKey == PersonalInformation.DefaultFacetKey && assertValue(x.Facet))); }
public void SetFacets_NoPhoneList_ShouldSetFacet(Contact xdbContact, IXdbContext xdbContext, string phone) { // Arrange var userProfile = Substitute.For <Sitecore.Security.UserProfile>(); userProfile[Accounts.Constants.UserProfile.Fields.PhoneNumber] = phone; var facetUpdater = new PhoneFacetUpdater(); // Act var changed = facetUpdater.SetFacets(userProfile, xdbContact, xdbContext); // Assert changed.Should().BeTrue(); xdbContext.Received(1).RegisterOperation(Arg.Is <SetFacetOperation>(x => x.FacetReference.FacetKey == PhoneNumberList.DefaultFacetKey && ((PhoneNumberList)x.Facet).PreferredPhoneNumber.Number == phone)); }
public void SetFacets_NoEmailList_ShouldSetFacet(Contact xdbContact, IXdbContext xdbContext, string email) { // Arrange var userProfile = Substitute.For <Sitecore.Security.UserProfile>(); userProfile.Email.Returns(email); var facetUpdater = new EmailFacetUpdater(); // Act var changed = facetUpdater.SetFacets(userProfile, xdbContact, xdbContext); // Assert changed.Should().BeTrue(); xdbContext.Received(1).RegisterOperation(Arg.Is <SetFacetOperation>(x => x.FacetReference.FacetKey == EmailAddressList.DefaultFacetKey && ((EmailAddressList)x.Facet).PreferredEmail.SmtpAddress == email)); }
public void SetFacets_NoAvatar_ShouldSetFacet(IWebClient webClient, Contact xdbContact, IXdbContext xdbContext, string url, string mimeType, byte[] picture) { // Arrange var userProfile = Substitute.For <Sitecore.Security.UserProfile>(); userProfile[Accounts.Constants.UserProfile.Fields.PictureUrl] = url; userProfile[Accounts.Constants.UserProfile.Fields.PictureMimeType] = mimeType; webClient.DownloadData(url).Returns(picture); var facetUpdater = new AvatarFacetUpdater(webClient); // Act var changed = facetUpdater.SetFacets(userProfile, xdbContact, xdbContext); // Assert changed.Should().BeTrue(); xdbContext.Received(1).RegisterOperation(Arg.Is <SetFacetOperation>(x => x.FacetReference.FacetKey == Avatar.DefaultFacetKey && ((Avatar)x.Facet).Picture == picture && ((Avatar)x.Facet).MimeType == mimeType)); }