Beispiel #1
0
        public void DoNotMatch(params string[] errorCodes)
        {
            var predicate = ErrorPredicate.ByCode(errorCodes);

            var isMatch = predicate.IsMatch(new Error("invalid", "test"));

            Assert.False(isMatch);
        }
Beispiel #2
0
        public void Match(params string[] errorCodes)
        {
            var predicate = ErrorPredicate.ByCode(errorCodes);

            var isMatch = predicate.IsMatch(new Error(errorCodes[0], "test"));

            Assert.True(isMatch);
        }
Beispiel #3
0
        public void DoNotMatch_WithCondition(params string[] errorCodes)
        {
            var predicate = ErrorPredicate
                            .ByCode(errorCodes)
                            .WithCondition(_ => false);

            var isMatch = predicate.IsMatch(new Error(errorCodes[0], "test"));

            Assert.False(isMatch);
        }
Beispiel #4
0
        public void Sync_CodeErrorPredicate_HasErrors_ValidError_ReturnsOk()
        {
            const int expectedStatusCode = 203;

            var response = ApiResponse
                           .Error <int>(TestError.Default)
                           .WithStatusCode(expectedStatusCode)
                           .SuppressErrors(
                ErrorPredicate.ByCode(TestError.Default.Code));

            Assert.True(response.IsOk);
            Assert.Null(response.StatusCode);
        }
Beispiel #5
0
        public async Task Sync_Async_CodeErrorPredicate()
        {
            const int ifErrorData = 3;

            var response = await ApiResponse
                           .Error <int>(AnotherTestError.Default)
                           .IfError(
                ErrorPredicate.ByCode(AnotherTestError.Default.Code),
                e => ApiResponse.Ok(ifErrorData).AsTask());

            Assert.True(response.IsOk);
            Assert.Equal(ifErrorData, response.Data);
        }
        public async Task Sync_Async_CodeErrorPredicate_HasErrors_ValidError_ExecuteOnError()
        {
            var onErrorMock = new Mock <IAsyncExecutionProvider <Error> >();

            var response = await ApiResponse
                           .Error(TestError.Default)
                           .OnError(
                ErrorPredicate.ByCode(TestError.Default.Code),
                onErrorMock.Object.Execute);

            Assert.True(response.HasErrors);
            Assert.Equal(TestError.Default, response.Error, ErrorComparer.Default);

            onErrorMock.Verify(v => v.Execute(TestError.Default), Times.Once());
        }