public static ProcessEdit CreatProcessWithBaseProcess(int id, IEnumerable<FieldEdit> fields) { var process = new ProcessEditMock(id); var processEditExtensionsMock = Mock.Create<ProcessEditExtensions>(); process.ProcessEditExtensions = processEditExtensionsMock; var baseProcess = new ProcessEditMock(12, "Base Person", "BasePerson_p"); processEditExtensionsMock = Mock.Create<ProcessEditExtensions>(); baseProcess.ProcessEditExtensions = processEditExtensionsMock; var section = new SectionEditMock(1, "Test section"); process.BaseProcess = baseProcess; process.BaseProcess.SectionList.Add(section); process.SectionList.Add(section); foreach (var field in fields) { process.BaseProcess.SectionList[0].FieldList.Add(field); process.SectionList[0].FieldList.Add(field); } return process; }
public static ProcessEdit CreateProcess(int id, IEnumerable<FieldEdit> fields) { var process = new ProcessEditMock(id); var section = new SectionEditMock(1, "Test section"); var processEditExtensionsMock = Mock.Create<ProcessEditExtensions>(); process.ProcessEditExtensions = processEditExtensionsMock; process.SectionList.Add(section); foreach (var field in fields) process.SectionList[0].FieldList.Add(field); return process; }
public void PopulateSecurityConfigurations() { var catalog = new TypeCatalog(); var container = new CompositionContainer(catalog, false); var expressionServiceBase = Mock.Create<IExpressionServiceBase>(Behavior.Loose); container.ComposeExportedValue(expressionServiceBase); Ioc.InjectContainer(container); var vm = new ProcessCommandsViewModel(); var process = new ProcessEditMock(); var processEditExtensionsMock = Mock.Create<ProcessEditExtensions>(Behavior.Loose); process.ProcessEditExtensions = processEditExtensionsMock; vm.Model = process; process.ProcessOptionChoose = ProcessOption.VersionEnabled; Assert.AreEqual(1, vm.Model.CommandList.Count); var collectionUtilities = Mock.Create<ICollectionUtilities>(Behavior.Loose); Mock.Arrange(() => collectionUtilities.SortStatesInfoWithAll(Arg.IsAny<IEnumerable<StateEdit>>())).Returns<IEnumerable<StateEdit>>( list => { var result = new ObservableCollection<StateInfo>(list.Select(s => new StateInfo { Name = s.Name, Guid = s.Guid })); if (result.All(x => x.Guid != Constants.AllStatesGuid)) result.Insert(0, new StateInfo { Guid = Constants.AllStatesGuid, Name = Constants.AllStatesName }); return result; }); vm.CollectionUtilities = collectionUtilities; vm.Roles = new ObservableCollection<RoleInfo>( new[] { new RoleInfo { Id = Constants.AllRolesId, Name = Constants.AllRolesName }, new RoleInfo { Id = 1, Name = "Role 1" }, new RoleInfo { Id = 2, Name = "Role 2" } }); vm.BusinessUnits = new ObservableCollection<BusinessUnitInfo>( new[] { new BusinessUnitInfo { Id = Constants.AllBusinessUnitsId, Name = Constants.AllBusinessUnitsName }, new BusinessUnitInfo { Id = 1, Name = "BU 1" }, new BusinessUnitInfo { Id = 2, Name = "BU 2" } }); vm.SelectedCommand = vm.Model.CommandList.First(); vm.SecurityConfigurationList.Add(ProcessCommandSecurityConfigurationEdit.NewProcessCommandSecurityConfigurationEdit()); vm.OnRefreshed(); Assert.AreEqual(1, vm.Model.CommandList[0].SecurityConfigurationList.Count); //default description Assert.AreEqual(1, vm.Model.CommandList[0].SecurityConfigurationList.Count); var configuration = vm.Model.CommandList[0].SecurityConfigurationList[0]; Assert.IsTrue(configuration.BusinessUnitName.Equals(Constants.AllBusinessUnitsName) && configuration.RoleName.Equals(Constants.AllRolesName)); configuration = vm.Model.CommandList[0].SecurityConfigurationList[0]; vm.SelectedSecurityConfiguration = configuration; vm.SelectedRoleId = 1; vm.SelectedBusinessUnitId = 2; //first configuration Assert.AreEqual(1, vm.Model.CommandList[0].SecurityConfigurationList.Count); Assert.IsTrue(vm.RoleName.Equals("Role 1") && vm.BusinessUnitName.Equals("BU 2")); vm.SecurityConfigurationList.Add(ProcessCommandSecurityConfigurationEdit.NewProcessCommandSecurityConfigurationEdit()); configuration = vm.Model.CommandList[0].SecurityConfigurationList[1]; vm.SelectedSecurityConfiguration = configuration; vm.SelectedRoleId = 2; vm.SelectedBusinessUnitId = 1; //second configuration Assert.AreEqual(2, vm.Model.CommandList[0].SecurityConfigurationList.Count); Assert.IsTrue(vm.RoleName.Equals("Role 2") && vm.BusinessUnitName.Equals("BU 1")); Ioc.InjectContainer(null); }
public void AfterBaseBusinessUnitAndBaseRoleChanged_SecurityConfigurationNamesChanges() { var catalog = new TypeCatalog(); var container = new CompositionContainer(catalog, false); var expressionServiceBase = Mock.Create<IExpressionServiceBase>(Behavior.Loose); container.ComposeExportedValue(expressionServiceBase); Ioc.InjectContainer(container); #region Arrange const string BusinessUnitName = "Unit1"; const string RoleName = "Role1"; const int RoleId = 1; const int BusinessUnitId = 1; var process = new ProcessEditMock(); var processEditExtensionsMock = Mock.Create<ProcessEditExtensions>(); process.ProcessEditExtensions = processEditExtensionsMock; var roleMock = Mock.Create<IRoleInfo>(); Mock.Arrange(() => roleMock.Id).Returns(RoleId); Mock.Arrange(() => roleMock.Name).Returns(RoleName); var businessUnitMock = Mock.Create<IBusinessUnitInfo>(); Mock.Arrange(() => businessUnitMock.Id).Returns(BusinessUnitId); Mock.Arrange(() => businessUnitMock.Name).Returns(BusinessUnitName); var collectionUtilities = Mock.Create<ICollectionUtilities>(); Mock.Arrange(() => collectionUtilities.SortStatesInfoWithAll(Arg.IsAny<IEnumerable<StateEdit>>())).Returns<IEnumerable<StateEdit>>( list => { var result = new ObservableCollection<StateInfo>(); result.Insert(0, new StateInfo { Guid = Constants.AllStatesGuid, Name = Constants.AllStatesName }); return result; }); Mock.Arrange(() => collectionUtilities.SortBusinessUnitsWithAll(Arg.IsAny<IEnumerable<IBusinessUnitInfo>>())).Returns<IEnumerable<IBusinessUnitInfo>>( list => { var result = new ObservableCollection<BusinessUnitInfo>(list.Select(b => new BusinessUnitInfo { Name = b.Name, Id = b.Id })); return result; }); Mock.Arrange(() => collectionUtilities.SortRolesWithAll(Arg.IsAny<IEnumerable<IRoleInfo>>())).Returns<IEnumerable<IRoleInfo>>( list => { var result = new ObservableCollection<RoleInfo>(list.Select(r => new RoleInfo { Name = r.Name, Id = r.Id })); return result; }); var vm = new ProcessCommandsViewModel(); vm.Model = process; vm.CollectionUtilities = collectionUtilities; var organizationInfoMock = Mock.Create<IOrganizationInfo>(); Mock.Arrange(() => organizationInfoMock.Roles).Returns(new List<IRoleInfo>() { roleMock }); Mock.Arrange(() => organizationInfoMock.BusinessUnits).Returns(new List<IBusinessUnitInfo> { businessUnitMock }); vm.OrganizationInfo = organizationInfoMock; vm.Model.CommandList.Add(ProcessCommandEdit.NewProcessCommandEdit()); vm.Model.CommandList[0].SecurityConfigurationList.Add(RoleId, BusinessUnitId, Constants.AllStatesGuid, null, null, null, Constants.AllPersonFieldsName, null); #endregion Arrange //Act vm.OnRefreshed(); //Assert Assert.AreEqual(vm.Model.CommandList[0].SecurityConfigurationList[0].BusinessUnitName, BusinessUnitName); Assert.AreEqual(vm.Model.CommandList[0].SecurityConfigurationList[0].RoleName, RoleName); //Arrange Mock.Arrange(() => collectionUtilities.SortBusinessUnitsWithAll(Arg.IsAny<IEnumerable<IBusinessUnitInfo>>())).Returns<IEnumerable<IBusinessUnitInfo>>(list => new ObservableCollection<BusinessUnitInfo>()); Mock.Arrange(() => collectionUtilities.SortRolesWithAll(Arg.IsAny<IEnumerable<IRoleInfo>>())).Returns<IEnumerable<IRoleInfo>>(list => new ObservableCollection<RoleInfo>()); //Act: role and businessUnit are removed vm.OnRefreshed(); //Assert Assert.AreEqual(vm.Model.CommandList[0].SecurityConfigurationList[0].BusinessUnitName, Constants.Unknown); Assert.AreEqual(vm.Model.CommandList[0].SecurityConfigurationList[0].RoleName, Constants.Unknown); Ioc.InjectContainer(null); }
public void WhenProcessStatesIsChanged_ProcessCommandTabStatesUpdated() { var catalog = new TypeCatalog(); var container = new CompositionContainer(catalog, false); var expressionServiceBase = Mock.Create<IExpressionServiceBase>(Behavior.Loose); container.ComposeExportedValue(expressionServiceBase); Ioc.InjectContainer(container); var vm = new ProcessCommandsViewModel(); var process = new ProcessEditMock(); var processEditExtensionsMock = Mock.Create<ProcessEditExtensions>(); process.ProcessEditExtensions = processEditExtensionsMock; vm.Model = process; var collectionUtilities = Mock.Create<ICollectionUtilities>(); Mock.Arrange(() => collectionUtilities.SortStatesInfoWithAll(Arg.IsAny<IEnumerable<StateEdit>>())).Returns<IEnumerable<StateEdit>>( list => { var result = new ObservableCollection<StateInfo>(list.Select(s => new StateInfo { Name = s.Name, Guid = s.Guid })); if (result.All(x => x.Guid != Constants.AllStatesGuid)) result.Insert(0, new StateInfo { Guid = Constants.AllStatesGuid, Name = Constants.AllStatesName }); return result; }); vm.CollectionUtilities = collectionUtilities; process.ProcessOptionChoose = ProcessOption.VersionEnabled; Assert.AreEqual(1, vm.Model.CommandList.Count); var statesBeforechanges = vm.StateInfoList.Count; ((BindingList<StateEdit>)process.StateList).AddNew(); Assert.AreEqual(statesBeforechanges + 1, vm.StateInfoList.Count); Ioc.InjectContainer(null); }
public void PermissionRemoveCommandTests() { // Arrange. const int roleId = 147; const int businessUnitId = 111; var permission = new ProcessSecurityConfigurationEditMock(roleId, businessUnitId, true, false); var model = new ProcessEditMock(1); var processEditExtensionsMock = Mock.Create<ProcessEditExtensions>(); model.ProcessEditExtensions = processEditExtensionsMock; model.SecurityConfigurationList.Add(permission); this._target.Model = model; this._target.OnRefreshed(); // Act. this._target.SelectedPermission = null; // Assert. Assert.IsFalse(this._target.PermissionRemoveCommand.CanExecute(null)); // Act. this._target.SelectedPermission = new ProcessSecurityViewModel.PersmissionGroupViewModel { Model = permission }; // Assert. Assert.IsTrue(this._target.PermissionRemoveCommand.CanExecute(null)); // Arrange. var propertiesChanged = new List<string>(); this._target.PropertyChanged += (o, e) => propertiesChanged.Add(e.PropertyName); // Act. this._target.PermissionRemoveCommand.Execute(null); // Assert. Assert.IsFalse(this._target.Model.SecurityConfigurationList.Contains(permission)); Assert.IsNull(this._target.SelectedPermission); }