Exemplo n.º 1
0
        public void AddService_Single_ImplementationType_NullShouldThrow()
        {
            var    container  = new RestierContainerBuilder(typeof(TestableEmptyApi));
            Action addService = () => { container.AddService(ODataServiceLifetime.Scoped, typeof(DefaultSubmitHandler), implementationType: null); };

            addService.Should().Throw <ArgumentNullException>();
        }
        public void BuildContainer_HasServices()
        {
            var container = new RestierContainerBuilder();

            container.BuildContainer();
            container.Services.Should().HaveCount(1);
        }
Exemplo n.º 3
0
        public async Task ComplexTypeUpdate()
        {
            // Arrange
            var container  = new RestierContainerBuilder(typeof(LibraryApi));
            var provider   = container.BuildContainer();
            var libraryApi = provider.GetService <ApiBase>();

            var item = new DataModificationItem(
                "Readers",
                typeof(Person),
                null,
                RestierEntitySetOperation.Update,
                new Dictionary <string, object> {
                { "Id", new Guid("53162782-EA1B-4712-AF26-8AA1D2AC0461") }
            },
                new Dictionary <string, object>(),
                new Dictionary <string, object> {
                { "Addr", new Dictionary <string, object> {
                      { "Zip", "332" }
                  } }
            });
            var changeSet = new ChangeSet(new[] { item });
            var sc        = new SubmitContext(provider, changeSet);

            // Act
            var changeSetPreparer = libraryApi.GetApiService <IChangeSetInitializer>();
            await changeSetPreparer.InitializeAsync(sc, CancellationToken.None).ConfigureAwait(false);

            var person = item.Resource as Person;

            // Assert
            Assert.NotNull(person);
            Assert.Equal("332", person.Addr.Zip);
        }
        public void ConfigurationRegistersApiServicesCorrectly()
        {
            var container = new RestierContainerBuilder(typeof(TestApiA));
            var provider  = container.BuildContainer();
            var api       = provider.GetService <ApiBase>();

            Assert.Null(api.GetApiService <IServiceA>());
            Assert.Null(api.GetApiService <IServiceB>());

            container = new RestierContainerBuilder(typeof(TestApiB));
            var provider2 = container.BuildContainer();
            var apiB      = provider2.GetService <ApiBase>();

            Assert.Same(TestApiB.serviceA, apiB.GetApiService <IServiceA>());

            var serviceBInstance  = apiB.GetApiService <ServiceB>();
            var serviceBInterface = apiB.GetApiService <IServiceB>();

            Assert.Equal(serviceBInstance, serviceBInterface);

            // AddService will call services.TryAddTransient
            Assert.Same(serviceBInstance, serviceBInterface);

            var serviceBFirst = serviceBInterface as ServiceB;

            Assert.NotNull(serviceBFirst);

            Assert.Same(TestApiB.serviceB, serviceBFirst.InnerHandler);
        }
Exemplo n.º 5
0
        public async Task GetModelAsyncRetriableAfterFailure()
        {
            using (var wait = new ManualResetEventSlim(false))
            {
                var container = new RestierContainerBuilder(typeof(TestableEmptyApi));
                container.Services.AddRestierCoreServices(typeof(TestableEmptyApi))
                .AddChainedService <IModelBuilder>((sp, next) => new TestRetryModelBuilder());
                addTestServices(container.Services);

                var provider = container.BuildContainer();

                var tasks = PrepareThreads(6, provider, wait);
                wait.Set();

#pragma warning disable CA2008 // Do not create tasks without passing a TaskScheduler
                await Task.WhenAll(tasks).ContinueWith(t =>
                {
                    t.IsFaulted.Should().BeTrue();
                    tasks.All(e => e.IsFaulted).Should().BeTrue();
                });

#pragma warning restore CA2008 // Do not create tasks without passing a TaskScheduler

                tasks = PrepareThreads(150, provider, wait);

                var models = await Task.WhenAll(tasks);

                models.All(e => ReferenceEquals(e, models[42])).Should().BeTrue();
            }
        }
Exemplo n.º 6
0
        public async Task TestEntityFilterReturnsTask()
        {
            var container = new RestierContainerBuilder(typeof(TestEntityFilterReturnsTaskApi));
            var provider  = container.BuildContainer();
            var api       = provider.GetService <ApiBase>();

            DataModificationItem <Customer> createCustomer = new DataModificationItem <Customer>(
                "Customers",
                typeof(Customer),
                null,
                DataModificationItemAction.Insert,
                null,
                null,
                new Dictionary <string, object>()
            {
                { "CustomerID", "NEW01" },
                { "CompanyName", "New Cust" },
            });

            await api.SubmitAsync(new ChangeSet(new ChangeSetItem[] { createCustomer }));

            NorthwindContext ctx = new NorthwindContext();

#if EF7
            Customer newCustomer = await ctx.Customers.FirstOrDefaultAsync(e => e.CustomerID == "NEW01");
#else
            Customer newCustomer = await ctx.Customers.FindAsync("NEW01");
#endif
            // The "OnInserting" should have been appended by the OnInsertingCustomers filter
            Assert.Equal("New CustOnInserting", newCustomer.CompanyName);

            ctx.Customers.Remove(newCustomer);
            await ctx.SaveChangesAsync();
        }
Exemplo n.º 7
0
        public void GenericSourceOfComposableFunctionIsCorrect()
        {
            var container = new RestierContainerBuilder(typeof(TestApi));
            var provider  = container.BuildContainer();
            var api       = provider.GetService <ApiBase>();

            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());
        }
        public void Constructor_CreatesServiceCollection()
        {
            var container = new RestierContainerBuilder();

            container.Should().NotBeNull();
            container.Services.Should().NotBeNull().And.BeEmpty();
        }
        public void AddService_Single_ServiceType_NullShouldThrow()
        {
            var    container  = new RestierContainerBuilder();
            Action addService = () => { container.AddService(ODataServiceLifetime.Scoped, null, typeof(DefaultSubmitHandler)); };

            addService.Should().Throw <ArgumentNullException>();
        }
Exemplo n.º 10
0
        public void AddService_Factory_ServiceType_NullShouldThrow()
        {
            var    container  = new RestierContainerBuilder();
            Action addService = () => { container.AddService(ODataServiceLifetime.Scoped, null, (sp) => new DefaultSubmitExecutor()); };

            addService.Should().Throw <ArgumentNullException>();
        }
        public void ConfigurationRegistersApiServicesCorrectly()
        {
            var container = new RestierContainerBuilder(typeof(TestApiA));
            var provider = container.BuildContainer();
            var api = provider.GetService<ApiBase>();

            Assert.Null(api.Context.GetApiService<IServiceA>());
            Assert.Null(api.Context.GetApiService<IServiceB>());

            container = new RestierContainerBuilder(typeof(TestApiB));
            var provider2 = container.BuildContainer();
            var apiB = provider2.GetService<ApiBase>();

            Assert.Same(TestApiB.serviceA, apiB.Context.GetApiService<IServiceA>());

            var serviceBInstance = apiB.Context.GetApiService<ServiceB>();
            var serviceBInterface = apiB.Context.GetApiService<IServiceB>();
            Assert.Equal(serviceBInstance, serviceBInterface);

            // AddService will call services.TryAddTransient
            Assert.Same(serviceBInstance, serviceBInterface);

            var serviceBFirst = serviceBInterface as ServiceB;
            Assert.NotNull(serviceBFirst);

            Assert.Same(TestApiB.serviceB, serviceBFirst.InnerHandler);
        }
Exemplo n.º 12
0
        public void AddService_Factory_ImplementationFactory_NullShouldThrow()
        {
            var    container  = new RestierContainerBuilder();
            Action addService = () => { container.AddService(ODataServiceLifetime.Scoped, typeof(DefaultSubmitHandler), implementationFactory: null); };

            addService.Should().Throw <ArgumentNullException>();
        }
Exemplo n.º 13
0
 public void DefaultApiBaseCanBeCreatedAndDisposed()
 {
     var container = new RestierContainerBuilder(typeof(TestApi));
     var provider = container.BuildContainer();
     var api = provider.GetService<ApiBase>();
     api.Dispose();
 }
Exemplo n.º 14
0
        public void BuildContainer_HasServices()
        {
            var container = new RestierContainerBuilder(typeof(TestableEmptyApi));

            container.BuildContainer();
            container.Services.Should().HaveCount(1);
        }
Exemplo n.º 15
0
        public void InvocationContextGetsApiServicesCorrectly()
        {
            var container = new RestierContainerBuilder(typeof(TestApi));
            var provider  = container.BuildContainer();
            var context   = new InvocationContext(provider);

            Assert.Same(TestApi.ApiService, context.GetApiService <IServiceA>());
        }
Exemplo n.º 16
0
        public void InvocationContext_GetsApiServicesCorrectly()
        {
            var container = new RestierContainerBuilder(typeof(TestApi));
            var provider  = container.BuildContainer();
            var context   = new InvocationContext(provider);

            context.GetApiService <IServiceA>().Should().BeSameAs(TestApi.ApiService);
        }
Exemplo n.º 17
0
        public void ThrowOnNoServiceFound()
        {
            var container = new RestierContainerBuilder(typeof(TestApiH));
            var provider  = container.BuildContainer();
            var api       = provider.GetService <ApiBase>();

            Assert.Throws <InvalidOperationException>(() => { api.GetApiService <ISomeService>(); });
        }
Exemplo n.º 18
0
        public void NewApiContextIsConfiguredCorrectly()
        {
            var container = new RestierContainerBuilder(typeof(TestApi));
            var provider  = container.BuildContainer();
            var api       = provider.GetService <ApiBase>();

            Assert.NotNull(api);
        }
Exemplo n.º 19
0
        public void DefaultApiBaseCanBeCreatedAndDisposed()
        {
            var container = new RestierContainerBuilder(typeof(TestApi));
            var provider  = container.BuildContainer();
            var api       = provider.GetService <ApiBase>();

            api.Dispose();
        }
        public void ServiceChainTest()
        {
            var container = new RestierContainerBuilder(typeof(TestApiC));
            var provider = container.BuildContainer();
            var api = provider.GetService<ApiBase>();

            var handler = api.Context.GetApiService<IServiceB>();
            Assert.Equal("q2Pre_q1Pre_q1Post_q2Post_", handler.GetStr());
        }
Exemplo n.º 21
0
        public void NewApiContextIsConfiguredCorrectly()
        {
            var container = new RestierContainerBuilder(typeof(TestApi));
            var provider = container.BuildContainer();
            var api = provider.GetService<ApiBase>();

            var context = api.Context;
            Assert.NotNull(context.Configuration);
        }
 public void InvocationContextGetsApiServicesCorrectly()
 {
     var container = new RestierContainerBuilder(typeof(TestApi));
     var provider = container.BuildContainer();
     var api = provider.GetService<ApiBase>();
     var apiContext = api.Context;
     var context = new InvocationContext(apiContext);
     Assert.Same(TestApi.ApiService, context.GetApiService<IServiceA>());
 }
Exemplo n.º 23
0
        public void ContributorsAreCalledCorrectly()
        {
            var container = new RestierContainerBuilder(typeof(TestApiA));
            var provider  = container.BuildContainer();
            var api       = provider.GetService <ApiBase>();
            var value     = api.GetApiService <ISomeService>().Call();

            Assert.Equal("03210", value);
        }
Exemplo n.º 24
0
        public void DifferentPropertyBagsDoNotConflict()
        {
            var container = new RestierContainerBuilder(typeof(TestApi));
            var provider  = container.BuildContainer();
            var api       = provider.GetService <ApiBase>();

            api.SetProperty("Test", 2);
            Assert.Equal(2, api.GetProperty <int>("Test"));
        }
Exemplo n.º 25
0
        public void GenericSourceOfEntityContainerElementThrowsIfWrongType()
        {
            var container = new RestierContainerBuilder(typeof(TestApi));
            var provider  = container.BuildContainer();
            var api       = provider.GetService <ApiBase>();
            var arguments = new object[0];

            Assert.Throws <ArgumentException>(() => api.GetQueryableSource <object>("Test", arguments));
        }
Exemplo n.º 26
0
        public void InvocationContext_IsConfiguredCorrectly()
        {
            var container = new RestierContainerBuilder(typeof(TestApi));
            var provider  = container.BuildContainer();
            var api       = provider.GetService <ApiBase>();
            var context   = new InvocationContext(provider);

            context.GetApiService <ApiBase>().Should().BeSameAs(api);
        }
Exemplo n.º 27
0
        public void SourceOfComposableFunctionThrowsIfNotMapped()
        {
            var container = new RestierContainerBuilder(typeof(TestApiEmpty));
            var provider  = container.BuildContainer();
            var api       = provider.GetService <ApiBase>();
            var arguments = new object[0];

            Assert.Throws <NotSupportedException>(() => api.GetQueryableSource("Namespace", "Function", arguments));
        }
 public void NewInvocationContextIsConfiguredCorrectly()
 {
     var container = new RestierContainerBuilder(typeof(TestApi));
     var provider = container.BuildContainer();
     var api = provider.GetService<ApiBase>();
     var apiContext = api.Context;
     var context = new InvocationContext(apiContext);
     Assert.Same(apiContext, context.ApiContext);
 }
Exemplo n.º 29
0
        public void NewInvocationContextIsConfiguredCorrectly()
        {
            var container = new RestierContainerBuilder(typeof(TestApi));
            var provider  = container.BuildContainer();
            var api       = provider.GetService <ApiBase>();
            var context   = new InvocationContext(provider);

            Assert.Same(api, context.GetApiService <ApiBase>());
        }
Exemplo n.º 30
0
        public void DifferentPropertyBagsDoNotConflict()
        {
            var container = new RestierContainerBuilder(typeof(TestApi));
            var provider = container.BuildContainer();
            var api = provider.GetService<ApiBase>();

            var context = api.Context;
            context.SetProperty("Test", 2);
            Assert.Equal(2, context.GetProperty<int>("Test"));
        }
Exemplo n.º 31
0
        public void ConventionBasedMethodNameFactory_ExecuteMethod_Authorize()
        {
            var container = new RestierContainerBuilder(typeof(TestApi));
            var provider  = container.BuildContainer();

            var context = new OperationContext((string test) => { return(null); }, "TestMethod", null, true, null, provider);
            var name    = ConventionBasedMethodNameFactory.GetFunctionMethodName(context, RestierPipelineState.Authorization, RestierOperationMethod.Execute);

            Assert.Equal("CanExecuteTestMethod", name);
        }
Exemplo n.º 32
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        private RestierContainerBuilder GetContainerBuilder()
        {
            var container = new RestierContainerBuilder();

            container.Services
            .AddRestierCoreServices()
            .AddRestierConventionBasedServices(typeof(LibraryApi))
            .AddRestierDefaultServices();
            return(container);
        }
Exemplo n.º 33
0
        public void ServiceChainTest()
        {
            var container = new RestierContainerBuilder(typeof(TestApiC));
            var provider  = container.BuildContainer();
            var api       = provider.GetService <ApiBase>();

            var handler = api.GetApiService <IServiceB>();

            Assert.Equal("q2Pre_q1Pre_q1Post_q2Post_", handler.GetStr());
        }
Exemplo n.º 34
0
        public async Task ApiSubmitAsyncCorrectlyForwardsCall()
        {
            var container = new RestierContainerBuilder(typeof(TestApi));
            var provider  = container.BuildContainer();
            var api       = provider.GetService <ApiBase>();

            var submitResult = await api.SubmitAsync();

            Assert.NotNull(submitResult.CompletedChangeSet);
        }
Exemplo n.º 35
0
        public void SourceQueryProviderCannotExecute()
        {
            var container = new RestierContainerBuilder(typeof(TestApi));
            var provider  = container.BuildContainer();
            var api       = provider.GetService <ApiBase>();

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

            Assert.Throws <NotSupportedException>(() => source.Provider.Execute(null));
        }
Exemplo n.º 36
0
        public void ApiAndApiContextCanBeInjectedByDI()
        {
            var container = new RestierContainerBuilder(typeof(TestApi));
            var provider  = container.BuildContainer();
            var api       = provider.GetService <ApiBase>();

            var svc = api.GetApiService <IService>();

            Assert.Same(svc.Api, api);
        }
Exemplo n.º 37
0
        public void SourceQueryableCannotEnumerate()
        {
            var container = new RestierContainerBuilder(typeof(TestApi));
            var provider  = container.BuildContainer();
            var api       = provider.GetService <ApiBase>();

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

            Assert.Throws <NotSupportedException>(() => (source as IEnumerable).GetEnumerator());
        }
        public void CachedConfigurationIsCachedCorrectly()
        {
            var container = new RestierContainerBuilder(typeof(TestApiA));
            var provider = container.BuildContainer();
            var api = provider.GetService<ApiBase>();

            var configuration = api.Context.Configuration;

            ApiBase anotherApi = provider.GetService<ApiBase>();
            var cached = anotherApi.Context.Configuration;
            Assert.Same(configuration, cached);
        }
Exemplo n.º 39
0
        public void ApiAndApiContextCanBeInjectedByDI()
        {
            var container = new RestierContainerBuilder(typeof(TestApi));
            var provider = container.BuildContainer();
            var api = provider.GetService<ApiBase>();

            var context = api.Context;
            var svc = context.GetApiService<IService>();

            Assert.Same(svc.Api, api);
            Assert.Same(svc.Context, context);

            api.Dispose();
            Assert.Throws<ObjectDisposedException>(() => api.Context);
        }
Exemplo n.º 40
0
        public void PropertyBagsAreDisposedCorrectly()
        {
            var container = new RestierContainerBuilder(typeof(TestApi));
            var provider = container.BuildContainer();
            var scope = provider.GetRequiredService<IServiceScopeFactory>().CreateScope();
            var scopedProvider  = scope.ServiceProvider;
            var api = scopedProvider.GetService<ApiBase>();
            var context = api.Context;

            Assert.NotNull(context.GetApiService<MyPropertyBag>());
            Assert.Equal(1, MyPropertyBag.InstanceCount);

            var scopedProvider2 = provider.GetRequiredService<IServiceScopeFactory>().CreateScope().ServiceProvider;
            var api2 = scopedProvider2.GetService<ApiBase>();
            var context2 = api2.Context;

            Assert.NotNull(context2.GetApiService<MyPropertyBag>());
            Assert.Equal(2, MyPropertyBag.InstanceCount);

            scope.Dispose();

            Assert.Equal(1, MyPropertyBag.InstanceCount);
        }
Exemplo n.º 41
0
        public void PropertyBagManipulatesPropertiesCorrectly()
        {
            var container = new RestierContainerBuilder(typeof(TestApi));
            var provider = container.BuildContainer();
            var api = provider.GetService<ApiBase>();
            var context =api.Context;

            Assert.False(context.HasProperty("Test"));
            Assert.Null(context.GetProperty("Test"));
            Assert.Null(context.GetProperty<string>("Test"));
            Assert.Equal(default(int), context.GetProperty<int>("Test"));

            context.SetProperty("Test", "Test");
            Assert.True(context.HasProperty("Test"));
            Assert.Equal("Test", context.GetProperty("Test"));
            Assert.Equal("Test", context.GetProperty<string>("Test"));

            context.ClearProperty("Test");
            Assert.False(context.HasProperty("Test"));
            Assert.Null(context.GetProperty("Test"));
            Assert.Null(context.GetProperty<string>("Test"));
            Assert.Equal(default(int), context.GetProperty<int>("Test"));
        }
        public void ThrowOnNoServiceFound()
        {
            var container = new RestierContainerBuilder(typeof(TestApiH));
            var provider = container.BuildContainer();
            var api = provider.GetService<ApiBase>();

            Assert.Throws<InvalidOperationException>(() => { api.Context.GetApiService<ISomeService>(); });
        }
Exemplo n.º 43
0
        public void GenericApiSourceOfEntityContainerElementIsCorrect()
        {
            var container = new RestierContainerBuilder(typeof(TestApi));
            var provider = container.BuildContainer();
            var api = provider.GetService<ApiBase>();

            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());
        }
        public async Task GetModelAsyncRetriableAfterFailure()
        {
            using (var wait = new ManualResetEventSlim(false))
            {
                var container = new RestierContainerBuilder(typeof(TestApiC));
                var provider = container.BuildContainer();

                var tasks = PrepareThreads(6, provider, wait);
                wait.Set();

                await Task.WhenAll(tasks).ContinueWith(t =>
                {
                    Assert.True(t.IsFaulted);
                    Assert.True(tasks.All(e => e.IsFaulted));
                });

                tasks = PrepareThreads(150, provider, wait);

                var models = await Task.WhenAll(tasks);
                Assert.True(models.All(e => object.ReferenceEquals(e, models[42])));
            }
        }
        public async Task ModelBuilderShouldBeCalledOnlyOnceIfSucceeded()
        {
            using (var wait = new ManualResetEventSlim(false))
            {
                for (int i = 0; i < 2; i++)
                {
                    var container = new RestierContainerBuilder(typeof(TestApiB));
                    var provider = container.BuildContainer();
                    var tasks = PrepareThreads(50, provider, wait);
                    wait.Set();

                    var models = await Task.WhenAll(tasks);
                    Assert.True(models.All(e => object.ReferenceEquals(e, models[42])));
                }
            }
        }
        public async Task GetModelUsingDefaultModelHandler()
        {
            var container = new RestierContainerBuilder(typeof(TestApiA));
            var provider = container.BuildContainer();
            var api = provider.GetService<ApiBase>();
            var context = api.Context;

            var model = await context.GetModelAsync();
            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 ContributorsAreCalledCorrectly()
 {
     var container = new RestierContainerBuilder(typeof(TestApiA));
     var provider = container.BuildContainer();
     var api = provider.GetService<ApiBase>();
     var value = api.Context.GetApiService<ISomeService>().Call();
     Assert.Equal("03210", value);
 }
Exemplo n.º 48
0
        public async Task ApiQueryAsyncWithQueryReturnsResults()
        {
            var container = new RestierContainerBuilder(typeof(TestApi));
            var provider = container.BuildContainer();
            var api = provider.GetService<ApiBase>();

            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"}));
        }
        public void MultiInjectionViaConstructor()
        {
            var container = new RestierContainerBuilder(typeof(TestApiG));
            var provider = container.BuildContainer();
            var api = provider.GetService<ApiBase>();

            var value = api.Context.GetApiService<ISomeService>().Call();
            Assert.Equal("0122", value);

            // Test expression compilation
            value = api.Context.GetApiService<ISomeService>().Call();
            Assert.Equal("0122", value);
            value = api.Context.GetApiService<ISomeService>().Call();
            Assert.Equal("0122", value);
        }
        public void DefaultValueInConstructorUsedIfNoService()
        {
            var container = new RestierContainerBuilder(typeof(TestApiF));
            var provider = container.BuildContainer();
            var api = provider.GetService<ApiBase>();

            var value = api.Context.GetApiService<ISomeService>().Call();
            Assert.Equal("42", value);

            value = api.Context.GetApiService<ISomeService>().Call();
            Assert.Equal("42", value);
            value = api.Context.GetApiService<ISomeService>().Call();
            Assert.Equal("42", value);
        }
        public void ServiceInjectedViaProperty()
        {
            var container = new RestierContainerBuilder(typeof(TestApiE));
            var provider = container.BuildContainer();
            var api = provider.GetService<ApiBase>();

            var expected = "Text42";
            var value = api.Context.GetApiService<ISomeService>().Call();
            Assert.Equal(expected, value);

            value = api.Context.GetApiService<ISomeService>().Call();
            Assert.Equal(expected, value);

            value = api.Context.GetApiService<ISomeService>().Call();
            Assert.Equal(expected, value);

            Assert.NotEqual(
                api.Context.GetApiService<ISomeService>(),
                api.Context.GetApiService<ISomeService>());
        }
Exemplo n.º 52
0
        public async Task ApiSubmitAsyncCorrectlyForwardsCall()
        {
            var container = new RestierContainerBuilder(typeof(TestApi));
            var provider = container.BuildContainer();
            var api = provider.GetService<ApiBase>();

            var submitResult = await api.SubmitAsync();
            Assert.NotNull(submitResult.CompletedChangeSet);
        }
        public void NextInjectedWithInheritedField()
        {
            var container = new RestierContainerBuilder(typeof(TestApiI));
            var provider = container.BuildContainer();
            var api = provider.GetService<ApiBase>();

            var value = api.Context.GetApiService<ISomeService>().Call();
            Assert.Equal("4200", value);

            // Test expression compilation
            value = api.Context.GetApiService<ISomeService>().Call();
            Assert.Equal("4200", value);
            value = api.Context.GetApiService<ISomeService>().Call();
            Assert.Equal("4200", value);
        }
Exemplo n.º 54
0
        public void SourceQueryProviderCannotExecute()
        {
            var container = new RestierContainerBuilder(typeof(TestApi));
            var provider = container.BuildContainer();
            var api = provider.GetService<ApiBase>();
            var context = api.Context;

            var source = context.GetQueryableSource<string>("Test");
            Assert.Throws<NotSupportedException>(() => source.Provider.Execute(null));
        }
Exemplo n.º 55
0
        public void GenericSourceOfComposableFunctionIsCorrect()
        {
            var container = new RestierContainerBuilder(typeof(TestApi));
            var provider = container.BuildContainer();
            var api = provider.GetService<ApiBase>();
            var context = api.Context;
            var arguments = new object[0];

            var source = context.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());
        }
        public void NothingInjectedStillWorks()
        {
            // Outmost service does not call inner service
            var container = new RestierContainerBuilder(typeof(TestApiD));
            var provider = container.BuildContainer();
            var api = provider.GetService<ApiBase>();

            var value = api.Context.GetApiService<ISomeService>().Call();
            Assert.Equal("42", value);

            // Test expression compilation.
            value = api.Context.GetApiService<ISomeService>().Call();
            Assert.Equal("42", value);
            value = api.Context.GetApiService<ISomeService>().Call();
            Assert.Equal("42", value);
        }
        public void NextInjectedViaProperty()
        {
            var container = new RestierContainerBuilder(typeof(TestApiB));
            var provider = container.BuildContainer();
            var api = provider.GetService<ApiBase>();
            var value = api.Context.GetApiService<ISomeService>().Call();
            Assert.Equal("01", value);

            // Test expression compilation.
            value = api.Context.GetApiService<ISomeService>().Call();
            Assert.Equal("01", value);
        }
Exemplo n.º 58
0
        public async Task ApiQueryAsyncCorrectlyForwardsCall()
        {
            var container = new RestierContainerBuilder(typeof(TestApi));
            var provider = container.BuildContainer();
            var api = provider.GetService<ApiBase>();

            var queryRequest = new QueryRequest(
                api.GetQueryableSource<string>("Test"));
            var queryResult = await api.QueryAsync(queryRequest);
            Assert.True(queryResult.Results.Cast<string>()
                .SequenceEqual(new[] {"Test"}));
        }
        public void ContextApiScopeWorksCorrectly()
        {
            var container = new RestierContainerBuilder(typeof(TestApiC));
            var provider = container.BuildContainer();
            var api = provider.GetService<ApiBase>();

            var service1 = api.Context.GetApiService<ISomeService>();
            
            container = new RestierContainerBuilder(typeof(TestApiC));
            provider = container.BuildContainer();
            var api2 = provider.GetService<ApiBase>();

            var service2 = api2.Context.GetApiService<ISomeService>();

            Assert.NotEqual(service1, service2);

            container = new RestierContainerBuilder(typeof(TestApiC));
            provider = container.BuildContainer();
            var api3 = provider.GetService<ApiBase>();
            var service3 = api3.Context.GetApiService<ISomeService>();

            Assert.NotEqual(service3, service2);
        }
Exemplo n.º 60
0
        public void GenericSourceOfComposableFunctionThrowsIfWrongType()
        {
            var container = new RestierContainerBuilder(typeof(TestApi));
            var provider = container.BuildContainer();
            var api = provider.GetService<ApiBase>();

            var context = api.Context;
            var arguments = new object[0];

            Assert.Throws<ArgumentException>(() => context.GetQueryableSource<object>("Namespace", "Function", arguments));
        }