Skip to content
This repository has been archived by the owner on Dec 6, 2019. It is now read-only.

Commit

Permalink
[#392] fixed up Feature/Accounts UserProfileService tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nickwesselman committed Jun 28, 2018
1 parent 318e3d1 commit 5837960
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 25 deletions.
Expand Up @@ -238,7 +238,7 @@
<Compile Include="Services\FacetUpdaters\PhoneFacetUpdaterTests.cs" />
<Compile Include="UpdateContactFacetsServiceTests.cs" />
<Compile Include="UserProfileProviderTests.cs" />
<None Include="UserProfileServiceTests.cs" />
<Compile Include="UserProfileServiceTests.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config">
Expand Down
29 changes: 5 additions & 24 deletions src/Feature/Accounts/Tests/UserProfileServiceTests.cs
Expand Up @@ -60,7 +60,7 @@ public void GetInterestsShouldReturnInterests([Frozen] IEnumerable<string> inter
}

[Theory, AutoDbDataWithExtension]
public void GetProfileShouldReturnFullEditProfileModel(Db db, [Substitute] UserProfile userProfile, [RightKeys("FirstName", "LastName", "Phone", "Interest")] IDictionary<string, string> properties,
public void GetProfileShouldReturnFullEditProfileModel(Db db, [Substitute] UserProfile userProfile, string username, [RightKeys("FirstName", "LastName", "Phone", "Interest")] IDictionary<string, string> properties,
[Frozen] IProfileSettingsService profileSettingsService, [Frozen] IUserProfileProvider userProfileProvider, [Greedy] UserProfileService userProfileService)
{
var id = new ID();
Expand All @@ -77,7 +77,9 @@ public void GetInterestsShouldReturnInterests([Frozen] IEnumerable<string> inter
profileSettingsService.GetUserDefaultProfile().Returns(db.GetItem(id));
userProfileProvider.GetCustomProperties(Arg.Any<UserProfile>()).Returns(properties);

var result = userProfileService.GetProfile(userProfile);
var user = Substitute.For<Sitecore.Security.Accounts.User>($@"extranet\{username}", true);
user.Profile.Returns(userProfile);
var result = userProfileService.GetProfile(user);
result.FirstName.Should().Be(properties["FirstName"]);
result.LastName.Should().Be(properties["LastName"]);
result.PhoneNumber.Should().Be(properties["Phone"]);
Expand All @@ -99,34 +101,13 @@ public void SetProfileShouldUpdateUserProfile(Db db, [Substitute] UserProfile us
}
});
profileSettingsService.GetUserDefaultProfile().Returns(db.GetItem(id));
userProfileService.SetProfile(userProfile, editProfile);
userProfileService.SaveProfile(userProfile, editProfile);

userProfileProvider.Received(1).SetCustomProfile(userProfile, Arg.Is<IDictionary<string, string>>(
x => x["FirstName"] == editProfile.FirstName &&
x["LastName"] == editProfile.LastName &&
x["Interest"] == editProfile.Interest &&
x["Phone"] == editProfile.PhoneNumber));
}

[Theory, AutoDbDataWithExtension(typeof(AutoConfiguredNSubstituteCustomization))]
public void ValidateProfileShouldAddModelError(ModelStateDictionary modelState, [Frozen] IEnumerable<string> interests, IProfileSettingsService profileSettingsService, IUserProfileProvider userProfileProvider, [Greedy] UserProfileService userProfileService)
{
var editProfile = new EditProfile() { Interest = "invalid interest" };

var result = userProfileService.ValidateProfile(editProfile, modelState);

result.Should().BeFalse();
modelState.Keys.Should().Contain("Interest");
}

[Theory, AutoDbDataWithExtension(typeof(AutoConfiguredNSubstituteCustomization))]
public void ValidateProfileShouldreturnValid(ModelStateDictionary modelState, [Frozen] IEnumerable<string> interests, IProfileSettingsService profileSettingsService, IUserProfileProvider userProfileProvider, [Greedy] UserProfileService userProfileService)
{
var editProfile = new EditProfile() { Interest = interests.First() };

var result = userProfileService.ValidateProfile(editProfile, modelState);

result.Should().BeTrue();
}
}
}

0 comments on commit 5837960

Please sign in to comment.