public async Task GetDoesNotReturnProfileAfterLanguageRemovedTest() { var account = Model.Create <Account>(); var profile = Model.UsingBuildStrategy <ProfileBuildStrategy>().Create <Profile>(); var languageToRemoved = profile.Languages.First(); var filters = new List <ProfileFilter> { new ProfileFilter { CategoryGroup = CategoryGroup.Language, CategoryName = languageToRemoved } }; var address = ApiLocation.ProfilesMatching(filters); await profile.SaveAllCategories(_logger).ConfigureAwait(false); profile = await profile.Save(_logger).ConfigureAwait(false); var firstActual = await Client.Get <List <ProfileResult> >(address, _logger).ConfigureAwait(false); firstActual.Single(x => x.Id == profile.Id) .Should().BeEquivalentTo(profile, opt => opt.ExcludingMissingMembers()); profile = await profile.Set(x => x.Languages.Remove(languageToRemoved)).Save(_logger, account) .ConfigureAwait(false); var secondActual = await Client.Get <List <ProfileResult> >(address, _logger).ConfigureAwait(false); secondActual.Should().NotContain(x => x.Id == profile.Id); }
public async Task GetReturnsMultipleProfilesMatchingFiltersTest() { var firstProfile = await Model.UsingBuildStrategy <ProfileBuildStrategy>().Create <Profile>().Save(_logger) .ConfigureAwait(false); var secondProfile = await Model.UsingBuildStrategy <ProfileBuildStrategy>().Create <Profile>() .Set(x => x.Gender = firstProfile.Gender).Save(_logger).ConfigureAwait(false); var filters = new List <ProfileFilter> { new ProfileFilter { CategoryGroup = CategoryGroup.Gender, CategoryName = firstProfile.Gender } }; var address = ApiLocation.ProfilesMatching(filters); var actual = await Client.Get <List <ProfileResult> >(address, _logger).ConfigureAwait(false); actual.Single(x => x.Id == firstProfile.Id) .Should().BeEquivalentTo(firstProfile, opt => opt.ExcludingMissingMembers()); actual.Single(x => x.Id == secondProfile.Id) .Should().BeEquivalentTo(secondProfile, opt => opt.ExcludingMissingMembers()); }
public async Task GetReturnsProfileWithCaseInsensitiveFilterMatchTest(string filterName) { var category = new NewCategory { Group = CategoryGroup.Gender, Name = "Female" }; await category.Save(_logger).ConfigureAwait(false); var profile = await Model.UsingBuildStrategy <ProfileBuildStrategy>().Create <Profile>().Set(x => x.Gender = "Female") .Save(_logger).ConfigureAwait(false); var filters = new List <ProfileFilter> { new ProfileFilter { CategoryGroup = CategoryGroup.Gender, CategoryName = filterName } }; var address = ApiLocation.ProfilesMatching(filters); var actual = await Client.Get <List <ProfileResult> >(address, _logger).ConfigureAwait(false); actual.Single(x => x.Id == profile.Id).Should().BeEquivalentTo(profile, opt => opt.ExcludingMissingMembers()); }
public async Task GetReturnProfileAfterSkillAddedToMatchExistingFilterTest() { var account = Model.Create <Account>(); var newSkill = Model.UsingBuildStrategy <ProfileBuildStrategy>().Create <Skill>(); var profile = await Model.UsingBuildStrategy <ProfileBuildStrategy>().Create <Profile>().Save(_logger, account) .ConfigureAwait(false); var filters = new List <ProfileFilter> { new ProfileFilter { CategoryGroup = CategoryGroup.Skill, CategoryName = newSkill.Name } }; var address = ApiLocation.ProfilesMatching(filters); // Save the current categories await profile.SaveAllCategories(_logger).ConfigureAwait(false); var firstActual = await Client.Get <List <ProfileResult> >(address, _logger).ConfigureAwait(false); firstActual.Should().NotContain(x => x.Id == profile.Id); await profile.Set(x => x.Skills.Add(newSkill)).Save(_logger, account).ConfigureAwait(false); // Save the updated categories await profile.SaveAllCategories(_logger).ConfigureAwait(false); var secondActual = await Client.Get <List <ProfileResult> >(address, _logger).ConfigureAwait(false); secondActual.Single(x => x.Id == profile.Id) .Should().BeEquivalentTo(profile, opt => opt.ExcludingMissingMembers()); }
public async Task GetIgnoresFiltersOnUnapprovedCategoriesTest() { var firstProfile = Model.UsingBuildStrategy <ProfileBuildStrategy>().Create <Profile>().Set(x => x.Languages.Clear()) .Set(x => x.Languages.Add("English")); await firstProfile.SaveAllCategories(_logger).ConfigureAwait(false); firstProfile = await firstProfile.Save(_logger).ConfigureAwait(false); var secondProfile = await Model.UsingBuildStrategy <ProfileBuildStrategy>().Create <Profile>() .Set(x => x.Languages.Clear()).Set(x => x.Languages.Add("English")) .Set(x => x.Gender = Guid.NewGuid().ToString()).Save(_logger).ConfigureAwait(false); var filters = new List <ProfileFilter> { new ProfileFilter { CategoryGroup = CategoryGroup.Language, CategoryName = firstProfile.Languages.First() }, new ProfileFilter { CategoryGroup = CategoryGroup.Gender, CategoryName = secondProfile.Gender } }; var address = ApiLocation.ProfilesMatching(filters); var actual = await Client.Get <List <ProfileResult> >(address, _logger).ConfigureAwait(false); actual.Single(x => x.Id == firstProfile.Id) .Should().BeEquivalentTo(firstProfile, opt => opt.ExcludingMissingMembers()); actual.Single(x => x.Id == secondProfile.Id) .Should().BeEquivalentTo(secondProfile, opt => opt.ExcludingMissingMembers().Excluding(x => x.Gender)); }
public async Task GetDoesReturnProfileAfterGenderUpdatedMatchesExistingFilterTest() { var account = Model.Create <Account>(); var profile = Model.UsingBuildStrategy <ProfileBuildStrategy>().Create <Profile>().ClearSkills().ClearLanguages(); var newGender = Guid.NewGuid().ToString(); var filters = new List <ProfileFilter> { new ProfileFilter { CategoryGroup = CategoryGroup.Gender, CategoryName = newGender } }; var address = ApiLocation.ProfilesMatching(filters); profile = await profile.Save(_logger, account).ConfigureAwait(false); var firstActual = await Client.Get <List <ProfileResult> >(address, _logger).ConfigureAwait(false); firstActual.Should().NotContain(x => x.Id == profile.Id); profile.Gender = newGender; // Save the gender await profile.SaveAllCategories(_logger).ConfigureAwait(false); await profile.Save(_logger, account).ConfigureAwait(false); var secondActual = await Client.Get <List <ProfileResult> >(address, _logger).ConfigureAwait(false); secondActual.Single(x => x.Id == profile.Id) .Should().BeEquivalentTo(profile, opt => opt.ExcludingMissingMembers()); }
public async Task GetReturnsProfileWithoutGenderWhenGenderIsUnapprovedTest() { var profile = await Model.UsingBuildStrategy <ProfileBuildStrategy>().Create <Profile>() .Set(x => x.Gender = null) .ClearLanguages().Save(_logger) .ConfigureAwait(false); await profile.SaveAllCategories(_logger).ConfigureAwait(false); // Save a gender that is not approved profile = await profile.Set(x => x.Gender = Guid.NewGuid().ToString()).Save(_logger).ConfigureAwait(false); var filters = new List <ProfileFilter> { new ProfileFilter { CategoryGroup = CategoryGroup.Skill, CategoryName = profile.Skills.Skip(2).First().Name } }; var address = ApiLocation.ProfilesMatching(filters); var actual = await Client.Get <List <ProfileResult> >(address, _logger).ConfigureAwait(false); var result = actual.Single(x => x.Id == profile.Id); result.Should().BeEquivalentTo(profile, opt => opt.Excluding(x => x.Gender).ExcludingMissingMembers()); result.Gender.Should().BeNull(); }
public async Task GetReturnsSkillAfterApprovedForAnonymousUserTest() { var account = Model.UsingBuildStrategy <ProfileBuildStrategy>().Create <Account>(); var profile = Model.UsingBuildStrategy <ProfileBuildStrategy>().Create <Profile>().ClearCategories(); profile = await profile.Save(_logger, account).ConfigureAwait(false); var newSkill = new Skill { Level = SkillLevel.Expert, Name = Guid.NewGuid().ToString("N") }; profile.Skills.Add(newSkill); profile = await profile.Save(_logger, account).ConfigureAwait(false); var profileAddress = ApiLocation.ProfileFor(profile.Id); var firstActual = await Client.Get <PublicProfile>(profileAddress, _logger).ConfigureAwait(false); firstActual.Skills.Should().NotContain(x => x.Name == newSkill.Name); var administrator = ClaimsIdentityFactory.Build().AsAdministrator(); await new NewCategory { Group = CategoryGroup.Skill, Name = newSkill.Name }.Save(_logger, administrator).ConfigureAwait(false); var secondActual = await Client.Get <PublicProfile>(profileAddress, _logger).ConfigureAwait(false); secondActual.Skills.Should().Contain(x => x.Name == newSkill.Name); }
public static async Task <Profile> Save(this Profile profile, ILogger logger = null, Account account = null) { var address = ApiLocation.AccountProfile; // If account is null then this will be invoked with a new account // This is a one-time usage for testing because the caller will not have access // to the account context for any additional calls // If additional calls are required for the same account context then pass an account in and reuse it var identity = ClaimsIdentityFactory.Build(account, profile); await Client.Put(address, logger, profile, identity, HttpStatusCode.NoContent).ConfigureAwait(false); var actual = await Client.Get <Profile>(address, logger, identity).ConfigureAwait(false); if (profile.BannedAt != null) { var profileUri = ApiLocation.ProfileFor(actual.Id); var administrator = ClaimsIdentityFactory.Build().AsAdministrator(); // Use an admin to cancel the profile await Client.Delete(profileUri, logger, administrator).ConfigureAwait(false); actual.BannedAt = profile.BannedAt; } return(actual); }
public async Task PutMakesCategoryVisibleImmediatelyTest() { var expected = await Model.Create <NewCategory>().Save().ConfigureAwait(false); var identity = ClaimsIdentityFactory.Build().AsAdministrator(); var address = ApiLocation.Category(expected); var model = Model.Create <UpdateCategory>().Set(x => x.Visible = false); await Client.Put(address, _logger, model, identity, HttpStatusCode.NoContent).ConfigureAwait(false); // Get the public categories again for an anonymous user var firstCategories = await Client.Get <List <PublicCategory> >(ApiLocation.Categories, _logger) .ConfigureAwait(false); // It is currently not visible so we should have it returned here firstCategories.Should().NotContain(x => x.Group == expected.Group && x.Name == expected.Name); model.Visible = true; await Client.Put(address, _logger, model, identity, HttpStatusCode.NoContent).ConfigureAwait(false); var secondCategories = await Client.Get <List <PublicCategory> >(ApiLocation.Categories, _logger) .ConfigureAwait(false); // It is currently not visible so we should have it returned here var actual = secondCategories.Single(x => x.Group == expected.Group && x.Name == expected.Name); actual.LinkCount.Should().Be(0); }
public async Task DeleteReturnsNotFoundForEmptyIdTest() { var administrator = ClaimsIdentityFactory.Build().AsAdministrator(); var profileUri = ApiLocation.ProfileFor(Guid.Empty); await Client.Delete(profileUri, _logger, administrator, HttpStatusCode.NotFound).ConfigureAwait(false); }
public async Task GetReturnsNotFoundForInvalidIdTest() { var profile = Model.UsingBuildStrategy <ProfileBuildStrategy>().Create <Profile>(); var address = ApiLocation.ProfileFor(profile.Id); await Client.Get(address, _logger, null, HttpStatusCode.NotFound).ConfigureAwait(false); }
public async Task PutUpdatesProfileInformationForBannedAccountTest() { var expected = Model.UsingBuildStrategy <ProfileBuildStrategy>().Create <UpdatableProfile>(); var user = ClaimsIdentityFactory.Build(null, expected); // Create the profile await Client.Put(ApiLocation.AccountProfile, _logger, expected, user, HttpStatusCode.NoContent) .ConfigureAwait(false); // Get the profile var storedProfile = await Client.Get <Profile>(ApiLocation.AccountProfile, _logger, user).ConfigureAwait(false); var administrator = ClaimsIdentityFactory.Build().AsAdministrator(); // Ban the profile await Client.Delete(ApiLocation.ProfileFor(storedProfile.Id), _logger, administrator).ConfigureAwait(false); // Make a change to the profile expected.FirstName = Guid.NewGuid().ToString(); // Update the profile again await Client.Put(ApiLocation.AccountProfile, _logger, expected, user, HttpStatusCode.NoContent) .ConfigureAwait(false); var actual = await Client.Get <Profile>(ApiLocation.AccountProfile, _logger, user).ConfigureAwait(false); actual.Should().BeEquivalentTo(expected, opt => opt.ExcludingMissingMembers()); }
public async Task PutReturnsUnauthorizedForAnonymousUserTest() { var expected = Model.Create <Category>(); var address = ApiLocation.Category(expected); await Client.Put(address, _logger, null, null, HttpStatusCode.Unauthorized).ConfigureAwait(false); }
public async Task GetReturnsCategoryWithCorrectLinkCountWhenProfileBannedTest() { var account = Model.Create <Account>(); var profile = await Model.UsingBuildStrategy <ProfileBuildStrategy>().Create <Profile>().Save(_logger, account) .ConfigureAwait(false); var newCategory = profile.Skills.First(); var address = ApiLocation.Category(newCategory); var categoryApproval = new NewCategory { Group = CategoryGroup.Skill, Name = newCategory.Name }; await categoryApproval.Save(_logger).ConfigureAwait(false); var firstActual = await Client.Get <PublicCategory>(address, _logger).ConfigureAwait(false); firstActual.LinkCount.Should().Be(1); await profile.Set(x => x.BannedAt = DateTimeOffset.UtcNow).Save(_logger, account).ConfigureAwait(false); var secondActual = await Client.Get <PublicCategory>(address, _logger).ConfigureAwait(false); secondActual.LinkCount.Should().Be(0); }
public async Task GetOnlyIncludesApprovedSkillTest(bool approved) { var categoryName = Guid.NewGuid().ToString(); if (approved) { // Store the category as an administrator which will also make it approved by default var category = new NewCategory { Group = CategoryGroup.Skill, Name = categoryName }; await category.Save(_logger).ConfigureAwait(false); } var profile = await Model.UsingBuildStrategy <ProfileBuildStrategy>().Create <Profile>() .Set(x => x.Skills.First().Name = categoryName) .Save(_logger).ConfigureAwait(false); var address = ApiLocation.ProfileFor(profile.Id); var actual = await Client.Get <PublicProfile>(address, _logger).ConfigureAwait(false); if (approved) { actual.Skills.Should().Contain(x => x.Name == categoryName); } else { actual.Skills.Should().NotContain(x => x.Name == categoryName); } }
public async Task GetReturnsCategoryWithCorrectLinkCountWhenProfileIsHiddenAndThenRestoredTest( ProfileStatus status) { var account = Model.Create <Account>(); var profile = await Model.UsingBuildStrategy <ProfileBuildStrategy>().Create <Profile>().Set(x => x.Status = status) .Save(_logger, account).ConfigureAwait(false); var newCategory = profile.Skills.First(); var address = ApiLocation.Category(newCategory); var categoryApproval = new NewCategory { Group = CategoryGroup.Skill, Name = newCategory.Name }; await categoryApproval.Save(_logger).ConfigureAwait(false); var firstActual = await Client.Get <PublicCategory>(address, _logger).ConfigureAwait(false); firstActual.LinkCount.Should().Be(1); await profile.Set(x => x.Status = ProfileStatus.Hidden).Save(_logger, account).ConfigureAwait(false); var secondActual = await Client.Get <PublicCategory>(address, _logger).ConfigureAwait(false); secondActual.LinkCount.Should().Be(0); await profile.Set(x => x.Status = status).Save(_logger, account).ConfigureAwait(false); var thirdActual = await Client.Get <PublicCategory>(address, _logger).ConfigureAwait(false); thirdActual.LinkCount.Should().Be(1); }
public async Task DeleteRemovesAccountFromSearchResultsTest() { var profile = Model.UsingBuildStrategy <ProfileBuildStrategy>().Create <Profile>(); var account = Model.UsingBuildStrategy <ProfileBuildStrategy>().Create <Account>(); var identity = ClaimsIdentityFactory.Build(account, profile); var filters = new List <ProfileFilter> { new ProfileFilter { CategoryGroup = CategoryGroup.Language, CategoryName = profile.Languages.Skip(2).First() } }; var searchAddress = ApiLocation.ProfilesMatching(filters); var actual = await profile.Save(_logger, account).ConfigureAwait(false); await profile.SaveAllCategories(_logger).ConfigureAwait(false); var address = ApiLocation.AccountProfile; await Client.Delete(address, _logger, identity).ConfigureAwait(false); var profileResults = await Client.Get <List <ProfileResult> >(searchAddress, _logger).ConfigureAwait(false); profileResults.Should().NotContain(x => x.Id == profile.Id); await IsDeleted(actual.Id, identity).ConfigureAwait(false); }
public async Task DeleteReturnsUnauthorizedForAnonymousUserTest() { var profile = await Model.UsingBuildStrategy <ProfileBuildStrategy>().Create <Profile>().Save().ConfigureAwait(false); var address = ApiLocation.ProfileFor(profile.Id); await Client.Delete(address, _logger, null, HttpStatusCode.Unauthorized).ConfigureAwait(false); }
public async Task PutReturnsNotFoundWhenNameNotProvidedTest(string name) { var model = Model.Create <Category>().Set(x => x.Name = name); var identity = ClaimsIdentityFactory.Build().AsAdministrator(); var address = ApiLocation.Category(model); await Client.Put(address, _logger, model, identity, HttpStatusCode.NotFound).ConfigureAwait(false); }
public async Task PutReturnsForbiddenWhenUserNotAdministratorTest() { var expected = Model.Create <Category>(); var identity = ClaimsIdentityFactory.Build(); var address = ApiLocation.Category(expected); await Client.Put(address, _logger, null, identity, HttpStatusCode.Forbidden).ConfigureAwait(false); }
public async Task PutReturnsNotFoundWhenGroupIsInvalidTest() { var model = Model.Create <Category>().Set(x => x.Group = (CategoryGroup)int.MaxValue); var identity = ClaimsIdentityFactory.Build().AsAdministrator(); var address = ApiLocation.Category(model); await Client.Put(address, _logger, model, identity, HttpStatusCode.NotFound).ConfigureAwait(false); }
public async Task PutReturnsBadRequestWhenNoContentProvidedTest() { var model = Model.Create <Category>(); var identity = ClaimsIdentityFactory.Build().AsAdministrator(); var address = ApiLocation.Category(model); await Client.Put(address, _logger, null, identity, HttpStatusCode.BadRequest).ConfigureAwait(false); }
public async Task GetReturnsNotFoundForUnapprovedCategoryForAnonymousUserTest() { var profile = await Model.UsingBuildStrategy <ProfileBuildStrategy>().Create <Profile>().Save().ConfigureAwait(false); var newCategory = profile.Skills.First(); var address = ApiLocation.Category(newCategory); await Client.Get <PublicCategory>(address, _logger, null, HttpStatusCode.NotFound).ConfigureAwait(false); }
public async Task GetReturnsNotFoundForBannedProfileTest() { var profile = await Model.UsingBuildStrategy <ProfileBuildStrategy>().Create <Profile>() .Set(x => x.BannedAt = DateTimeOffset.UtcNow).Save(_logger).ConfigureAwait(false); var address = ApiLocation.ProfileFor(profile.Id); await Client.Get(address, _logger, null, HttpStatusCode.NotFound).ConfigureAwait(false); }
public async Task GetReturnsNotFoundForHiddenProfileTest() { var profile = await Model.UsingBuildStrategy <ProfileBuildStrategy>().Create <Profile>() .Set(x => x.Status = ProfileStatus.Hidden).Save(_logger).ConfigureAwait(false); var address = ApiLocation.ProfileFor(profile.Id); await Client.Get(address, _logger, null, HttpStatusCode.NotFound).ConfigureAwait(false); }
public async Task PutReturnsNotFoundWhenCategoryDoesNotExistTest() { var expected = Model.Create <Category>(); var identity = ClaimsIdentityFactory.Build().AsAdministrator(); var address = ApiLocation.Category(expected); var model = Model.Create <UpdateCategory>().Set(x => x.Visible = true); await Client.Put(address, _logger, model, identity, HttpStatusCode.NotFound).ConfigureAwait(false); }
public async Task DeleteReturnsForbiddenWhenUserNotAdministratorTest() { var profile = await Model.UsingBuildStrategy <ProfileBuildStrategy>().Create <Profile>().Save().ConfigureAwait(false); var address = ApiLocation.ProfileFor(profile.Id); var identity = ClaimsIdentityFactory.Build(); await Client.Delete(address, _logger, identity, HttpStatusCode.Forbidden).ConfigureAwait(false); }
public async Task GetReturnsVisibleCategoryForAnonymousUserTest() { var newCategory = await Model.Create <NewCategory>().Save().ConfigureAwait(false); var address = ApiLocation.Category(newCategory); var actual = await Client.Get <PublicCategory>(address, _logger).ConfigureAwait(false); actual.Should().BeEquivalentTo(newCategory, opt => opt.ExcludingMissingMembers()); }
public async Task GetDoesNotReturnProfileEmailTest() { var profile = await Model.UsingBuildStrategy <ProfileBuildStrategy>().Create <Profile>().Save().ConfigureAwait(false); var address = ApiLocation.ProfileFor(profile.Id); var actual = await Client.Get <Profile>(address, _logger).ConfigureAwait(false); actual.Email.Should().BeNull(); }