Exemplo n.º 1
0
        public void ShouldBeDeletable_WhenValueIsNotNullAndDeletable_ReturnsReturnsObjectValidator()
        {
            IObjectValidator sut = CreateSut();

            IValidator result = sut.ShouldBeDeletable(_fixture.Create <object>(), async obj => await Task.Run(() => _fixture.BuildDeletableMock(true).Object), GetType(), _fixture.Create <string>());

            Assert.That(result, Is.TypeOf <BusinessLogic.Validation.ObjectValidator>());
        }
Exemplo n.º 2
0
        public void ShouldBeDeletable_WhenValueIsNotNull_AssertDeletableWasCalledOnDeletable()
        {
            IObjectValidator sut = CreateSut();

            Mock <IDeletable> deletableMock = _fixture.BuildDeletableMock(true);

            sut.ShouldBeDeletable(_fixture.Create <object>(), async obj => await Task.Run(() => deletableMock.Object), GetType(), _fixture.Create <string>());

            deletableMock.Verify(m => m.Deletable, Times.Once);
        }
Exemplo n.º 3
0
        public void ShouldBeDeletable_WhenValueIsNullAndNullIsNotAllowed_AssertDeletableWasNotCalledOnDeletable()
        {
            IObjectValidator sut = CreateSut();

            Mock <IDeletable> deletableMock = _fixture.BuildDeletableMock();

            Assert.Throws <IntranetValidationException>(() => sut.ShouldBeDeletable <object, IDeletable>(null, async obj => await Task.Run(() => deletableMock.Object), GetType(), _fixture.Create <string>()));

            deletableMock.Verify(m => m.Deletable, Times.Never);
        }
Exemplo n.º 4
0
        public void ShouldBeDeletable_WhenValueIsNullAndNullIsNotAllowed_AssertDeletableGetterWasNotCalled()
        {
            IObjectValidator sut = CreateSut();

            bool deletableGetterWasCalled = false;

            Assert.Throws <IntranetValidationException>(() => sut.ShouldBeDeletable <object, IDeletable>(null, async obj => await Task.Run(() =>
            {
                deletableGetterWasCalled = true;
                return(_fixture.BuildDeletableMock().Object);
            }),
                                                                                                         GetType(),
                                                                                                         _fixture.Create <string>()));

            Assert.That(deletableGetterWasCalled, Is.False);
        }
Exemplo n.º 5
0
        public void ShouldBeDeletable_WhenValueIsNotNull_AssertDeletableGetterWasCalled()
        {
            IObjectValidator sut = CreateSut();

            object value = _fixture.Create <object>();
            object deletableGetterWasCalledWithObject = null;

            sut.ShouldBeDeletable(value, async obj => await Task.Run(() =>
            {
                deletableGetterWasCalledWithObject = obj;
                return(_fixture.BuildDeletableMock(true).Object);
            }),
                                  GetType(),
                                  _fixture.Create <string>());

            Assert.That(deletableGetterWasCalledWithObject, Is.EqualTo(value));
        }
Exemplo n.º 6
0
        public void ShouldBeDeletable_WhenValidatingFieldIsWhiteSpace_ThrowsArgumentNullException()
        {
            IObjectValidator sut = CreateSut();

            ArgumentNullException result = Assert.Throws <ArgumentNullException>(() => sut.ShouldBeDeletable(_fixture.Create <object>(), async obj => await Task.Run(() => _fixture.BuildDeletableMock().Object), GetType(), " "));

            Assert.That(result.ParamName, Is.EqualTo("validatingField"));
        }
Exemplo n.º 7
0
        public void ShouldBeDeletable_WhenIsDeletableGetterIsNull_ThrowsArgumentNullException()
        {
            IObjectValidator sut = CreateSut();

            ArgumentNullException result = Assert.Throws <ArgumentNullException>(() => sut.ShouldBeDeletable <object, IDeletable>(_fixture.Create <object>(), null, GetType(), _fixture.Create <string>()));

            Assert.That(result.ParamName, Is.EqualTo("deletableGetter"));
        }
Exemplo n.º 8
0
        public void ShouldBeDeletable_WhenValueIsNotNullAndDeletableGetterThrowsException_ThrowsIntranetValidationException()
        {
            IObjectValidator sut = CreateSut();

            Exception exception = _fixture.Create <Exception>();

            IDeletable deletableGetter() => throw exception;

            Type   validatingType              = GetType();
            string validatingField             = _fixture.Create <string>();
            IntranetValidationException result = Assert.Throws <IntranetValidationException>(() => sut.ShouldBeDeletable(_fixture.Create <object>(), async obj => await Task.Run((Func <IDeletable>)deletableGetter), validatingType, validatingField));

            Assert.That(result.ErrorCode, Is.EqualTo(ErrorCode.ValueShouldReferToDeletableEntity));
            Assert.That(result.ValidatingType, Is.EqualTo(validatingType));
            Assert.That(result.ValidatingField, Is.EqualTo(validatingField));
            Assert.That(result.InnerException, Is.EqualTo(exception));
        }
Exemplo n.º 9
0
        public void ShouldBeDeletable_WhenValueIsNotNullAndNotDeletable_ThrowsIntranetValidationException()
        {
            IObjectValidator sut = CreateSut();

            Type   validatingType              = GetType();
            string validatingField             = _fixture.Create <string>();
            IntranetValidationException result = Assert.Throws <IntranetValidationException>(() => sut.ShouldBeDeletable(_fixture.Create <object>(), async obj => await Task.Run(() => _fixture.BuildDeletableMock(false).Object), validatingType, validatingField));

            Assert.That(result.ErrorCode, Is.EqualTo(ErrorCode.ValueShouldReferToDeletableEntity));
            Assert.That(result.ValidatingType, Is.EqualTo(validatingType));
            Assert.That(result.ValidatingField, Is.EqualTo(validatingField));
            Assert.That(result.InnerException, Is.Null);
        }
Exemplo n.º 10
0
        public void ShouldBeDeletable_WhenValueIsNullAndNullIsNotAllowed_ThrowsIntranetValidationException()
        {
            IObjectValidator sut = CreateSut();

            Type   validatingType              = GetType();
            string validatingField             = _fixture.Create <string>();
            IntranetValidationException result = Assert.Throws <IntranetValidationException>(() => sut.ShouldBeDeletable <object, IDeletable>(null, async obj => await Task.Run(() => _fixture.BuildDeletableMock().Object), validatingType, validatingField));

            Assert.That(result.ErrorCode, Is.EqualTo(ErrorCode.ValueCannotBeNull));
            Assert.That(result.ValidatingType, Is.EqualTo(validatingType));
            Assert.That(result.ValidatingField, Is.EqualTo(validatingField));
        }