Ejemplo n.º 1
0
    public void Valid_Model()
    {
        // Arrange
        TodoRequestModel model = TodoRequestModelBuilder.CreateValid();

        // Act
        ValidationResult result = Validator.Validate(model);

        // Assert
        _ = result.IsValid.Should().BeTrue();
    }
        public void Map_RequestModelToDto_Is_Valid()
        {
            // Arrange
            var mapper             = new TodoModelDtoMapper();
            TodoRequestModel model = TodoRequestModelBuilder.CreateValid();

            // Act
            TodoDto result = mapper.Map(model);

            // Assert
            result.Should().BeEquivalentTo(model);
            result.Id.Should().BeNull();
        }
        public async Task Update_One_NotFound()
        {
            // Arrange
            Guid todoId  = TestIds.NonUsageId;
            var  model   = TodoRequestModelBuilder.CreateValid();
            var  content = new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json");

            // Act
            var response = await _client.PutAsync(ENDPOINT_NAME + todoId, content);

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.NotFound);
        }
Ejemplo n.º 4
0
    public void Invalid_Model_Description_Null()
    {
        // Arrange
        TodoRequestModel model = TodoRequestModelBuilder.CreateValid();

        model.Description = null;

        // Act
        ValidationResult result = Validator.Validate(model);

        // Assert
        _ = result.IsValid.Should().BeFalse();
        _ = result.Errors.Should().NotBeEmpty().And.HaveCount(1);
    }
Ejemplo n.º 5
0
    public void Invalid_Model_Description_Too_Long()
    {
        // Arrange
        TodoRequestModel model = TodoRequestModelBuilder.CreateValid();

        model.Description = new string('A', 101);

        // Act
        ValidationResult result = Validator.Validate(model);

        // Assert
        _ = result.IsValid.Should().BeFalse();
        _ = result.Errors.Should().NotBeEmpty().And.HaveCount(1);
        // TODO: Check the error message too.
    }
        public void Invalid_Model_Description_Too_Long()
        {
            // Arrange
            TodoRequestModel model = TodoRequestModelBuilder.CreateValid();

            model.Description = new string('A', 101);

            // Act
            ValidationResult result = Validator.Validate(model);

            // Assert
            result.IsValid.Should().BeFalse();
            result.Errors.Should().NotBeEmpty().And.HaveCount(1);
            //result.Errors.Should().Contain(c => c.ErrorMessage.Contains("{The length of 'Description' must be 100 characters or fewer."));
        }
        public async Task Create_One_OK()
        {
            // Arrange
            var model   = TodoRequestModelBuilder.CreateValid();
            var content = new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json");

            // Act
            var response = await _client.PostAsync(ENDPOINT_NAME, content);

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

            var responseTodo = JsonConvert.DeserializeObject <TodoResponseModel>(responseBody);

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.OK);
            responseTodo.Should().NotBeNull();
            responseTodo.Id.Should().NotBeEmpty();
        }
        public async Task Update_One_OK()
        {
            // Arrange
            Guid todoId = TestIds.NormalUsageId;
            var  model  = TodoRequestModelBuilder.CreateValid();

            model.Description = "Changed description";
            model.IsDone      = true;
            var content = new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json");

            // Act
            var response = await _client.PutAsync(ENDPOINT_NAME + todoId, content);

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

            var responseTodo = JsonConvert.DeserializeObject <TodoResponseModel>(responseBody);

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.OK);
            responseTodo.Should().NotBeNull();

            responseTodo.Description.Should().Be(model.Description);
            responseTodo.IsDone.Should().Be(model.IsDone);
        }