public static async Task <ApiResponse <T> > Fetch <T>(
            this ISqlHattemSessionFactory sessionFactory,
            Func <ISqlHattemSession, Task <ApiResponse <T> > > handler
            )
        {
            using var session = sessionFactory.Create();

            return(await handler(session)
                   .OnError(ErrorPredicate.Any(), _ => session.Rollback())
                   .OnSuccess(_ => session.Commit()));
        }
        public static async Task <ApiResponse <T> > Execute <T>(
            this ISqlHattemSessionFactory sessionFactory,
            Func <ISqlHattemSession, Task <ApiResponse <T> > > handler,
            IsolationLevel isolationLevel = IsolationLevel.ReadCommitted
            )
        {
            using var session = sessionFactory.Create(isolationLevel);

            return(await handler(session)
                   .OnError(ErrorPredicate.Any(), _ => session.Rollback())
                   .OnSuccess(_ => session.Commit()));
        }
        public async Task Sync_Async_AnyErrorPredicate_HasErrors_ValidError_ExecuteOnError()
        {
            var onErrorMock = new Mock <IAsyncExecutionProvider <Error> >();

            var response = await ApiResponse
                           .Error(TestError.Default)
                           .OnError(
                ErrorPredicate.Any(),
                e => onErrorMock.Object.Execute(e));

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

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