public void TryValidateThrowsOnNonString() { var attrib = new MustNotBeEmptyAttribute(); attrib.Invoking(a => a.TryValidate(CreateContext(), new StringValidationAttributeTests(), out string reason)) .Should().Throw <InvalidCastException>(); }
public void EmptyStringCorrectlyFailsAtNotBeingEmpty() { var attrib = new MustNotBeEmptyAttribute(); attrib.TryValidate(CreateContext(), string.Empty, out string reason) .Should().BeFalse(); reason.Should().NotBeNullOrEmpty(); }
public void NonEmptyStringCorrectlyChecksAsNotBeingEmpty() { var attrib = new MustNotBeEmptyAttribute(); attrib.TryValidate(CreateContext(), "non-empty", out string reason) .Should().BeTrue(); reason.Should().BeNull(); }
public void ObjectConvertibleToStringValidatesCorrectly() { var attrib = new MustNotBeEmptyAttribute(); attrib.TryValidate(CreateContext(), new ColoredString("non-empty"), out string reason) .Should().BeTrue(); reason.Should().BeNull(); attrib.TryValidate(CreateContext(), ColoredString.Empty, out reason) .Should().BeFalse(); reason.Should().NotBeNullOrEmpty(); }