コード例 #1
0
        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>());
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        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));
        }
コード例 #4
0
        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"));
        }
コード例 #5
0
        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"));
        }
コード例 #6
0
        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));
        }
コード例 #7
0
        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);
        }