当前位置: 首页>>代码示例>>C#>>正文


C# RhetosTestContainer.AddIgnoreClaims方法代码示例

本文整理汇总了C#中RhetosTestContainer.AddIgnoreClaims方法的典型用法代码示例。如果您正苦于以下问题:C# RhetosTestContainer.AddIgnoreClaims方法的具体用法?C# RhetosTestContainer.AddIgnoreClaims怎么用?C# RhetosTestContainer.AddIgnoreClaims使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RhetosTestContainer的用法示例。


在下文中一共展示了RhetosTestContainer.AddIgnoreClaims方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CombiningMultipleRules

        public void CombiningMultipleRules()
        {
            InsertCurrentPrincipal(); // Not related to row permissions.

            // Insert the test data (server code bypasses row permissions):

            using (var container = new RhetosTestContainer(commitChanges: true))
            {
                var repository = container.Resolve<Common.DomRepository>();
                var context = container.Resolve<Common.ExecutionContext>();
                repository.DemoRowPermissions2.DocumentApproval.Delete(repository.DemoRowPermissions2.DocumentApproval.All());
                repository.DemoRowPermissions2.DocumentComment.Delete(repository.DemoRowPermissions2.DocumentComment.All());
                repository.DemoRowPermissions2.Document.Delete(repository.DemoRowPermissions2.Document.All());
                repository.DemoRowPermissions2.RegionSupervisor.Delete(repository.DemoRowPermissions2.RegionSupervisor.All());
                repository.DemoRowPermissions2.Employee.Delete(repository.DemoRowPermissions2.Employee.All());
                repository.DemoRowPermissions2.Division.Delete(repository.DemoRowPermissions2.Division.All());
                repository.DemoRowPermissions2.Region.Delete(repository.DemoRowPermissions2.Region.All());

                var reg3 = new DemoRowPermissions2.Region { Name = "reg3" };
                repository.DemoRowPermissions2.Region.Insert(new[] { reg3 });

                var div1 = new DemoRowPermissions2.Division { Name = "div1" };
                var div2 = new DemoRowPermissions2.Division { Name = "div2" };
                var div3 = new DemoRowPermissions2.Division { Name = "div3", RegionID = reg3.ID };
                repository.DemoRowPermissions2.Division.Insert(new[] { div1, div2, div3 });

                // The current user:
                var emp1 = new DemoRowPermissions2.Employee
                {
                    UserName = context.UserInfo.UserName,
                    DivisionID = div1.ID
                };
                repository.DemoRowPermissions2.Employee.Insert(new[] { emp1 });

                var sup3 = new DemoRowPermissions2.RegionSupervisor
                {
                    EmployeeID = emp1.ID,
                    RegionID = reg3.ID
                };
                repository.DemoRowPermissions2.RegionSupervisor.Insert(new[] { sup3 });

                // The user can access doc1, because it's in the same division:
                var doc1 = new DemoRowPermissions2.Document { Title = "doc1", DivisionID = div1.ID };
                // The user cannot access doc2:
                var doc2 = new DemoRowPermissions2.Document { Title = "doc2", DivisionID = div2.ID };
                // The user can access doc3, because it's in the region he supervises:
                var doc3 = new DemoRowPermissions2.Document { Title = "doc3", DivisionID = div3.ID };
                // The user can access doc4 (same division), but cannot edit it (previous year):
                var doc4 = new DemoRowPermissions2.Document { Title = "doc4", DivisionID = div1.ID, Created = DateTime.Now.AddYears(-1) };
                repository.DemoRowPermissions2.Document.Insert(new[] { doc1, doc2, doc3, doc4 });
            }

            // Simulate client request: Reading all documents (access denied)

            using (var container = new RhetosTestContainer())
            {
                container.AddIgnoreClaims();
                var processingEngine = container.Resolve<IProcessingEngine>();
                var serverCommand = new ReadCommandInfo
                {
                    DataSource = typeof(DemoRowPermissions2.Document).FullName,
                    ReadRecords = true
                };
                var serverResponse = processingEngine.Execute(new[] { serverCommand });
                var report = GenerateReport(serverResponse);
                Console.WriteLine("Server response: " + report);
                Assert.IsTrue(report.Contains("You are not authorized"));
            }

            // Simulate client request: Reading the user's documents

            using (var container = new RhetosTestContainer())
            {
                container.AddIgnoreClaims();
                var processingEngine = container.Resolve<IProcessingEngine>();
                var serverCommand = new ReadCommandInfo
                {
                    DataSource = typeof(DemoRowPermissions2.Document).FullName,
                    ReadRecords = true,
                    Filters = new[] { new FilterCriteria(typeof(Common.RowPermissionsReadItems)) }
                };
                var serverResponse = processingEngine.Execute(new[] { serverCommand });
                var report = GenerateReport(serverResponse);
                Console.WriteLine("Server response: " + report);
                Assert.AreEqual("doc1, doc3, doc4", report);
            }

            // Simulate client request: Edit doc1 (ok)

            using (var container = new RhetosTestContainer())
            {
                container.AddIgnoreClaims();
                var repository = container.Resolve<Common.DomRepository>();
                var doc1 = repository.DemoRowPermissions2.Document.Query().Where(d => d.Title == "doc1").Single();
                doc1.Title += "x";

                var processingEngine = container.Resolve<IProcessingEngine>();
                var serverCommand = new SaveEntityCommandInfo
                {
                    Entity = typeof(DemoRowPermissions2.Document).FullName,
//.........这里部分代码省略.........
开发者ID:tjakopovic,项目名称:Rhetos,代码行数:101,代码来源:RowPermissionsDemo.cs

示例2: SimpleRowPermissionRules

        public void SimpleRowPermissionRules()
        {
            InsertCurrentPrincipal(); // Not related to row permissions.

            // Insert the test data (server code bypasses row permissions):

            using (var container = new RhetosTestContainer(commitChanges: true))
            {
                var repository = container.Resolve<Common.DomRepository>();
                var context = container.Resolve<Common.ExecutionContext>();
                repository.DemoRowPermissions1.Document.Delete(repository.DemoRowPermissions1.Document.All());
                repository.DemoRowPermissions1.Employee.Delete(repository.DemoRowPermissions1.Employee.All());
                repository.DemoRowPermissions1.Division.Delete(repository.DemoRowPermissions1.Division.All());

                var div1 = new DemoRowPermissions1.Division { Name = "div1" };
                var div2 = new DemoRowPermissions1.Division { Name = "div2" };
                repository.DemoRowPermissions1.Division.Insert(new[] { div1, div2 });

                // The current user:
                var emp1 = new DemoRowPermissions1.Employee
                {
                    UserName = context.UserInfo.UserName,
                    DivisionID = div1.ID
                };
                repository.DemoRowPermissions1.Employee.Insert(new[] { emp1 });

                // The user can access doc1, because it's in the same division:
                var doc1 = new DemoRowPermissions1.Document { Title = "doc1", DivisionID = div1.ID };
                // The user cannot access doc2:
                var doc2 = new DemoRowPermissions1.Document { Title = "doc2", DivisionID = div2.ID };
                repository.DemoRowPermissions1.Document.Insert(new[] { doc1, doc2 });
            }

            // Simulate client request: Reading all documents (access denied)

            using (var container = new RhetosTestContainer())
            {
                container.AddIgnoreClaims();
                var processingEngine = container.Resolve<IProcessingEngine>();
                var serverCommand = new ReadCommandInfo
                {
                    DataSource = typeof(DemoRowPermissions1.Document).FullName,
                    ReadRecords = true
                };
                var serverResponse = processingEngine.Execute(new[] { serverCommand });
                var report = GenerateReport(serverResponse);
                Console.WriteLine("Server response: " + report);
                Assert.IsTrue(report.Contains("You are not authorized"));
            }

            // Simulate client request: Reading the user's documents

            using (var container = new RhetosTestContainer())
            {
                container.AddIgnoreClaims();
                var processingEngine = container.Resolve<IProcessingEngine>();
                var serverCommand = new ReadCommandInfo
                {
                    DataSource = typeof(DemoRowPermissions1.Document).FullName,
                    ReadRecords = true,
                    Filters = new[] { new FilterCriteria(typeof(Common.RowPermissionsReadItems)) }
                };
                var serverResponse = processingEngine.Execute(new[] { serverCommand });
                var report = GenerateReport(serverResponse);
                Console.WriteLine("Server response: " + report);
                Assert.AreEqual("doc1", report);
            }
        }
开发者ID:tjakopovic,项目名称:Rhetos,代码行数:68,代码来源:RowPermissionsDemo.cs

示例3: ProcessingEngineUniqueConstraintError

 public void ProcessingEngineUniqueConstraintError()
 {
     using (var container = new RhetosTestContainer())
     {
         container.AddIgnoreClaims();
         var processingEngine = container.Resolve<IProcessingEngine>();
         var saveDuplicates = new SaveEntityCommandInfo
         {
             Entity = "TestUnique.E",
             DataToInsert = new[]
             {
                 new TestUnique.E { I = 123, S = "abc" },
                 new TestUnique.E { I = 123, S = "abc" },
             }
         };
         var processingEngineResult = processingEngine.Execute(new[] { saveDuplicates });
         Assert.IsFalse(processingEngineResult.Success);
         TestUtility.AssertContains(processingEngineResult.UserMessage, "duplicate");
     }
 }
开发者ID:tjakopovic,项目名称:Rhetos,代码行数:20,代码来源:UniqueTest.cs


注:本文中的RhetosTestContainer.AddIgnoreClaims方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。