Пример #1
0
        public async Task CreateUserTest()
        {
            var url       = "/api/users/create-user";
            var maxLength = 64;

            var client = ServerFactory.CreateHttpClient();

            var body = new CreateUserRequest
            {
                Name = "1"
            };
            var result = await client.PutAsync(url, body.GetContent());

            Assert.Equal(HttpStatusCode.BadRequest, result.StatusCode);

            body = new CreateUserRequest
            {
                Name = string.Join("", Enumerable.Range(0, maxLength + 1).Select(x => "a"))
            };
            result = await client.PutAsync(url, body.GetContent());

            Assert.Equal(HttpStatusCode.BadRequest, result.StatusCode);

            body = new CreateUserRequest
            {
                Name = string.Join("", Enumerable.Range(0, 4).Select(x => "1"))
            };
            result = await client.PutAsync(url, body.GetContent());

            Assert.Equal(HttpStatusCode.BadRequest, result.StatusCode);

            body = new CreateUserRequest
            {
                Name = "My Name",
            };
            result = await client.PutAsync(url, body.GetContent());

            result.EnsureSuccessStatusCode();
            var json = await result.Content.ReadAsStringAsync();

            var deserialize = JsonConvert.DeserializeObject <Guid>(json);

            Assert.True(deserialize != Guid.Empty);
        }