예제 #1
0
        public async Task Collection_Configuration()
        {
            // arrange
            BsonClassMap.RegisterClassMap <Bar>(
                x => x.MapField(y => y.Baz)
                .SetSerializer(new DateTimeOffsetSerializer(BsonType.String))
                .SetElementName("testName"));

            IRequestExecutor tester = CreateSchema(
                () =>
            {
                IMongoCollection <Bar> collection =
                    _resource.CreateCollection <Bar>("data_" + Guid.NewGuid().ToString("N"));

                collection.InsertMany(_barEntities);
                return(collection.AsExecutable());
            });

            // act
            IExecutionResult res1 = await tester.ExecuteAsync(
                QueryRequestBuilder.New()
                .SetQuery("{ root(order: { baz: ASC}){ baz}}")
                .Create());

            IExecutionResult res2 = await tester.ExecuteAsync(
                QueryRequestBuilder.New()
                .SetQuery("{ root(order: { baz: DESC}){ baz}}")
                .Create());

            // assert
            res1.MatchDocumentSnapshot("ASC");
            res2.MatchDocumentSnapshot("DESC");
        }
예제 #2
0
        public async Task BsonElement_Rename()
        {
            // arrange
            IRequestExecutor tester = CreateSchema(
                () =>
            {
                IMongoCollection <Foo> collection =
                    _resource.CreateCollection <Foo>("data_" + Guid.NewGuid().ToString("N"));

                collection.InsertMany(_fooEntities);
                return(collection.AsExecutable());
            });

            // act
            IExecutionResult res1 = await tester.ExecuteAsync(
                QueryRequestBuilder.New()
                .SetQuery("{ root(order: { bar: ASC}){ bar}}")
                .Create());

            IExecutionResult res2 = await tester.ExecuteAsync(
                QueryRequestBuilder.New()
                .SetQuery("{ root(order: { bar: DESC}){ bar}}")
                .Create());

            // assert
            res1.MatchDocumentSnapshot("ASC");
            res2.MatchDocumentSnapshot("DESC");
        }
예제 #3
0
        private Func <IResolverContext, IExecutable <TResult> > BuildResolver <TResult>(
            MongoResource mongoResource,
            params TResult[] results)
            where TResult : class
        {
            IMongoCollection <TResult> collection =
                mongoResource.CreateCollection <TResult>("data_" + Guid.NewGuid().ToString("N"));

            collection.InsertMany(results);

            return(ctx => collection.AsExecutable());
        }
예제 #4
0
        private Func <IResolverContext, IExecutable <TResult> > BuildResolver <TResult>(
            MongoResource mongoResource,
            params TResult[] results)
            where TResult : class
        {
            if (FileName is null)
            {
                throw new InvalidOperationException();
            }

            IMongoCollection <TResult> collection =
                mongoResource.CreateCollection <TResult>("data_" + Guid.NewGuid().ToString("N"));

            collection.InsertMany(results);

            return(ctx => collection.AsExecutable());
        }
예제 #5
0
 public IExecutable <Person> GetPersons([Service] IMongoCollection <Person> collection)
 {
     return(collection.AsExecutable());
 }