public void BeforeCall_Throws_Exception_On_Null_When_No_SkipNullCheck_Defined_But_ParameterInfo_Passed() { var parameterInfo = new ParameterDetailsInfo { ParameterDetails = new List <ParameterDetails> { new ParameterDetails { Name = "test", Position = 0, SkipNullcheck = false } } }; var inspector = new ValidatingParameterInspector(new[] { _singleValidatorMock.Object, _secondValidatorMock.Object, new NullCheckObjectValidator() }, _errorMessageGeneratorMock.Object, null, parameterInfo); object input = null; Assert.Throws <FaultException>( () => inspector.BeforeCall(OperationName, new[] { input })); }
public void BeforeCall_SkipNullCheck() { var parameterInfo = new ParameterDetailsInfo { ParameterDetails = new List <ParameterDetails> { new ParameterDetails { Name = "test", Position = 0, SkipNullcheck = true } } }; var inspector = new ValidatingParameterInspector(new[] { _singleValidatorMock.Object, _secondValidatorMock.Object, new NullCheckObjectValidator() }, _errorMessageGeneratorMock.Object, null, parameterInfo); object input = null; inspector.BeforeCall(OperationName, new[] { input }); _singleValidatorMock.Verify(x => x.Validate(input), Times.Once()); }
public void Setup() { _defaultParameterDetailsInfo = new ParameterDetailsInfo { ParameterDetails = new List <ParameterDetails> { new ParameterDetails { Name = "test", Position = 0, SkipNullcheck = false }, new ParameterDetails { Name = "test2", Position = 1, SkipNullcheck = false } } }; _singleValidatorMock = new Mock <IObjectValidator>(); _singleValidatorMock.Setup(x => x.Validate(It.IsAny <object>())).Returns(Enumerable.Empty <ValidationResult>()); _secondValidatorMock = new Mock <IObjectValidator>(); _secondValidatorMock.Setup(x => x.Validate(It.IsAny <object>())).Returns(Enumerable.Empty <ValidationResult>()); _errorMessageGeneratorMock = new Mock <IErrorMessageGenerator>(); _singleValidatorParameterInspector = new ValidatingParameterInspector(new[] { _singleValidatorMock.Object }, _errorMessageGeneratorMock.Object, null, _defaultParameterDetailsInfo); _multipleValidatorsParameterInspector = new ValidatingParameterInspector(new[] { _singleValidatorMock.Object, _secondValidatorMock.Object }, _errorMessageGeneratorMock.Object, null, _defaultParameterDetailsInfo); }
public void BeforeCall_SkipNullCheck_With_Multiple_Parameters() { var parameterInfo = new ParameterDetailsInfo { ParameterDetails = new List <ParameterDetails> { new ParameterDetails { Name = "test1", Position = 0, SkipNullcheck = false }, new ParameterDetails { Name = "test2", Position = 1, SkipNullcheck = true }, new ParameterDetails { Name = "test3", Position = 2, SkipNullcheck = false } } }; var inspector = new ValidatingParameterInspector(new[] { _singleValidatorMock.Object, _secondValidatorMock.Object, new NullCheckObjectValidator() }, _errorMessageGeneratorMock.Object, null, parameterInfo); object input1 = new object(); object input2 = null; object input3 = "test"; inspector.BeforeCall(OperationName, new[] { input1, input2, input3 }); }
public void BeforeCall_SkipNullCheck_With_Multiple_Parameters_Should_Throw_If_Not_SkipNullCheck_Marked_Parameter_Is_Null() { var parameterInfo = new ParameterDetailsInfo { ParameterDetails = new List <ParameterDetails> { new ParameterDetails { Name = "test1", Position = 0, SkipNullcheck = false }, new ParameterDetails { Name = "test2", Position = 1, SkipNullcheck = true }, new ParameterDetails { Name = "test3", Position = 2, SkipNullcheck = false } } }; var inspector = new ValidatingParameterInspector(new[] { _singleValidatorMock.Object, _secondValidatorMock.Object, new NullCheckObjectValidator() }, _errorMessageGeneratorMock.Object, null, parameterInfo); object input1 = new object(); object input2 = "test"; object input3 = null; Assert.Throws <FaultException>( () => inspector.BeforeCall(OperationName, new[] { input1, input2, input3 })); }