public void CommittedConfigurationIsConfiguredCorrectly()
        {
            var configuration = new ApiConfiguration();

            configuration.EnsureCommitted();
            Assert.True(configuration.IsCommitted);

            configuration.EnsureCommitted();
            Assert.True(configuration.IsCommitted);
        }
Esempio n. 2
0
 public void NewApiContextIsConfiguredCorrectly()
 {
     var configuration = new ApiConfiguration();
     configuration.EnsureCommitted();
     var context = new ApiContext(configuration);
     Assert.Same(configuration, context.Configuration);
 }
Esempio n. 3
0
        public void GenericSourceOfComposableFunctionIsCorrect()
        {
            var configuration = new ApiConfiguration();
            var modelMapper   = new TestModelMapper();

            configuration.AddHookHandler <IModelMapper>(modelMapper);
            configuration.EnsureCommitted();
            var context   = new ApiContext(configuration);
            var arguments = new object[0];

            var source = Api.Source <DateTime>(context,
                                               "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(ApiData), methodCall.Method.DeclaringType);
            Assert.Equal("Source", 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());
        }
        public async Task GetModelUsingDefaultModelHandler()
        {
            var configuration = new ApiConfiguration();

            configuration.AddHookHandler <IModelBuilder>(new TestModelProducer());
            configuration.AddHookHandler <IModelBuilder>(new TestModelExtender(2));
            configuration.AddHookHandler <IModelBuilder>(new TestModelExtender(3));

            configuration.EnsureCommitted();
            var context = new ApiContext(configuration);

            var model = await Api.GetModelAsync(context);

            Assert.Equal(4, model.SchemaElements.Count());
            Assert.NotNull(model.SchemaElements
                           .SingleOrDefault(e => e.Name == "TestName"));
            Assert.NotNull(model.SchemaElements
                           .SingleOrDefault(e => e.Name == "TestName2"));
            Assert.NotNull(model.SchemaElements
                           .SingleOrDefault(e => e.Name == "TestName3"));
            Assert.NotNull(model.EntityContainer);
            Assert.NotNull(model.EntityContainer.Elements
                           .SingleOrDefault(e => e.Name == "TestEntitySet"));
            Assert.NotNull(model.EntityContainer.Elements
                           .SingleOrDefault(e => e.Name == "TestEntitySet2"));
            Assert.NotNull(model.EntityContainer.Elements
                           .SingleOrDefault(e => e.Name == "TestEntitySet3"));
        }
        public void CommittedConfigurationCannotAddHookHandler()
        {
            var configuration = new ApiConfiguration();

            configuration.EnsureCommitted();

            Assert.Throws <InvalidOperationException>(
                () => configuration.AddHookHandler <IHookHandler>(new TestModelBuilder()));
        }
Esempio n. 6
0
        public void NewApiContextIsConfiguredCorrectly()
        {
            var configuration = new ApiConfiguration();

            configuration.EnsureCommitted();
            var context = new ApiContext(configuration);

            Assert.Same(configuration, context.Configuration);
        }
 public void InvocationContextGetsHookPointsCorrectly()
 {
     var hook = new HookA();
     var configuration = new ApiConfiguration().AddHookHandler<IHookA>(hook);
     configuration.EnsureCommitted();
     var apiContext = new ApiContext(configuration);
     var context = new InvocationContext(apiContext);
     Assert.Same(hook, context.GetHookHandler<IHookA>());
 }
Esempio n. 8
0
        public void SourceOfComposableFunctionThrowsIfNotMapped()
        {
            var configuration = new ApiConfiguration();

            configuration.EnsureCommitted();
            var context   = new ApiContext(configuration);
            var arguments = new object[0];

            Assert.Throws <NotSupportedException>(() => Api.Source(context, "Namespace", "Function", arguments));
        }
Esempio n. 9
0
        public void SourceOfEntityContainerElementThrowsIfNotMapped()
        {
            var configuration = new ApiConfiguration();

            configuration.EnsureCommitted();
            var context   = new ApiContext(configuration);
            var arguments = new object[0];

            Assert.Throws <NotSupportedException>(() => Api.Source(context, "Test", arguments));
        }
        public void InvocationContextGetsHookPointsCorrectly()
        {
            var hook          = new HookA();
            var configuration = new ApiConfiguration().AddHookHandler <IHookA>(hook);

            configuration.EnsureCommitted();
            var apiContext = new ApiContext(configuration);
            var context    = new InvocationContext(apiContext);

            Assert.Same(hook, context.GetHookHandler <IHookA>());
        }
Esempio n. 11
0
        public void GenericSourceOfComposableFunctionThrowsIfWrongType()
        {
            var configuration = new ApiConfiguration();
            var modelMapper   = new TestModelMapper();

            configuration.AddHookHandler <IModelMapper>(modelMapper);
            configuration.EnsureCommitted();
            var context   = new ApiContext(configuration);
            var arguments = new object[0];

            Assert.Throws <ArgumentException>(() => Api.Source <object>(context, "Namespace", "Function", arguments));
        }
Esempio n. 12
0
        public void GenericSourceOfEntityContainerElementThrowsIfWrongType()
        {
            var configuration = new ApiConfiguration();
            var modelMapper   = new TestModelMapper();

            configuration.AddHookHandler <IModelMapper>(modelMapper);
            configuration.EnsureCommitted();
            var context   = new ApiContext(configuration);
            var arguments = new object[0];

            Assert.Throws <ArgumentException>(() => Api.Source <object>(context, "Test", arguments));
        }
Esempio n. 13
0
        public void SourceQueryProviderCannotExecute()
        {
            var configuration = new ApiConfiguration();
            var modelMapper   = new TestModelMapper();

            configuration.AddHookHandler <IModelMapper>(modelMapper);
            configuration.EnsureCommitted();
            var context = new ApiContext(configuration);

            var source = Api.Source <string>(context, "Test");

            Assert.Throws <NotSupportedException>(() => source.Provider.Execute(null));
        }
Esempio n. 14
0
        public void SourceQueryableCannotEnumerate()
        {
            var configuration = new ApiConfiguration();
            var modelMapper   = new TestModelMapper();

            configuration.AddHookHandler <IModelMapper>(modelMapper);
            configuration.EnsureCommitted();
            var context = new ApiContext(configuration);

            var source = Api.Source <string>(context, "Test");

            Assert.Throws <NotSupportedException>(() => (source as IEnumerable).GetEnumerator());
        }