public void ShouldBeKnownValue_WhenValueIsNullAndNullIsAllowed_ReturnsObjectValidator() { IObjectValidator sut = CreateSut(); IValidator result = sut.ShouldBeKnownValue <object>(null, async obj => await Task.Run(() => _fixture.Create <bool>()), GetType(), _fixture.Create <string>(), true); Assert.That(result, Is.TypeOf <BusinessLogic.Validation.ObjectValidator>()); }
public void ShouldBeKnownValue_WhenValueIsNotNull_AssertIsKnownValueGetterWasCalled() { IObjectValidator sut = CreateSut(); object value = _fixture.Create <object>(); object isKnownValueGetterWasCalledWithObject = null; sut.ShouldBeKnownValue(value, async obj => await Task.Run(() => { isKnownValueGetterWasCalledWithObject = obj; return(true); }), GetType(), _fixture.Create <string>()); Assert.That(isKnownValueGetterWasCalledWithObject, Is.EqualTo(value)); }
public void ShouldBeKnownValue_WhenValueIsNullAndNullIsNotAllowed_ThrowsIntranetValidationException() { IObjectValidator sut = CreateSut(); Type validatingType = GetType(); string validatingField = _fixture.Create <string>(); IntranetValidationException result = Assert.Throws <IntranetValidationException>(() => sut.ShouldBeKnownValue <object>(null, async obj => await Task.Run(() => _fixture.Create <bool>()), validatingType, validatingField)); Assert.That(result.ErrorCode, Is.EqualTo(ErrorCode.ValueCannotBeNull)); Assert.That(result.ValidatingType, Is.EqualTo(validatingType)); Assert.That(result.ValidatingField, Is.EqualTo(validatingField)); }
public void ShouldBeKnownValue_WhenValidatingFieldIsWhiteSpace_ThrowsArgumentNullException() { IObjectValidator sut = CreateSut(); ArgumentNullException result = Assert.Throws <ArgumentNullException>(() => sut.ShouldBeKnownValue(_fixture.Create <object>(), async obj => await Task.Run(() => _fixture.Create <bool>()), GetType(), " ")); Assert.That(result.ParamName, Is.EqualTo("validatingField")); }
public void ShouldBeKnownValue_WhenIsKnownValueGetterIsNull_ThrowsArgumentNullException() { IObjectValidator sut = CreateSut(); ArgumentNullException result = Assert.Throws <ArgumentNullException>(() => sut.ShouldBeKnownValue(_fixture.Create <object>(), null, GetType(), _fixture.Create <string>())); Assert.That(result.ParamName, Is.EqualTo("isKnownValueGetter")); }
public void ShouldBeKnownValue_WhenValueIsNotNullAndIsKnownValueGetterThrowsException_ThrowsIntranetValidationException() { IObjectValidator sut = CreateSut(); Exception exception = _fixture.Create <Exception>(); bool IsKnownValueGetter() => throw exception; Type validatingType = GetType(); string validatingField = _fixture.Create <string>(); IntranetValidationException result = Assert.Throws <IntranetValidationException>(() => sut.ShouldBeKnownValue(_fixture.Create <object>(), async obj => await Task.Run((Func <bool>)IsKnownValueGetter), validatingType, validatingField)); Assert.That(result.ErrorCode, Is.EqualTo(ErrorCode.ValueShouldBeKnown)); Assert.That(result.ValidatingType, Is.EqualTo(validatingType)); Assert.That(result.ValidatingField, Is.EqualTo(validatingField)); Assert.That(result.InnerException, Is.EqualTo(exception)); }
public void ShouldBeKnownValue_WhenValueIsNotNullAndUnknown_ThrowsIntranetValidationException() { IObjectValidator sut = CreateSut(); Type validatingType = GetType(); string validatingField = _fixture.Create <string>(); IntranetValidationException result = Assert.Throws <IntranetValidationException>(() => sut.ShouldBeKnownValue(_fixture.Create <object>(), async obj => await Task.Run(() => false), validatingType, validatingField)); Assert.That(result.ErrorCode, Is.EqualTo(ErrorCode.ValueShouldBeKnown)); Assert.That(result.ValidatingType, Is.EqualTo(validatingType)); Assert.That(result.ValidatingField, Is.EqualTo(validatingField)); Assert.That(result.InnerException, Is.Null); }