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


C# StateManager.GetNextAvailableStates方法代码示例

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


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

示例1: GetNextAvailableStatesWithMultiPersonFieldSecurity

        public void GetNextAvailableStatesWithMultiPersonFieldSecurity()
        {
            var personIds = new Dictionary<string, int>();
            personIds[Constants.BasePersonProcessName] = 111;
            personIds["Employee"] = 222;

            var identity = Mock.Create<IMQ1Identity>();
            Mock.Arrange(() => identity.IsAdmin).Returns(false);
            Mock.Arrange(() => identity.IsAuthenticated).Returns(true);
            Mock.Arrange(() => identity.PersonId).Returns(111);
            Mock.Arrange(() => identity.PersonIds).Returns(personIds);
            Mock.Arrange(() => identity.BusinessUnitId).Returns(10);
            Mock.Arrange(() => identity.RolesId).Returns(new List<int> { 1, 2 });

            var principal = Mock.Create<IPrincipal>();

            Mock.Arrange(() => principal.Identity).Returns(identity);

            Csla.ApplicationContext.User = principal;

            var currentState = Mock.Create<IState>();
            Mock.Arrange(() => currentState.Id).Returns(100);

            var state1 = Mock.Create<IState>();
            Mock.Arrange(() => state1.Id).Returns(1);
            Mock.Arrange(() => state1.Guid).Returns(Guid.NewGuid);

            var state2 = Mock.Create<IState>();
            Mock.Arrange(() => state2.Id).Returns(2);
            Mock.Arrange(() => state2.Guid).Returns(Guid.NewGuid);

            // Approvers can move from CurrentState to State1.
            var connector1 = Mock.Create<IStateConnector>();
            Mock.Arrange(() => connector1.ConnectedTo).Returns(state1);
            var sc1 = Mock.Create<IStateConnectorSecurityConfiguration>();
            Mock.Arrange(() => sc1.BusinessUnitId).Returns(Constants.AllBusinessUnitsId);
            Mock.Arrange(() => sc1.RoleId).Returns(Constants.AllRolesId);
            Mock.Arrange(() => sc1.PersonFieldName).Returns("Approvers");
            Mock.Arrange(() => sc1.CanMove).Returns(true);
            Mock.Arrange(() => connector1.SecurityConfigurations).Returns(new[] { sc1 });

            // Employees can move from CurrentState to State2.
            var connector2 = Mock.Create<IStateConnector>();
            Mock.Arrange(() => connector2.ConnectedTo).Returns(state2);
            var sc2 = Mock.Create<IStateConnectorSecurityConfiguration>();
            Mock.Arrange(() => sc2.BusinessUnitId).Returns(Constants.AllBusinessUnitsId);
            Mock.Arrange(() => sc2.RoleId).Returns(Constants.AllRolesId);
            Mock.Arrange(() => sc2.PersonFieldName).Returns("Employees");
            Mock.Arrange(() => sc2.CanMove).Returns(true);
            Mock.Arrange(() => connector2.SecurityConfigurations).Returns(new[] { sc2 });

            Mock.Arrange(() => currentState.Connectors).Returns(new[] { connector1, connector2 });

            var approver = Mock.Create<ICrossRefItemInfo>();
            Mock.Arrange(() => approver.Id).Returns(111);
            var approvers = new List<ICrossRefItemInfo> { approver };

            var employee = Mock.Create<ICrossRefItemInfo>();
            Mock.Arrange(() => employee.Id).Returns(222);
            var employees = new List<ICrossRefItemInfo> { employee };

            var item = new ItemWithPersonFields { CurrentState = 100, Approvers = approvers, Employees = employees };

            var stateManager = new StateManager();

            stateManager.States.Add(currentState);
            stateManager.States.Add(state1);
            stateManager.States.Add(state2);

            var nextStates = stateManager.GetNextAvailableStates(item);

            Assert.AreEqual(2, nextStates.Length);
            Assert.IsTrue(nextStates.Contains(state1));
            Assert.IsTrue(nextStates.Contains(state2));

            approvers.Clear();
            employees.Clear();
            nextStates = stateManager.GetNextAvailableStates(item);
            Assert.AreEqual(0, nextStates.Length);
        }
开发者ID:mparsin,项目名称:Elements,代码行数:80,代码来源:StateManagerTests.cs

示例2: GetNextAvailableStatesWithPersonFieldSecurity

        public void GetNextAvailableStatesWithPersonFieldSecurity()
        {
            var personIds = new Dictionary<string, int>();
            personIds[Constants.BasePersonProcessName] = 111;
            personIds["Employee"] = 222;

            var identity = Mock.Create<IMQ1Identity>();
            Mock.Arrange(() => identity.IsAdmin).Returns(false);
            Mock.Arrange(() => identity.IsAuthenticated).Returns(true);
            Mock.Arrange(() => identity.PersonId).Returns(111);
            Mock.Arrange(() => identity.PersonIds).Returns(personIds);
            Mock.Arrange(() => identity.BusinessUnitId).Returns(10);
            Mock.Arrange(() => identity.RolesId).Returns(new List<int> { 1, 2 });

            var principal = Mock.Create<IPrincipal>();

            Mock.Arrange(() => principal.Identity).Returns(identity);

            Csla.ApplicationContext.User = principal;

            var state1 = Mock.Create<IState>();
            Mock.Arrange(() => state1.Id).Returns(1);
            
            var state2 = Mock.Create<IState>();
            Mock.Arrange(() => state2.Id).Returns(2);

            var securityConfig = Mock.Create<IStateConnectorSecurityConfiguration>();
            Mock.Arrange(() => securityConfig.BusinessUnitId).Returns(Constants.AllBusinessUnitsId);
            Mock.Arrange(() => securityConfig.RoleId).Returns(Constants.AllRolesId);
            Mock.Arrange(() => securityConfig.PersonFieldName).Returns("Manager");
            Mock.Arrange(() => securityConfig.CanMove).Returns(true);

            var connector = Mock.Create<IStateConnector>();
            Mock.Arrange(() => connector.ConnectedTo).Returns(state2);
            Mock.Arrange(() => connector.SecurityConfigurations).Returns(new[] { securityConfig });

            Mock.Arrange(() => state1.Connectors).Returns(new[] { connector });

            var stateManager = new StateManager();

            stateManager.States.Add(state1);
            stateManager.States.Add(state2);

            var item = new ItemWithPersonFields { CurrentState = 1, Manager = 222 };

            var nextStates = stateManager.GetNextAvailableStates(item);

            Assert.AreEqual(1, nextStates.Length);
            Assert.AreSame(state2, nextStates[0]);

            item.Manager = 333;
            nextStates = stateManager.GetNextAvailableStates(item);

            Assert.AreEqual(0, nextStates.Length);
        }
开发者ID:mparsin,项目名称:Elements,代码行数:55,代码来源:StateManagerTests.cs


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