public async Task PutReturnsBadRequestForEmptyBodyTest()
        {
            var user = ClaimsIdentityFactory.Build();

            await Client.Put(ApiLocation.AccountProfile, _logger, null, user, HttpStatusCode.BadRequest)
            .ConfigureAwait(false);
        }
示例#2
0
        public async Task GetReturnsCategoryWithCorrectLinkCountWhenProfileIsRemovedFromExistingCategoryTest()
        {
            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.Categories;
            var categoryApproval = new NewCategory
            {
                Group = CategoryGroup.Skill,
                Name  = newCategory.Name
            };
            var administrator = ClaimsIdentityFactory.Build().AsAdministrator();

            await Client.Post(address, _logger, categoryApproval, administrator).ConfigureAwait(false);

            profile.Skills.Remove(profile.Skills.First());

            await profile.Save(_logger, account).ConfigureAwait(false);

            var actual = await Client.Get <List <PublicCategory> >(address, _logger).ConfigureAwait(false);

            var category = actual.Single(x => x.Group == CategoryGroup.Skill && x.Name == newCategory.Name);

            category.LinkCount.Should().Be(0);
        }
示例#3
0
        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);
        }
示例#4
0
        public async Task GetReturnsProfileWithMultiplePhotosTest()
        {
            var account = Model.UsingBuildStrategy <ProfileBuildStrategy>().Create <Account>();
            var profile = await Model.UsingBuildStrategy <ProfileBuildStrategy>().Create <Profile>().ClearCategories()
                          .Save(_logger, account).ConfigureAwait(false);

            var identity       = ClaimsIdentityFactory.Build(account, profile);
            var profileAddress = ApiLocation.AccountProfilePhotos;
            var expected       = Resources.photo;

            await Client.PostFile <PhotoDetails>(profileAddress, _logger, expected, identity)
            .ConfigureAwait(false);

            await Client.PostFile <PhotoDetails>(profileAddress, _logger, expected, identity)
            .ConfigureAwait(false);

            var result = await Client.PostFile <PhotoDetails>(profileAddress, _logger, expected, identity)
                         .ConfigureAwait(false);

            var photo = result.Item2;

            var export = await Client.Get <ExportProfile>(ApiLocation.AccountProfileExport, _logger, identity).ConfigureAwait(false);

            export.Should().BeEquivalentTo(profile, opt => opt.ExcludingMissingMembers());
            export.Photos.Should().HaveCount(3);
            export.Photos.All(x => x.Hash == photo.Hash).Should().BeTrue();
            export.Photos.All(x => x.ProfileId == profile.Id).Should().BeTrue();
            export.Photos.All(x => x.Data.SequenceEqual(expected)).Should().BeTrue();
        }
示例#5
0
        public async Task PostReturnsBadRequestWhenNoContentProvidedTest()
        {
            var identity = ClaimsIdentityFactory.Build().AsAdministrator();
            var address  = ApiLocation.Categories;

            await Client.Post(address, _logger, null, identity, HttpStatusCode.BadRequest).ConfigureAwait(false);
        }
        public async Task GetHandlesRaceConditionWithMultipleCallsOnNewAccountTest()
        {
            // Related to Issue 35
            for (var index = 0; index < 50; index++)
            {
                _output.WriteLine("Executing test " + (index + 1));

                var profile         = Model.UsingBuildStrategy <ProfileBuildStrategy>().Create <Profile>();
                var identity        = ClaimsIdentityFactory.Build(null, profile);
                var profileAddress  = ApiLocation.AccountProfile;
                var categoryAddress = ApiLocation.Categories;

                var profileTask = Client.Get <Profile>(profileAddress, null, identity);
                var tasks       = new List <Task>
                {
                    profileTask
                };

                for (var categoryCount = 0; categoryCount < 10; categoryCount++)
                {
                    var categoryTask = Client.Get <List <Category> >(categoryAddress, null, identity);

                    tasks.Add(categoryTask);
                }

                await Task.WhenAll(tasks).ConfigureAwait(false);
            }
        }
示例#7
0
        public async Task PostReturnsForbiddenWhenUserNotAdministratorTest()
        {
            var identity = ClaimsIdentityFactory.Build();
            var address  = ApiLocation.Categories;

            await Client.Post(address, _logger, null, identity, HttpStatusCode.Forbidden).ConfigureAwait(false);
        }
示例#8
0
        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);
        }
示例#9
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);
        }
示例#10
0
        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);
        }
示例#11
0
        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.Categories;
            var categoryApproval = new NewCategory
            {
                Group = CategoryGroup.Skill,
                Name  = newCategory.Name
            };
            var administrator = ClaimsIdentityFactory.Build().AsAdministrator();

            await Client.Post(address, _logger, categoryApproval, administrator).ConfigureAwait(false);

            var firstActual = await Client.Get <List <PublicCategory> >(address, _logger).ConfigureAwait(false);

            firstActual.Single(x => x.Group == CategoryGroup.Skill && x.Name == newCategory.Name).LinkCount.Should()
            .Be(1);

            await profile.Set(x => x.BannedAt = DateTimeOffset.UtcNow).Save(_logger, account).ConfigureAwait(false);

            var secondActual = await Client.Get <List <PublicCategory> >(address, _logger).ConfigureAwait(false);

            secondActual.Single(x => x.Group == CategoryGroup.Skill && x.Name == newCategory.Name).LinkCount.Should()
            .Be(0);
        }
示例#12
0
        public static async Task SaveAllCategories(this Profile profile, ILogger logger = null)
        {
            var administrator = ClaimsIdentityFactory.Build().AsAdministrator();

            var tasks = new List <Task>();

            if (profile.Gender != null)
            {
                tasks.Add(new NewCategory {
                    Group = CategoryGroup.Gender, Name = profile.Gender
                }.Save(logger,
                       administrator));
            }

            foreach (var language in profile.Languages)
            {
                tasks.Add(new NewCategory {
                    Group = CategoryGroup.Language, Name = language
                }
                          .Save(logger, administrator));
            }

            foreach (var skill in profile.Skills)
            {
                tasks.Add(new NewCategory {
                    Group = CategoryGroup.Skill, Name = skill.Name
                }.Save(logger, administrator));
            }

            await Task.WhenAll(tasks).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 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);
        }
示例#15
0
        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);
        }
示例#16
0
        public async Task PostReturnsCreatedForNewCategoryTest()
        {
            var model    = Model.Create <NewCategory>();
            var identity = ClaimsIdentityFactory.Build().AsAdministrator();
            var address  = ApiLocation.Categories;

            await Client.Post(address, _logger, model, identity).ConfigureAwait(false);
        }
        public async Task PutReturnsBadRequestForInvalidEmailTest(string email)
        {
            var expected = Model.UsingBuildStrategy <ProfileBuildStrategy>().Create <UpdatableProfile>().Set(x => x.Email = email);
            var user     = ClaimsIdentityFactory.Build(null, expected);

            await Client.Put(ApiLocation.AccountProfile, _logger, expected, user, HttpStatusCode.BadRequest)
            .ConfigureAwait(false);
        }
示例#18
0
        public async Task PostReturnsBadRequestWhenUnsupportedGroupProvidedTest()
        {
            var model    = Model.Create <NewCategory>().Set(x => x.Group = (CategoryGroup)1234);
            var identity = ClaimsIdentityFactory.Build().AsAdministrator();
            var address  = ApiLocation.Categories;

            await Client.Post(address, _logger, model, identity, HttpStatusCode.BadRequest).ConfigureAwait(false);
        }
示例#19
0
        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);
        }
示例#20
0
        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);
        }
示例#21
0
        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);
        }
示例#22
0
        public async Task GetReturnsNotFoundForUnapprovedCategoryForAuthenticatedUserTest()
        {
            var profile = await Model.UsingBuildStrategy <ProfileBuildStrategy>().Create <Profile>().Save().ConfigureAwait(false);

            var newCategory = profile.Skills.First();
            var address     = ApiLocation.Category(newCategory);
            var identity    = ClaimsIdentityFactory.Build();

            await Client.Get <PublicCategory>(address, _logger, identity, HttpStatusCode.NotFound).ConfigureAwait(false);
        }
        public async Task GetForNewUserCreatesProfileAsHiddenTest()
        {
            var profile  = Model.UsingBuildStrategy <ProfileBuildStrategy>().Create <Profile>();
            var identity = ClaimsIdentityFactory.Build(null, profile);
            var address  = ApiLocation.AccountProfile;

            var actual = await Client.Get <Profile>(address, _logger, identity).ConfigureAwait(false);

            actual.Status.Should().Be(ProfileStatus.Hidden);
        }
示例#24
0
        public async Task GetReturnsVisibleCategoriesForAuthenticatedUserTest()
        {
            var expected = await Model.Create <NewCategory>().Save().ConfigureAwait(false);

            var identity = ClaimsIdentityFactory.Build();
            var address  = ApiLocation.Categories;

            var actual = await Client.Get <List <PublicCategory> >(address, _logger, identity).ConfigureAwait(false);

            actual.Should().Contain(x => x.Group == expected.Group && x.Name == expected.Name);
        }
示例#25
0
        public async Task GetReturnsAllCategoriesForAdministratorTest()
        {
            var expected = await Model.Create <NewCategory>().Save().ConfigureAwait(false);

            var administrator = ClaimsIdentityFactory.Build().AsAdministrator();
            var address       = ApiLocation.Categories;

            var actual = await Client.Get <List <Category> >(address, _logger, administrator).ConfigureAwait(false);

            actual.Should().Contain(x => x.Group == expected.Group && x.Name == expected.Name);
        }
示例#26
0
        public async Task GetReturnsCategoryForAdministratorTest()
        {
            var expected = await Model.Create <NewCategory>().Save().ConfigureAwait(false);

            var administrator = ClaimsIdentityFactory.Build().AsAdministrator();
            var address       = ApiLocation.Category(expected);

            var actual = await Client.Get <Category>(address, _logger, administrator).ConfigureAwait(false);

            actual.Should().BeEquivalentTo(expected, opt => opt.ExcludingMissingMembers());
        }
示例#27
0
        public async Task GetReturnsVisibleCategoryForAuthenticatedUserTest()
        {
            var newCategory = await Model.Create <NewCategory>().Save().ConfigureAwait(false);

            var identity = ClaimsIdentityFactory.Build();
            var address  = ApiLocation.Category(newCategory);

            var actual = await Client.Get <PublicCategory>(address, _logger, identity).ConfigureAwait(false);

            actual.Should().BeEquivalentTo(newCategory, opt => opt.ExcludingMissingMembers());
        }
        public async Task PutUpdatesProfileInformationTest()
        {
            var expected = Model.UsingBuildStrategy <ProfileBuildStrategy>().Create <UpdatableProfile>();
            var user     = ClaimsIdentityFactory.Build(null, expected);

            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());
        }
示例#29
0
        public async Task GetDoesNotReturnUnapprovedCategoryCreatedByProfilePutForAuthenticatedUserTest()
        {
            var profile = await Model.UsingBuildStrategy <ProfileBuildStrategy>().Create <Profile>().Save().ConfigureAwait(false);

            var newCategory = profile.Skills.First();
            var address     = ApiLocation.Categories;
            var identity    = ClaimsIdentityFactory.Build();

            var actual = await Client.Get <List <PublicCategory> >(address, _logger, identity).ConfigureAwait(false);

            actual.Should().NotContain(x => x.Group == CategoryGroup.Skill && x.Name == newCategory.Name);
        }
示例#30
0
        public async Task GetReturnsUnapprovedCategoryForAdministratorTest()
        {
            var profile = await Model.UsingBuildStrategy <ProfileBuildStrategy>().Create <Profile>().Save().ConfigureAwait(false);

            var newCategory = profile.Skills.First();
            var address     = ApiLocation.Category(newCategory);
            var identity    = ClaimsIdentityFactory.Build().AsAdministrator();

            var actual = await Client.Get <PublicCategory>(address, _logger, identity).ConfigureAwait(false);

            actual.Should().BeEquivalentTo(newCategory, opt => opt.ExcludingMissingMembers());
        }