public void Should_return_true_if_both_items_are_invalid_and_have_different_keys()
    {
        (TestEnum.Get("unknown") != TestEnum.Get("other")).Should().BeTrue();

        (ExtensibleTestValidatableEnum.Get("unknown") != ExtensibleTestValidatableEnum.Get("other")).Should().BeTrue();
        (ExtendedTestValidatableEnum.Get("unknown") != ExtendedTestValidatableEnum.Get("other")).Should().BeTrue();
    }
    public void Should_return_false_if_both_items_are_invalid_and_have_same_key()
    {
        (TestEnum.Get("unknown") != TestEnum.Get("Unknown")).Should().BeFalse();

        (ExtensibleTestValidatableEnum.Get("unknown") != ExtensibleTestValidatableEnum.Get("Unknown")).Should().BeFalse();
        (ExtendedTestValidatableEnum.Get("unknown") != ExtendedTestValidatableEnum.Get("Unknown")).Should().BeFalse();
    }
예제 #3
0
    public void Should_return_true_if_both_items_are_invalid_and_have_same_key()
    {
        TestEnum.Get("unknown").Equals(TestEnum.Get("Unknown")).Should().BeTrue();

        ExtensibleTestValidatableEnum.Get("unknown").Equals(ExtensibleTestValidatableEnum.Get("Unknown")).Should().BeTrue();
        ExtendedTestValidatableEnum.Get("unknown").Equals(ExtendedTestValidatableEnum.Get("Unknown")).Should().BeTrue();
    }
예제 #4
0
    public void Should_return_false_if_both_items_are_invalid_and_have_different_keys()
    {
        TestEnum.Get("unknown").Equals(TestEnum.Get("other")).Should().BeFalse();

        ExtensibleTestValidatableEnum.Get("unknown").Equals(ExtensibleTestValidatableEnum.Get("other")).Should().BeFalse();
        ExtendedTestValidatableEnum.Get("unknown").Equals(ExtendedTestValidatableEnum.Get("other")).Should().BeFalse();
    }
예제 #5
0
    public void Should_return_null_if_null_is_provided()
    {
        TestEnum.Get(null).Should().BeNull();
        ValidTestEnum.Get(null).Should().BeNull();

        ExtensibleTestEnum.Get(null).Should().BeNull();
        ExtendedTestEnum.Get(null).Should().BeNull();
        DifferentAssemblyExtendedTestEnum.Get(null).Should().BeNull();
        ExtensibleTestValidatableEnum.Get(null).Should().BeNull();
        ExtendedTestValidatableEnum.Get(null).Should().BeNull();
    }
예제 #6
0
    public void Should_return_item_with_provided_key()
    {
        TestEnum.Get("item2").Should().Be(TestEnum.Item2);

        ValidTestEnum.Get("item1").Should().Be(ValidTestEnum.Item1);

        ExtensibleTestEnum.Get("Item1").Should().Be(ExtensibleTestEnum.Item1);
        ExtendedTestEnum.Get("Item1").Should().Be(ExtendedTestEnum.Item1);
        ExtendedTestEnum.Get("Item2").Should().Be(ExtendedTestEnum.Item2);
        DifferentAssemblyExtendedTestEnum.Get("Item1").Should().Be(DifferentAssemblyExtendedTestEnum.Item1);
        DifferentAssemblyExtendedTestEnum.Get("Item2").Should().Be(DifferentAssemblyExtendedTestEnum.Item2);

        ExtensibleTestValidatableEnum.Get("Item1").Should().Be(ExtensibleTestValidatableEnum.Item1);
        ExtendedTestValidatableEnum.Get("Item1").Should().Be(ExtendedTestValidatableEnum.Item1);
        ExtendedTestValidatableEnum.Get("Item2").Should().Be(ExtendedTestValidatableEnum.Item2);
    }
예제 #7
0
    public void Should_return_invalid_item_if_enum_doesnt_have_item_with_provided_key()
    {
        var item = TestEnum.Get("unknown");

        item.IsValid.Should().BeFalse();
        item.Key.Should().Be("unknown");

        var extensibleItem = ExtensibleTestValidatableEnum.Get("unknown");

        extensibleItem.IsValid.Should().BeFalse();
        extensibleItem.Key.Should().Be("unknown");

        var extendedItem = ExtendedTestValidatableEnum.Get("unknown");

        extendedItem.IsValid.Should().BeFalse();
        extendedItem.Key.Should().Be("unknown");
    }
예제 #8
0
    public void Should_return_invalid_item_if_enum_has_no_such_key()
    {
        var item = TestEnum.Get("invalid");

        item.Key.Should().Be("invalid");
        item.IsValid.Should().BeFalse();

        var extensibleItem = ExtensibleTestValidatableEnum.Get("invalid");

        extensibleItem.Key.Should().Be("invalid");
        extensibleItem.IsValid.Should().BeFalse();

        var extendedItem = ExtendedTestValidatableEnum.Get("invalid");

        extendedItem.Key.Should().Be("invalid");
        extendedItem.IsValid.Should().BeFalse();
    }
    public void Should_throw_if_item_is_invalid()
    {
        TestEnum.Get("invalid").Invoking(e => e.EnsureValid())
        .Should().Throw <InvalidOperationException>().WithMessage($"The current enumeration item of type \"{nameof(TestEnum)}\" with identifier \"invalid\" is not valid.");

        StructStringEnum.Get("invalid").Invoking(e => e.EnsureValid())
        .Should().Throw <InvalidOperationException>().WithMessage($"The current enumeration item of type \"{nameof(StructStringEnum)}\" with identifier \"invalid\" is not valid.");

        AbstractEnum.Get(42).Invoking(e => e.EnsureValid())
        .Should().Throw <InvalidOperationException>().WithMessage($"The current enumeration item of type \"{nameof(AbstractEnum)}\" with identifier \"42\" is not valid.");

        StructIntegerEnum.Get(42).Invoking(e => e.EnsureValid())
        .Should().Throw <InvalidOperationException>().WithMessage($"The current enumeration item of type \"{nameof(StructIntegerEnum)}\" with identifier \"42\" is not valid.");

        // we cannot prevent construction of a struct
        new StructIntegerEnumWithZero().Invoking(e => e.EnsureValid())
        .Should().Throw <InvalidOperationException>().WithMessage($"The current enumeration item of type \"{nameof(StructIntegerEnumWithZero)}\" with identifier \"0\" is not valid.");

        ExtensibleTestValidatableEnum.Get("invalid").Invoking(e => e.EnsureValid())
        .Should().Throw <InvalidOperationException>().WithMessage($"The current enumeration item of type \"{nameof(ExtensibleTestValidatableEnum)}\" with identifier \"invalid\" is not valid.");

        ExtendedTestValidatableEnum.Get("invalid").Invoking(e => e.EnsureValid())
        .Should().Throw <InvalidOperationException>().WithMessage($"The current enumeration item of type \"{nameof(ExtendedTestValidatableEnum)}\" with identifier \"invalid\" is not valid.");
    }