Esempio n. 1
0
        public void ReturnsFalseAndNullForUnsuccessfulResult()
        {
            Result <int?> result = new InvalidOperationError();

            Assert.False(result.IsDefined(out var entity));
            Assert.Null(entity);
        }
Esempio n. 2
0
    public void HandlesNullabilityAnnotationsCorrectly()
    {
        // Successful value type results
        Result <int>  integerValue           = 1;
        Result <int?> nullNullableInteger    = (int?)null;
        Result <int?> nonNullNullableInteger = 1;

        // Unsuccessful value type results
        Result <int>  failedInteger         = new InvalidOperationError();
        Result <int?> failedNullableInteger = new InvalidOperationError();

        // Successful reference type results
        Result <string>  stringValue           = string.Empty;
        Result <string?> nullNullableString    = (string?)null;
        Result <string?> nonNullNullableString = string.Empty;

        // Unsuccessful reference type results
        Result <string>  failedString         = new InvalidOperationError();
        Result <string?> failedNullableString = new InvalidOperationError();

        // Actual tests

        // Valid access to value types
        if (integerValue.IsSuccess)
        {
            Assert.NotNull(integerValue.Entity.ToString());
        }

        if (nullNullableInteger.IsSuccess)
        {
            Assert.Null(nullNullableInteger.Entity?.ToString());
        }

        if (nonNullNullableInteger.IsSuccess)
        {
            Assert.NotNull(nullNullableInteger.Entity.ToString());
        }

        // Composite access to value types
        if (nonNullNullableInteger is { IsSuccess : true, Entity : not null })
Esempio n. 3
0
        public void ReturnsFalseForUnsuccessfulResult()
        {
            Result <int?> result = new InvalidOperationError();

            Assert.False(result.IsDefined());
        }