public void AddRole(Guid flowId, int version, string roleString) { // parse the role string string[] tokens = roleString.Split('&'); if (tokens.Length < 4) { throw new ArgumentException("Role string should have following format: <typenumber>&<id>&<name>&<sourcesystem>?"); } AccountData account = new AccountData { AccountType = Int32.Parse(tokens[0]), Id = new Guid(tokens[1]), Name = tokens[2], SourceSystem = tokens[3] }; _persistence.AddRoles(flowId, version, new [] { account }); }
public void TestAddRolesShouldSkipExistingRoles() { var collection = _database.GetCollection <ProcessDefinitionPersistence>(MongoProcessDefinitionPersistenceService.CollectionName); IProcessDefinitionPersisnenceService service = InstService(); AccountData[] accounts = new[] { new AccountData { AccountType = 1, Id = Guid.NewGuid(), Name = "Underwriter", SourceSystem = "ActiveDirectory" }, new AccountData { AccountType = 1, Id = Guid.NewGuid(), Name = "Modeler", SourceSystem = "ActiveDirectory" }, }; OnCreateFlowWithAssociatedSecutityAccounts(service, accounts); Assert.AreEqual(1, collection.Count(pd => true)); AccountData[] accountsToAdd = new[] { new AccountData { AccountType = 2, Id = Guid.NewGuid(), Name = "London", SourceSystem = "ActiveDirectory" }, new AccountData { AccountType = 1, Id = Guid.NewGuid(), Name = "Underwriter", SourceSystem = "ActiveDirectory" } }; IReadOnlyList <ProcessDefinitionDigest> flows = service.LisAlltWorkflows(); Assert.IsNotNull(flows); Assert.AreEqual(1, flows.Count); ProcessDefinitionDigest flow = flows.ElementAt(0); service.AddRoles(flow.Id, flow.Version, accountsToAdd); var idFilter = Builders <ProcessDefinitionPersistence> .Filter.Eq(r => r.Id, flow.Id); ProcessDefinitionPersistence persistence = collection.FindSync(idFilter).FirstOrDefault(); Assert.IsNotNull(persistence); Assert.IsNotNull(persistence.Accounts); Assert.AreEqual(3, persistence.Accounts.Count); Assert.AreEqual(1, persistence.Accounts.Count(a => a.Name == "London")); Assert.AreEqual(1, persistence.Accounts.Count(a => a.Name == "Underwriter")); Assert.AreEqual(1, persistence.Accounts.Count(a => a.Name == "Modeler")); }