Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
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.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);
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
0
        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);
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
0
        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);
        }
Ejemplo n.º 11
0
        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());
        }
Ejemplo n.º 12
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());
        }
Ejemplo n.º 13
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());
        }
Ejemplo n.º 14
0
        public async Task GetReturnsGenderCorrectlyWhenToggledBetweenVisibleAndInvisibleTest()
        {
            var profile = Model.UsingBuildStrategy <ProfileBuildStrategy>().Create <Profile>()
                          .Set(x => x.Gender = Guid.NewGuid().ToString());
            var filters = new List <ProfileFilter>
            {
                new ProfileFilter
                {
                    CategoryGroup = CategoryGroup.Language,
                    CategoryName  = profile.Languages.Skip(2).First()
                }
            };
            var address = ApiLocation.ProfilesMatching(filters);

            await profile.SaveAllCategories().ConfigureAwait(false);

            profile = await profile.Save().ConfigureAwait(false);

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

            firstActual.Single(x => x.Id == profile.Id).Gender.Should().Be(profile.Gender);

            var administrator   = ClaimsIdentityFactory.Build().AsAdministrator();
            var categoryAddress = ApiLocation.Category(CategoryGroup.Gender, profile.Gender);
            var updateCategory  = new UpdateCategory
            {
                Visible = false
            };

            // Hide the gender category
            await Client.Put(categoryAddress, _logger, updateCategory, administrator, HttpStatusCode.NoContent)
            .ConfigureAwait(false);

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

            secondActual.Single(x => x.Id == profile.Id).Gender.Should().BeNullOrEmpty();

            updateCategory.Visible = true;

            // Show the gender category again
            await Client.Put(categoryAddress, _logger, updateCategory, administrator, HttpStatusCode.NoContent)
            .ConfigureAwait(false);

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

            thirdActual.Single(x => x.Id == profile.Id).Gender.Should().Be(profile.Gender);
        }
Ejemplo n.º 15
0
        public async Task GetReturnsCategoryWithCorrectLinkCountWhenUsedAfterApprovalByAdministratorTest()
        {
            var profile = await Model.UsingBuildStrategy <ProfileBuildStrategy>().Create <Profile>().Save().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 actual = await Client.Get <PublicCategory>(address, _logger).ConfigureAwait(false);

            actual.Should().BeEquivalentTo(newCategory, opt => opt.ExcludingMissingMembers());
            actual.LinkCount.Should().Be(1);
        }
Ejemplo n.º 16
0
        public async Task GetReturnsCategoryAfterApprovalForAdministratorTest()
        {
            var profile = await Model.UsingBuildStrategy <ProfileBuildStrategy>().Create <Profile>().Save().ConfigureAwait(false);

            var newCategory      = profile.Skills.First();
            var address          = ApiLocation.Category(newCategory);
            var categoryApproval = new NewCategory
            {
                Group = CategoryGroup.Skill,
                Name  = newCategory.Name
            };
            var administrator = ClaimsIdentityFactory.Build().AsAdministrator();

            await Client.Get <PublicCategory>(address, _logger, null, HttpStatusCode.NotFound).ConfigureAwait(false);

            await categoryApproval.Save(_logger, administrator).ConfigureAwait(false);

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

            actual.Should().BeEquivalentTo(newCategory, opt => opt.ExcludingMissingMembers());
        }
Ejemplo n.º 17
0
        public async Task PutSetsReviewedToTrueTest()
        {
            var profile = await Model.UsingBuildStrategy <ProfileBuildStrategy>().Create <Profile>().Save().ConfigureAwait(false);

            var skill    = profile.Skills.First();
            var category = new Category
            {
                Group = CategoryGroup.Skill,
                Name  = skill.Name
            };
            var address  = ApiLocation.Category(category);
            var identity = ClaimsIdentityFactory.Build().AsAdministrator();
            var model    = Model.Create <UpdateCategory>();

            await Client.Put(address, _logger, model, identity, HttpStatusCode.NoContent).ConfigureAwait(false);

            var categories = await Client.Get <List <Category> >(ApiLocation.Categories, _logger, identity)
                             .ConfigureAwait(false);

            var actual = categories.Single(x => x.Group == category.Group && x.Name == category.Name);

            actual.Reviewed.Should().BeTrue();
        }
Ejemplo n.º 18
0
        public async Task GetReturnsNotFoundForInvalidCategoryGroupTest()
        {
            var address = ApiLocation.Category("some", "other");

            await Client.Get(address, _logger, null, HttpStatusCode.NotFound).ConfigureAwait(false);
        }