示例#1
0
        public async Task SaveUser_WithUserNotInRepository_ShouldCreateUser()
        {
            var command = new UserResourceBuilder()
                          .WithDefaultValues()
                          .Build();

            var content = new StringContent(JsonSerializer.Serialize(command), Encoding.UTF8, "application/json");

            var client = GetClient();

            var createResponse = await client.PostAsync("api/users/save", content);

            createResponse.StatusCode.Should().Be(HttpStatusCode.OK);

            var createdUserContent = await createResponse.Content.ReadAsStringAsync();

            var userResource = Newtonsoft.Json.JsonConvert.DeserializeObject <UserResource>(createdUserContent);

            userResource.Should().NotBeNull();
            userResource.CreatedById.Should().Be(command.CreatedById);
            userResource.CreatedOn.Should().Be(command.CreatedOn);
            userResource.Email.Should().Be(command.Email);
            userResource.FirebaseId.Should().Be(command.FirebaseId);
            userResource.Id.Should().BeGreaterThan(0);
            userResource.LastModifiedById.Should().Be(command.LastModifiedById);
            userResource.LastModifiedOn.Should().Be(command.LastModifiedOn);
            userResource.Name.Should().Be(command.Name);
            userResource.PhotoUrl.Should().Be(command.PhotoUrl);
        }
示例#2
0
        public async Task SaveUser_WithEmptyPhotoUrl_ShouldReturnBadRequest()
        {
            var command = new UserResourceBuilder()
                          .WithDefaultValues()
                          .WithPhotoUrl(string.Empty)
                          .Build();

            var content = new StringContent(JsonSerializer.Serialize(command), Encoding.UTF8, "application/json");

            var client = GetClient();

            var createResponse = await client.PostAsync("api/users/save", content);

            createResponse.StatusCode.Should().Be(HttpStatusCode.BadRequest);

            var createResponseContent = await createResponse.Content.ReadAsStringAsync();

            createResponseContent.Should().Contain("PhotoUrl cannot be null or empty");
        }