Exemplo n.º 1
0
        public void SuperAdmin_can_access_all_brands()
        {
            // *** Arrange ***
            const int brandCount = 20;
            var       brands     = new List <Core.Brand.Interface.Data.Brand>();

            for (var i = 0; i < brandCount; i++)
            {
                brands.Add(CreateBrand());
            }

            var admin         = SecurityRepository.GetAdminById(_actorInfoProvider.Actor.Id);
            var allowedBrands = brands.Select(b => b.Id).ToList();

            allowedBrands.AddRange(admin.AllowedBrands.Select(b => b.Id));
            admin.SetAllowedBrands(allowedBrands);
            SecurityTestHelper.SignInAdmin(admin);

            // *** Act ***
            var filtered = BrandQueries.GetFilteredBrands(brands, admin.Id);

            // *** Assert ***
            Assert.IsNotNull(filtered);
            Assert.True(filtered.Count() == brandCount);
        }
Exemplo n.º 2
0
        public void Cannot_access_multiple_licensees_brands_that_are_not_allowed_for_admin()
        {
            var notAllowedBrands = new List <Guid>();
            var allowedBrands    = new List <Guid>();

            // Generate 10 brands that are not allowed to user
            for (var i = 0; i < 10; i++)
            {
                // Generate licensee for brand
                var licensee = CreateLicensee();

                var brand = CreateBrand(licensee);
                notAllowedBrands.Add(brand.Id);
            }

            var currentUser = SecurityRepository.GetAdminById(_actorInfoProvider.Actor.Id);
            var currentUserAllowedBrands = currentUser.AllowedBrands.Select(b => b.Id).ToList();

            currentUserAllowedBrands.AddRange(notAllowedBrands);
            currentUser.SetAllowedBrands(currentUserAllowedBrands);
            SecurityTestHelper.SignInAdmin(currentUser);

            var admin = SecurityTestHelper.CreateAdmin();

            admin.Licensees.Clear();
            admin.AllowedBrands.Clear();

            // Generate 5 brands that are allowed to user
            for (var i = 0; i < 5; i++)
            {
                var licensee = CreateLicensee();

                var brand = CreateBrand(licensee);
                admin.AddAllowedBrand(brand.Id);
                allowedBrands.Add(brand.Id);
            }

            SecurityTestHelper.SignInAdmin(admin);

            /*** Act ***/
            var brands = BrandQueries.GetAllBrands();

            /*** Assert ***/
            Assert.AreEqual(brands.Count(), allowedBrands.Count);
            // Check if filtered brands are same with allowed brands
            Assert.True(!brands.Select(b => b.Id).Except(allowedBrands).Any());
            // Check if there are no forbidden brands among filtered for user
            Assert.False(brands.Select(b => b.Id).Intersect(notAllowedBrands).Any());
        }