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

Fixed bug in inline Specification #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

SathishN
Copy link

When creating Specification with inline specification. it throws ArgumentNullException.

public class Person
{
    public string Name { get; set; }

    public Address2 MailingAddress { get; set; }

    public Address2 ShippingAddress { get; set; }
}

public class Address2
{
    public const string MailingType = "MAIL";

    public const string ShippingType = "SHIP";

    public string Type { get; set; }
    public string AddressLine { get; set; }
    public string City { get; set; }
    public string State { get; set; }
}

public class PersonSpecification : Validates<Person>
{
    public PersonSpecification()
    {
        Check(_ => _.Name).Required();

        Check(_ => _.MailingAddress).Optional()
            .Specification(v => v.Check(x => x.Type == Address2.MailingType))
            .And
            .Specification<Address2Specification>();

        Check(_ => _.ShippingAddress).Optional()
            .Specification(v => v.Check(x => x.Type == Address2.ShippingType))
            .And
            .Specification<Address2Specification>();
    }
}

public class Address2Specification : Validates<Address2>
{
    public Address2Specification()
    {
        Check(_ => _.AddressLine).Required();
        Check(_ => _.City).Required();
        Check(_ => _.State).Required();
    }
}

that throws following error

System.ArgumentNullException : Value cannot be null.
Parameter name: key
   at System.Collections.Generic.Dictionary`2.FindEntry(TKey key)
   at System.Collections.Generic.Dictionary`2.ContainsKey(TKey key)
   at SpecExpress.Rules.RuleValidatorContext.GetValidationProperty(PropertyValidator validator, Type instanceType) in RuleValidatorContext.cs: line 96
   at SpecExpress.Rules.RuleValidatorContext.SelectPropertyName(Object instance, PropertyValidator validator) in RuleValidatorContext.cs: line 55
   at SpecExpress.Rules.RuleValidatorContext..ctor(Object instance, PropertyValidator validator, RuleValidatorContext parentContext) in RuleValidatorContext.cs: line 36
   at SpecExpress.Rules.RuleValidatorContext`2..ctor(T instance, PropertyValidator`2 validator, RuleValidatorContext parentContext) in RuleValidatorContext.cs: line 114
   at SpecExpress.PropertyValidator`2.Validate(T instance, RuleValidatorContext parentRuleContext, SpecificationContainer specificationContainer, ValidationNotification notification) in PropertyValidator.cs: line 469
   at SpecExpress.PropertyValidator`1.Validate(Object instance, RuleValidatorContext parentRuleContext, SpecificationContainer specificationContainer, ValidationNotification notification) in PropertyValidator.cs: line 207
   at SpecExpress.Rules.GeneralValidators.SpecificationRule`2.Validate(RuleValidatorContext`2 context, SpecificationContainer specificationContainer, ValidationNotification notification) in SpecificationRule.cs: line 59
   at lambda_method(Closure, RuleValidatorContext`2, SpecificationContainer, ValidationNotification)
   at SpecExpress.PropertyValidator`2.Validate(T instance, RuleValidatorContext parentRuleContext, SpecificationContainer specificationContainer, ValidationNotification notification) in PropertyValidator.cs: line 477
   at SpecExpress.PropertyValidator`1.Validate(Object instance, SpecificationContainer specificationContainer, ValidationNotification notification) in PropertyValidator.cs: line 202
   at SpecExpress.SpecificationBase.Validate(Object instance, SpecificationContainer specificationContainer, ValidationNotification notification) in SpecificationBase.cs: line 34
   at SpecExpress.ValidationCatalog.Validate(Object instance, SpecificationContainer container, SpecificationBase specificationBase) in ValidationCatalog.cs: line 259
   at SpecExpress.ValidationCatalog.Validate(Object instance) in ValidationCatalog.cs: line 275
   at SpecExpress.Test.PersonSpecificationTests.Valid_Person() in PersonSpecificationTests.cs: line 44

Fixes are in the pull request.

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