public async Task GroupsWorkflow_ValidRequest_GetGroups()
{
// Get all groups and one individual group
var allGroupsInit = await _client.GroupsManager.GetAllGroupsAsync();
var oneGroup = await _client.GroupsManager.GetGroupAsync(allGroupsInit.Entries[0].Id);
Assert.AreEqual(allGroupsInit.Entries[0].Name, oneGroup.Name, "Did not retrieve the correct group");
// Create a new group
string groupName = GetUniqueName();
BoxGroupRequest groupReq = new BoxGroupRequest()
{
Name = groupName,
};
var newGroup = await _client.GroupsManager.CreateAsync(groupReq);
var allGroupsAfterAdd = await _client.GroupsManager.GetAllGroupsAsync(limit:3, autoPaginate:true);
Assert.AreEqual(newGroup.Name, groupName, "New group does not have correct name");
Assert.AreEqual(allGroupsInit.TotalCount + 1, allGroupsAfterAdd.TotalCount, "Number of groups after add is not correct");
//Update the name of an existing group
string updatedName = GetUniqueName();
Assert.IsFalse(allGroupsInit.Entries.Any<BoxGroup>(x => x.Name.Equals(updatedName)), "A group with updatedName already exists");
BoxGroupRequest updateRequest = new BoxGroupRequest()
{
Name = updatedName
};
var updatedGroup = await _client.GroupsManager.UpdateAsync(newGroup.Id, updateRequest);
var allGroupsAfterUpdate = await _client.GroupsManager.GetAllGroupsAsync();
Assert.AreEqual(updatedGroup.Name, updatedName, "The group name was not updated correctly");
Assert.AreEqual(1, allGroupsAfterUpdate.Entries.Count(x => x.Name.Equals(updatedName)), "The updated group name does not exist among all groups");
Assert.IsFalse(allGroupsAfterUpdate.Entries.Any<BoxGroup>(x => x.Name.Equals(groupName)), "The old group name still exists among all groups");
// Delete a group
var delResult = await _client.GroupsManager.DeleteAsync(newGroup.Id);
var allGroupsAfterDelete = await _client.GroupsManager.GetAllGroupsAsync();
Assert.IsTrue(delResult, "Group was not deleted successfully");
Assert.AreEqual(allGroupsInit.TotalCount, allGroupsAfterDelete.TotalCount, "Number of groups after delete is not correct");
Assert.IsFalse(allGroupsAfterDelete.Entries.Any<BoxGroup>(x => x.Id == newGroup.Id), "Deleted group still exists");
}