Пример #1
0
        public void TestMethod1 <T, TResult>(Func <IDataReader, T> readerFunc,
                                             Func <Func <IDataReader, T>, Func <IDataReader, TResult> > func, List <T> data, TResult expected)
        {
            var readerMoq  = CreateDataReaderMock(data);
            var commandMoq = CreateSqlCommandMock <TResult>(readerMoq);
            var moq        = CreateConnectionMock <TResult>(commandMoq, CommandType.StoredProcedure);

            var actual = IDvlSql.DefaultDvlSql(moq.Object).Procedure("someProc")
                         .ExecuteAsync(func(readerFunc))
                         .Result;

            if (actual is { } && expected is IEnumerable enumerable)
Пример #2
0
        public void FirstWithFunc <T>(Func <IDataReader, T> func, List <T> data, T expected)
        {
            var readerMoq  = CreateDataReaderMock(data);
            var commandMoq = CreateSqlCommandMock <T>(readerMoq);
            var moq        = CreateConnectionMock <T>(commandMoq);

            var actual = IDvlSql.DefaultDvlSql(moq.Object)
                         .From(TableName)
                         .Select()
                         .FirstAsync(func)
                         .Result;

            Assert.That(actual, Is.EqualTo(expected));
        }
Пример #3
0
        public void AnyWithoutWhere <T>(List <T> data, bool expected)
        {
            var readerMoq  = CreateDataReaderMock(data);
            var commandMoq = CreateSqlCommandMock <bool>(readerMoq);
            var moq        = CreateConnectionMockWithSqlStringContains <bool>(commandMoq);

            var actual = IDvlSql.DefaultDvlSql(moq.Object)
                         .From(TableName)
                         .Select()
                         .AnyAsync()
                         .Result;

            Assert.That(actual, Is.EqualTo(expected));
        }
Пример #4
0
        public void TestToListWithoutFunc <T>(List <T> data, List <T> expected)
        {
            var readerMoq  = CreateDataReaderMock(data);
            var commandMoq = CreateSqlCommandMock <List <T> >(readerMoq);
            var moq        = CreateConnectionMock <List <T> >(commandMoq);

            var list = IDvlSql.DefaultDvlSql(moq.Object)
                       .From(TableName)
                       .Select()
                       .ToListAsync <T>()
                       .Result;

            Assert.That(list, Is.EquivalentTo(expected));
        }
Пример #5
0
        public void FirstWithFuncThrowingExceptions <T>(Func <IDataReader, T> func, List <T> data)
        {
            var readerMoq  = CreateDataReaderMock(data);
            var commandMoq = CreateSqlCommandMock <T>(readerMoq);
            var moq        = CreateConnectionMock <T>(commandMoq);

            Assert.Throws(Is.InstanceOf(typeof(Exception)), () =>
            {
                var res = IDvlSql.DefaultDvlSql(moq.Object)
                          .From(TableName)
                          .Select()
                          .FirstAsync(func)
                          .Result;
            });
        }
Пример #6
0
        public void AllWithWheref1IsPositive <T>(List <T> data, bool expected)
        {
            var readerMoq  = CreateDataReaderMock(data);
            var commandMoq = CreateSqlCommandMock <bool>(readerMoq);
            var moq        = CreateConnectionMock <bool>(commandMoq);

            var actual = IDvlSql.DefaultDvlSql(moq.Object)
                         .From(TableName)
                         .Where(ConstantExp("f1", true) > 0)
                         .Select()
                         .AllAsync()
                         .Result;

            Assert.That(actual, Is.EqualTo(expected));
        }
Пример #7
0
        public void TestToDictionary <TKey, TValue, TData>(Func <IDataReader, TKey> keySelector,
                                                           Func <IDataReader, TValue> valueSelector, List <TData> data, Dictionary <TKey, List <TValue> > expected)
        {
            var readerMoq  = CreateDataReaderMock(data);
            var commandMoq = CreateSqlCommandMock <Dictionary <TKey, List <TValue> > >(readerMoq);
            var moq        = CreateConnectionMock <Dictionary <TKey, List <TValue> > >(commandMoq);

            var dictionary = IDvlSql.DefaultDvlSql(moq.Object)
                             .From(TableName)
                             .Select()
                             .ToDictionaryAsync(keySelector, valueSelector)
                             .Result;

            Assert.That(dictionary, Is.EquivalentTo(expected));
        }