Пример #1
0
        public void GenericApiSourceOfComposableFunctionIsCorrect()
        {
            var api       = new TestApi();
            var arguments = new object[0];

            var source = api.GetQueryableSource <DateTime>(
                "Namespace", "Function", arguments);

            Assert.Equal(typeof(DateTime), source.ElementType);
            Assert.True(source.Expression is MethodCallExpression);
            var methodCall = source.Expression as MethodCallExpression;

            Assert.Null(methodCall.Object);
            Assert.Equal(typeof(DataSourceStub), methodCall.Method.DeclaringType);
            Assert.Equal("GetQueryableSource", methodCall.Method.Name);
            Assert.Equal(typeof(DateTime), methodCall.Method.GetGenericArguments()[0]);
            Assert.Equal(3, methodCall.Arguments.Count);
            Assert.True(methodCall.Arguments[0] is ConstantExpression);
            Assert.Equal("Namespace", (methodCall.Arguments[0] as ConstantExpression).Value);
            Assert.True(methodCall.Arguments[1] is ConstantExpression);
            Assert.Equal("Function", (methodCall.Arguments[1] as ConstantExpression).Value);
            Assert.True(methodCall.Arguments[2] is ConstantExpression);
            Assert.Equal(arguments, (methodCall.Arguments[2] as ConstantExpression).Value);
            Assert.Equal(source.Expression.ToString(), source.ToString());
        }
Пример #2
0
        public async Task ApiQueryAsyncCorrectlyForwardsCall()
        {
            var api = new TestApi();

            var queryRequest = new QueryRequest(
                api.GetQueryableSource <string>("Test"));
            var queryResult = await api.QueryAsync(queryRequest);

            Assert.True(queryResult.Results.Cast <string>()
                        .SequenceEqual(new[] { "Test" }));
        }
Пример #3
0
        public async Task ApiQueryAsyncWithQueryReturnsResults()
        {
            var api = new TestApi();

            var request = new QueryRequest(api.GetQueryableSource <string>("Test"));
            var result  = await api.Context.QueryAsync(request);

            var results = result.Results.Cast <string>();

            Assert.True(results.SequenceEqual(new[] { "Test" }));
        }
Пример #4
0
        public void CanCallGetQueryableSourceWithTElementAndApiBaseAndStringAndArrayOfObject()
        {
            var  api          = new TestApi(serviceProvider);
            var  name         = "Tests";
            Type expectedType = typeof(Test);

            serviceProviderFixture.ModelMapper.Setup(x => x.TryGetRelevantType(It.IsAny <ModelContext>(), name, out expectedType)).Returns(true);

            var arguments = new[] { new object(), new object(), new object() };
            var result    = api.GetQueryableSource <Test>(name, arguments);

            result.Should().BeAssignableTo <IQueryable <Test> >();
        }
Пример #5
0
        public void CannotCallGetQueryableSourceWithInvalidTElement()
        {
            var  api          = new TestApi(serviceProvider);
            var  name         = "Tests";
            Type expectedType = typeof(Test);

            serviceProviderFixture.ModelMapper.Setup(x => x.TryGetRelevantType(It.IsAny <ModelContext>(), name, out expectedType)).Returns(true);

            var arguments = new[] { new object(), new object(), new object() };

            Action act = () => api.GetQueryableSource <ApiBaseExtensionsTests>(name, new[] { new object(), new object(), new object() });

            act.Should().Throw <ArgumentException>();
        }
Пример #6
0
        public void GenericApiSourceOfEntityContainerElementIsCorrect()
        {
            var api       = new TestApi();
            var arguments = new object[0];

            var source = api.GetQueryableSource <string>("Test", arguments);

            Assert.Equal(typeof(string), source.ElementType);
            Assert.True(source.Expression is MethodCallExpression);
            var methodCall = source.Expression as MethodCallExpression;

            Assert.Null(methodCall.Object);
            Assert.Equal(typeof(DataSourceStub), methodCall.Method.DeclaringType);
            Assert.Equal("GetQueryableSource", methodCall.Method.Name);
            Assert.Equal(typeof(string), methodCall.Method.GetGenericArguments()[0]);
            Assert.Equal(2, methodCall.Arguments.Count);
            Assert.True(methodCall.Arguments[0] is ConstantExpression);
            Assert.Equal("Test", (methodCall.Arguments[0] as ConstantExpression).Value);
            Assert.True(methodCall.Arguments[1] is ConstantExpression);
            Assert.Equal(arguments, (methodCall.Arguments[1] as ConstantExpression).Value);
            Assert.Equal(source.Expression.ToString(), source.ToString());
        }