Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why NotEmpty() does not check if value for Guid type is default(Guid)? #528

Closed
pawepaw opened this issue Jul 26, 2017 · 3 comments
Closed

Comments

@pawepaw
Copy link

pawepaw commented Jul 26, 2017

Hello,

I'm a bit confused. Why NotEmpty() rule does not check if Guid argument is equal to default(Guid) and return that it's not valid?

Documentation says:
Description: Ensures that the specified property is not null, an empty string or whitespace (or the default value for value types, eg 0 for int)

Since Guid is value type it should follow that rule. Am I missing something?

@pawepaw pawepaw changed the title Why NotEmpty() does not check if Guid is default(Guid)? Why NotEmpty() does not check if value for Guid type is default(Guid)? Jul 26, 2017
@JeremySkinner
Copy link
Member

JeremySkinner commented Jul 26, 2017

NotEmpty does check if a Guid is equal to default(Guid). Is this not the behaviour you're seeing?

[Fact]
public void Guid_test() {
  var validator = new TestModel2Validator();

  var result = validator.Validate(new TestModel2 {
    SomeId = default(Guid)
  });

  Assert.False(result.IsValid);
}
public class TestModel2Validator : AbstractValidator<TestModel2> {
	public TestModel2Validator() {
		RuleFor(x => x.SomeId).NotEmpty();
	}
}

public class TestModel2 {	
	public Guid SomeId { get; set; }
}

@pawepaw
Copy link
Author

pawepaw commented Jul 26, 2017

yeah you are right. It was nullable guid... I'm blind sorry and thanks for reply.
Probably it's time to go home.

@pawepaw pawepaw closed this as completed Jul 26, 2017
@JeremySkinner
Copy link
Member

Ah great, glad you found it. Going home sounds good to me!

@lock lock bot locked and limited conversation to collaborators Aug 20, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants