public void New_allowed_product_should_be_returned_in_search_result()
        {
            #region Setup

            var operationName = "/Category/Read";
            var readOperationOnCategory = AuthZRepository.CreateOperation(operationName);
            UsersGroup guestGroup = AuthZRepository.CreateUsersGroup("TmpGuests");
            AuthZRepository.AssociateUserWith(SampleUser, guestGroup);

            var permissionBuilder = ServiceLocator.Current.GetInstance<IPermissionsBuilderService>();
            permissionBuilder.Allow(readOperationOnCategory)
                .For(AdminUser)
                .OnEverything()
                .DefaultLevel()
                .Save();

            var categoryRepository = ServiceLocator.Current.GetInstance<CategoryRepository>();
            var allowedCategory = categoryRepository.Read(1);
            var deniedCategory = categoryRepository.Read(2);
            var entitiesGroupForCategory1 = AuthZRepository.CreateEntitiesGroup(string.Format("Category{0}",allowedCategory.CategoryId));
            AuthZRepository.AssociateEntityWith(allowedCategory, entitiesGroupForCategory1);

            CurrentSession.Flush();

            var productRepository = ServiceLocator.Current.GetInstance<ProductRepository>();
            productRepository.Search(null, allowedCategory).AsEnumerable().ToList().ForEach(x =>
            {
                AuthZRepository.AssociateEntityWith(x, entitiesGroupForCategory1);
            });

            permissionBuilder.Allow(readOperationOnCategory)
                .For(SampleUser)
                .On(entitiesGroupForCategory1)
                .DefaultLevel()
                .Save();

            CurrentSession.Flush();

            #endregion

            CurrentUser = SampleUser; // simulate different user
            var countOfAllowedProductsBeforeAddingNewProduct = productRepository.Search(null, null).Count();

            // now add a new product
            var p = new Product
            {
                Category = allowedCategory,
                Discontinued = false,
                EntitySecurityKey = Guid.NewGuid(),
                ProductName = "new test product"
            };

            productRepository.Create(p);
            CurrentSession.Flush();

            Assert.That(productRepository.Search(null, null).Count(), Is.EqualTo(countOfAllowedProductsBeforeAddingNewProduct + 1));
        }
Beispiel #2
0
 public virtual bool Equals(Product other)
 {
     if (ReferenceEquals(null, other)) return false;
     if (ReferenceEquals(this, other)) return true;
     if (ProductId != default(int))
     {
         return other.ProductId == ProductId;
     }
     return other.ProductId == ProductId && other.ProductName == ProductName && other.QuantityPerUnit == QuantityPerUnit && other.UnitPrice == UnitPrice && other.UnitsInStock == UnitsInStock && other.UnitsOnOrder == UnitsOnOrder && other.ReorderLevel == ReorderLevel && other.Discontinued == Discontinued && other.Category == Category && other.Supplier == Supplier;
 }