public async Task <CreateUserResponse> Create(UserDtoBuilder userDto)
        {
            var createJohnnyResponse = await TryToCreate(userDto);

            createJohnnyResponse.ShouldIndicateSuccessfulCreationOf(userDto);
            return(createJohnnyResponse);
        }
        public async Task <GetUserResponse> Get(UserDtoBuilder user)
        {
            var getJohnnyResponse = await TryToGet(user);

            getJohnnyResponse.ShouldIndicateSuccess();
            return(getJohnnyResponse);
        }
示例#3
0
        public UserListResponse GetUsers(string term)
        {
            var response = new UserListResponse();
            var users    = _userRepository.GetUsers(term);

            response.Users = users.Select(x => UserDtoBuilder.ToDto(x));
            return(response);
        }
 public CreateUserResponse ShouldIndicateSuccessfulCreationOf(UserDtoBuilder johnny)
 {
     this.ShouldBe201Created();
     this.ShouldHaveLocationStartingWith(UsersApiRelativeUriRoot);
     this.ShouldHaveBodyEqualTo(johnny.Build().Login);
     this.ShouldHaveLocationWith(johnny.Build().Login);
     return(this);
 }
        public async Task <GetUserResponse> TryToGet(UserDtoBuilder user)
        {
            using (var client = _testServer.CreateClient())
            {
                var result = await client.GetAsync("api/users" + $"/{user.Build().Login}");

                return(new GetUserResponse(await result.Content.ReadAsAsync <UserDto>(), result.StatusCode));
            }
        }
 public CreateUserResponse ShouldIndicateSuccessfulCreationOf(UserDtoBuilder johnny)
 {
     using (new AssertionScope())
     {
         return(ShouldBe201Created()
                .ShouldHaveLocationStartingWith(UsersApiRelativeUriRoot)
                .ShouldHaveBodyEqualTo(johnny.Build().Login)
                .ShouldHaveLocationWith(_content));
     }
 }
        public async Task <UserDTO> GetCurrentUser()
        {
            var user = await _userManager.FindByIdAsync(_userContextProvider.GetCurrentUserId());

            var roles = await _userManager.GetRolesAsync(user);

            return(UserDtoBuilder
                   .FromApplicationUser(user)
                   .WithRoles(roles)
                   .Create());
        }
        public List <UserDTO> GetUsers()
        {
            var users = _dbContext.ApplicationUser;

            return(users.Select(user =>
                                UserDtoBuilder
                                .FromApplicationUser(user)
                                .IncludeLockoutInfo()
                                .Create())
                   .ToList());
        }
        public async Task <CreateUserResponse> TryToCreate(UserDtoBuilder userDtoBuilder)
        {
            using (var client = _testServer.CreateClient())
            {
                var response = await client.PostAsJsonAsync("api/users", userDtoBuilder.Build());

                var content = await response.Content.ReadAsStringAsync();

                return(new CreateUserResponse(content, response.StatusCode, response.Headers));
            }
        }
        public static CollectionContributorDTO FromSharedCollection(SharedCollection sharedCollection)
        {
            var user = UserDtoBuilder.FromApplicationUser(sharedCollection.User).Create();

            return(new CollectionContributorDTO
            {
                CollectionId = sharedCollection.CollectionId,
                EditRights = sharedCollection.EditRights,
                User = user,
                UserId = user.Id
            });
        }
示例#11
0
        /// <summary>
        /// Posts the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>System.Object.</returns>
        public object Post(CreateUser request)
        {
            var dtoUser = request;

            var newUser = _userManager.CreateUser(dtoUser.Name).Result;

            newUser.UpdateConfiguration(dtoUser.Configuration, _xmlSerializer);

            var dtoBuilder = new UserDtoBuilder(Logger);

            var result = dtoBuilder.GetUserDto(newUser).Result;

            return(ToOptimizedResult(result));
        }
示例#12
0
        public void ShouldDOWHAT()
        {
            //GIVEN
            var context = new ComponentDriver();

            context.Start();
            var johnny = UserDtoBuilder.AUser().Adult();

            //WHEN
            context.Create(johnny);

            //THEN
            context.ShouldReportSuccessfulCreationOf(johnny);
        }
示例#13
0
        /// <summary>
        /// Gets the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>System.Object.</returns>
        public object Get(GetUser request)
        {
            var user = _userManager.GetUserById(request.Id);

            if (user == null)
            {
                throw new ResourceNotFoundException("User not found");
            }

            var dtoBuilder = new UserDtoBuilder(Logger);

            var result = dtoBuilder.GetUserDto(user).Result;

            return(ToOptimizedResult(result));
        }
        public async System.Threading.Tasks.Task Should_CreateUser()
        {
            var context = _fixture.Context;

            var user = UserDtoBuilder.WithDefaults();

            StringContent stringContent = new StringContent(JsonConvert.SerializeObject(new { user }), Encoding.UTF8, "application/json");

            using var client = _fixture.CreateAuthenticatedClient();

            var httpResponseMessage = await client.PostAsync(Endpoints.Post.CreateUser, stringContent);

            var response = JsonConvert.DeserializeObject <CreateUser.Response>(await httpResponseMessage.Content.ReadAsStringAsync());

            var sut = context.FindAsync <User>(response.User.UserId);

            Assert.NotEqual(default, response.User.UserId);
示例#15
0
        public void ShouldDOWHAT2()
        {
            //GIVEN
            var context = new ComponentDriver();

            context.Start();
            var johnny = UserDtoBuilder.AUser().Adult();
            var kate   = UserDtoBuilder.AUser().Adult();

            context.Create(johnny);
            context.Create(kate);

            //WHEN
            var probablyJohnny = context.Get(johnny);
            var probablyKate   = context.Get(kate);

            //THEN
            probablyJohnny.ShouldBe(johnny);
            probablyKate.ShouldBe(kate);
        }
示例#16
0
        /// <summary>
        /// Gets the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>System.Object.</returns>
        public object Get(GetUsers request)
        {
            var dtoBuilder = new UserDtoBuilder(Logger);

            var users = _userManager.Users;

            if (request.IsDisabled.HasValue)
            {
                users = users.Where(i => i.Configuration.IsDisabled == request.IsDisabled.Value);
            }

            if (request.IsHidden.HasValue)
            {
                users = users.Where(i => i.Configuration.IsHidden == request.IsHidden.Value);
            }

            var tasks = users.OrderBy(u => u.Name).Select(dtoBuilder.GetUserDto).Select(i => i.Result);

            return(ToOptimizedResult(tasks.ToList()));
        }
示例#17
0
 public UserDto GetUser(Guid id)
 {
     return(UserDtoBuilder.ToDto(_userRepository.GetById(id)));
 }
 public QueriedTestUser Get(UserDtoBuilder user)
 {
     return(new QueriedTestUser(
                _root.CommandFactory().CreateGetUserByIdQuery(user.Build().Login)
                .Execute()));
 }
 public void ShouldBe(UserDtoBuilder johnny)
 {
     _returnValue.Should().BeEquivalentTo(johnny.Build());
 }
 public void ShouldBe(UserDtoBuilder johnny)
 {
     _userDto.Should().BeEquivalentTo(johnny.Build());
 }
 public void ShouldReportSuccessfulCreationOf(UserDtoBuilder johnny)
 {
     _resultBuilder.Received(1).UserAddedSuccessfully(Arg <UserDto> .That(dto => dto.Should().BeEquivalentTo(johnny.Build())));
 }
示例#22
0
 public int Add(UserDto dto)
 {
     return(_userRepository.Add(UserDtoBuilder.ToEntity(dto)));
 }
 public void Create(UserDtoBuilder johnny)
 {
     _root.CommandFactory()
     .CreateRegisterUserCommand(johnny.Build(), _resultBuilder)
     .Execute();
 }