public async Task CreateGroupAsyncReturnsNewGroupIfSuccessful()
        {
            _groupRepositoryMock.Setup(m => m.CreateItemAsync(It.IsAny <Group>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(new Group()));

            _groupRepositoryMock.SetupCreateItemQuery(o => new List <Group>());

            var newGroupRequest = new Group();
            var tenantId        = Guid.NewGuid();
            var userId          = Guid.NewGuid();
            var result          = await _controller.CreateGroupAsync(newGroupRequest, tenantId, userId);

            Assert.IsType <Group>(result);
        }
Пример #2
0
        private async Task <object> CreateGroupAsync(dynamic input, CancellationToken cancellationToken)
        {
            Group newGroup;

            try
            {
                newGroup = this.Bind <Group>();
            }
            catch (Exception ex)
            {
                Logger.Error("Binding failed while attempting to create a Group resource", ex);
                return(Response.BadRequestBindingException());
            }

            await RequiresAccess()
            .WithTenantIdExpansion(ctx => TenantId)
            .ExecuteAsync(cancellationToken);

            try
            {
                // Force the group type to Custom because you can't create a built-in group using
                // this route.
                newGroup.Type = GroupType.Custom;

                var result = await _groupsController.CreateGroupAsync(newGroup, TenantId, PrincipalId, cancellationToken);

                return(Negotiate
                       .WithModel(result)
                       .WithStatusCode(HttpStatusCode.Created));
            }
            catch (ValidationFailedException ex)
            {
                return(Response.BadRequestValidationFailed(ex.Errors));
            }
            catch (Exception ex)
            {
                Logger.Error("Failed to create group resource due to an error", ex);
                return(Response.InternalServerError(ResponseReasons.InternalServerErrorCreateUser));
            }
        }