Skip to content

Conversation

@victormarante
Copy link

Add description for optional parameters. If the property type has a default value of null, throw an error saying description is required.

@ModernRonin
Copy link
Owner

got a test failing, see the CI build

@ModernRonin
Copy link
Owner

also, please write tests for the new behaviors.

@victormarante
Copy link
Author

I have added some tests. As for the failing test, Can_make_nullable_properties_optional_and_have_null_as_default, we either have to skip or modify this test now. This test checks if nullable properties with default values are allowed (which is fine), but if that is the case, a description is required.

How do we wish to handle this?

@ModernRonin
Copy link
Owner

it seems there are still tests failing?

@ModernRonin
Copy link
Owner

the one you mention, Can_make_nullable_properties_optional_and_have_null_as_default, adjust it to the new behavior (that the description is required).

@ModernRonin
Copy link
Owner

(also sorry for my being not very much here lately, but I have both stress at work and one of my two cats is in the final stages of renal dysfunction, I just wrote an email to the vet asking whether she thinks it's time to put him to sleep)

Copy link
Owner

@ModernRonin ModernRonin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed this now, please check the comments. And there are more tests that fail than just the one you mentioned (and for that one I wrote a reply, see the PR discussion)

else
{
result.RightLines.Add($"Default: {opt.Default}");
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be simplified to result.RightLines.Add(opt.Default is null ? opt.Description : $"Default: {opt.Default}"

{
throw new InvalidOperationException(
$"Default are only settable for optional parameters - maybe you forgot a call to {nameof(MakeOptional)}?");
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be good to have a test for the throw branch, too

public void Description_Should_Not_Have_Error_When_Description_Empty_For_Value_Type() =>
new OptionalParameterValidator()
.TestValidate(new OptionalParameter { Type = typeof(int) })
.ShouldHaveValidationErrorFor(p => p.Description);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't it be .ShouldNotHaveValidationErrors() or some such in this test-case?

@victormarante
Copy link
Author

I reviewed this now, please check the comments. And there are more tests that fail than just the one you mentioned (and for that one I wrote a reply, see the PR discussion)

Hi. I will try to look at this as soon as possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants