public void Initialize() { var session = new Session { UserId = SessionUserId }; _sqlGroupRepositoryMock = new Mock <IGroupRepository>(); _privilegesRepository = new Mock <IPrivilegesRepository>(); _applicationSettingsRepository = new Mock <IApplicationSettingsRepository>(); _serviceLogRepository = new Mock <IServiceLogRepository>(); _itemInfoRepository = new Mock <IItemInfoRepository>(); _sendMessageExecutor = new Mock <ISendMessageExecutor>(); _sqlHelperMock = new SqlHelperMock(); _controller = new GroupsController(_sqlGroupRepositoryMock.Object, _privilegesRepository.Object, _applicationSettingsRepository.Object, _serviceLogRepository.Object, _itemInfoRepository.Object, _sendMessageExecutor.Object, _sqlHelperMock) { Request = new HttpRequestMessage(), Configuration = new HttpConfiguration() }; _controller.Request.Properties[ServiceConstants.SessionProperty] = session; _controller.Request.RequestUri = new Uri("http://localhost"); _groupsQueryDataResult = new QueryResult <GroupDto>() { Total = 1, Items = new List <GroupDto>() }; _groupsTabularPagination = new Pagination() { Limit = 1, Offset = 0 }; _groupsSorting = new Sorting() { Order = SortOrder.Asc, Sort = "Name" }; _group = new GroupDto { Name = "Group1", Email = "*****@*****.**", Source = UserGroupSource.Database, LicenseType = LicenseType.Collaborator }; _assignScope = new AssignScope { SelectAll = true, Members = new List <KeyValuePair <int, UserType> > { new KeyValuePair <int, UserType>(1, UserType.User) } }; }
public async Task AssignMembers_UserDoesNotHaveRequiredPermissions_ForbiddenResult() { // arrange var collection = new List <KeyValuePair <int, UserType> >() { new KeyValuePair <int, UserType>(1, UserType.Group) }; var scope = new AssignScope() { Members = collection.ToArray() }; _privilegesRepository .Setup(t => t.GetInstanceAdminPrivilegesAsync(SessionUserId)) .ReturnsAsync(InstanceAdminPrivileges.None); _sqlGroupRepositoryMock.Setup(repo => repo.AssignMembers(It.IsAny <int>(), It.IsAny <AssignScope>(), It.IsAny <string>())); // act await _controller.AssignMembers(_groupId, scope); // assert }