コード例 #1
0
        private Mock <IConnection> PrepareRethinkDbConnectionMock(bool databaseExists, bool tableExists)
        {
            Mock <IConnection> rethinkDbConnectionMock = new Mock <IConnection>();

            rethinkDbConnectionMock
            .Setup(m => m.RunResultAsync <string[]>(It.Is <ReqlAst>(reql => DB_OR_TABLE_LIST_REQL_MATCH(reql)), It.IsAny <Object>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync((ReqlAst reql, Object globalOpts, CancellationToken cancelToken) =>
            {
                string reqlRaw = ReqlRaw.ToRawString(reql);

                if (databaseExists && DB_LIST_REQL_RAW.Equals(reqlRaw))
                {
                    return(new string[] { DATABASE_NAME });
                }

                if (tableExists && TABLE_LIST_REQL_RAW.Equals(reqlRaw))
                {
                    return(new string[] { TABLE_NAME });
                }

                return(new string[0]);
            });

            return(rethinkDbConnectionMock);
        }
コード例 #2
0
        public void avoid_shadowing_seralized_ast_lambda_expressions()
        {
            //Full Query / No Seralization
            var filter = R.Expr(R.Array(5, 4, 3)).Filter(doc => IsForbidden(doc).Not());

            var result = filter.RunResult <List <int> >(conn);

            result.Dump();
            result.Should().BeEquivalentTo(5, 4);
            //RESULT:
            //[5,4]

            //This is unbound?
            ReqlFunction1 func = expr => IsForbidden(expr).Not();
            var           str  = ReqlRaw.ToRawString(func);

            str.Dump();
            var rawFilter     = ReqlRaw.FromRawString(str);
            var filterWithRaw = R.Expr(R.Array(5, 4, 3)).Filter(rawFilter);
            //Not Allowed in C#
            //var filterWithRaw = R.Expr(R.Array(5, 4, 3)).Filter( x => rawFilter.SomethingElse );
            var result2 = filterWithRaw.RunResult <List <int> >(conn);

            result2.Should().BeEquivalentTo(5, 4);
            //ExtensionsForTesting.Dump(result2);
        }
コード例 #3
0
        public void can_stich_together_some_crazy_reql_expr_thing()
        {
            ClearDefaultTable();

            var foos = new[]
            {
                new Foo {
                    id = "a", Baz = 1, Bar = 1, Idx = "qux"
                },
                new Foo {
                    id = "b", Baz = 2, Bar = 2, Idx = "bub"
                },
                new Foo {
                    id = "c", Baz = 3, Bar = 3, Idx = "qux"
                }
            };

            R.Db(DbName).Table(TableName).Insert(foos).Run(conn);

            ReqlFunction1 filter = expr => expr["Bar"].Gt(2);

            var str = ReqlRaw.ToRawString(filter);

            str.Dump();

            var filterTerm = ReqlRaw.FromRawString(str);

            var result = table.Filter(filterTerm).RunResult <List <Foo> >(conn);

            result.Dump();

            result[0].id.Should().Be(foos[2].id);
            result[0].Baz.Should().Be(3);
            result.Count.Should().Be(1);
        }
コード例 #4
0
        public async Task can_test_using_mock()
        {
            var expectedQuery = R.Db(DbName).Table(TableName).ToRawString();

            var testQuery = R.Db(DbName).Table(TableName);

            var conn = A.Fake <IConnection>();

            await testQuery.RunAtomAsync <Result>(conn);

            A.CallTo(() =>
                     conn.RunAtomAsync <Result>(
                         A <ReqlAst> .That.Matches(test =>
                                                   ReqlRaw.ToRawString(test) == expectedQuery),
                         A <object> ._,
                         A <CancellationToken> ._))
            .MustHaveHappened();
        }