public void NewInvocationContextIsConfiguredCorrectly()
 {
     var configuration = new DomainConfiguration();
     configuration.EnsureCommitted();
     var domainContext = new DomainContext(configuration);
     var context = new InvocationContext(domainContext);
     Assert.Same(domainContext, context.DomainContext);
 }
Beispiel #2
0
        public void CommittedConfigurationIsConfiguredCorrectly()
        {
            var configuration = new DomainConfiguration();

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

            configuration.EnsureCommitted();
            Assert.True(configuration.IsCommitted);
        }
        public void ExtendModelAsync_UpdatesModel_IfHasOnModelCreatingMethod(Type type)
        {
            // Arrange
            var domain = Activator.CreateInstance(type);
            var extender = new ConventionalModelExtender(type);
            var domainConfig = new DomainConfiguration();
            domainConfig.EnsureCommitted();
            var domainContext = new DomainContext(domainConfig);
            domainContext.SetProperty(type.AssemblyQualifiedName, domain);
            var model = GetModel();
            var context = new ModelContext(domainContext) { Model = model };

            // Act
            extender.ExtendModelAsync(context, new CancellationToken());

            // Assert
            Assert.Same(model, context.Model);
            var operations = model.SchemaElements.OfType<IEdmOperation>();
            Assert.Single(operations);
            var operation = operations.Single();
            Assert.True(operation.IsBound);
            Assert.True(operation.IsFunction());
            Assert.Equal("MostExpensive", operation.Name);
            Assert.Equal("ns", operation.Namespace);
        }
Beispiel #4
0
        public async Task GetModelUsingDefaultModelHandler()
        {
            var configuration = new DomainConfiguration();

            configuration.SetHookPoint(
                typeof(IModelProducer), new TestModelProducer());
            configuration.AddHookPoint(
                typeof(IModelExtender), new TestModelExtender(2));
            configuration.AddHookPoint(
                typeof(IModelExtender), new TestModelExtender(3));
            configuration.AddHookPoint(
                typeof(IModelVisibilityFilter),
                new TestModelVisibilityFilter());
            configuration.EnsureCommitted();
            var context = new DomainContext(configuration);

            var model = await Domain.GetModelAsync(context);

            Assert.Equal(3, model.SchemaElements.Count());
            Assert.Null(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.Null(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"));
        }
Beispiel #5
0
        public void ExtendModelAsync_DoesntUpdatesModel_IfWithoutOnModelCreatingMethod()
        {
            // Arrange
            var domain       = new AnyDomain();
            var type         = domain.GetType();
            var extender     = new ConventionalModelExtender(type);
            var domainConfig = new DomainConfiguration();

            domainConfig.EnsureCommitted();
            var domainContext = new DomainContext(domainConfig);

            domainContext.SetProperty(type.AssemblyQualifiedName, domain);
            var model   = GetModel();
            var context = new ModelContext(domainContext)
            {
                Model = model
            };

            // Act
            extender.ExtendModelAsync(context, new CancellationToken());

            // Assert
            Assert.Same(model, context.Model);
            Assert.Empty(model.SchemaElements.OfType <IEdmOperation>());
        }
Beispiel #6
0
        public void ExtendModelAsync_UpdatesModel_IfHasOnModelCreatingMethod(Type type)
        {
            // Arrange
            var domain       = Activator.CreateInstance(type);
            var extender     = new ConventionalModelExtender(type);
            var domainConfig = new DomainConfiguration();

            domainConfig.EnsureCommitted();
            var domainContext = new DomainContext(domainConfig);

            domainContext.SetProperty(type.AssemblyQualifiedName, domain);
            var model   = GetModel();
            var context = new ModelContext(domainContext)
            {
                Model = model
            };

            // Act
            extender.ExtendModelAsync(context, new CancellationToken());

            // Assert
            Assert.Same(model, context.Model);
            var operations = model.SchemaElements.OfType <IEdmOperation>();

            Assert.Single(operations);
            var operation = operations.Single();

            Assert.True(operation.IsBound);
            Assert.True(operation.IsFunction());
            Assert.Equal("MostExpensive", operation.Name);
            Assert.Equal("ns", operation.Namespace);
        }
Beispiel #7
0
        public void DerivedConfigurationCannotCommitWithUncommittedBase()
        {
            var baseConfig    = new DomainConfiguration();
            var derivedConfig = new DomainConfiguration(baseConfig);

            Assert.Throws <InvalidOperationException>(() => derivedConfig.EnsureCommitted());
        }
Beispiel #8
0
        public void GenericSourceOfComposableFunctionIsCorrect()
        {
            var configuration = new DomainConfiguration();
            var modelMapper   = new TestModelMapper();

            configuration.SetHookPoint(typeof(IModelMapper), modelMapper);
            configuration.EnsureCommitted();
            var context   = new DomainContext(configuration);
            var arguments = new object[0];

            var source = Domain.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(DomainData), 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());
        }
Beispiel #9
0
        public void SourceOfEntityContainerElementIsCorrect()
        {
            var configuration = new DomainConfiguration();
            var modelMapper   = new TestModelMapper();

            configuration.AddHookPoint(typeof(IModelMapper), modelMapper);
            configuration.EnsureCommitted();
            var context   = new DomainContext(configuration);
            var arguments = new object[0];

            var source = Domain.Source(context, "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(DomainData), methodCall.Method.DeclaringType);
            Assert.Equal("Source", 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());
        }
Beispiel #10
0
        public async Task QueryAsyncCorrectlyUsesQueryHandler()
        {
            var configuration = new DomainConfiguration();
            var modelHandler  = new TestModelHandler();
            var modelMapper   = new TestModelMapper();
            var queryHandler  = new TestQueryHandler();

            configuration.SetHookPoint(typeof(IModelHandler), modelHandler);
            configuration.SetHookPoint(typeof(IModelMapper), modelMapper);
            configuration.SetHookPoint(typeof(IQueryHandler), queryHandler);
            configuration.EnsureCommitted();
            var context = new DomainContext(configuration);

            modelHandler.DomainContext = context;
            modelHandler.Model         = new EdmModel();
            queryHandler.DomainContext = context;
            queryHandler.Results       = new string[] { "Test" };

            var queryRequest = new QueryRequest(
                Domain.Source <string>(context, "Test"), true);
            var queryResult = await Domain.QueryAsync(context, queryRequest);

            Assert.True(queryResult.Results.Cast <string>()
                        .SequenceEqual(new string[] { "Test" }));
        }
Beispiel #11
0
        public void CommittedConfigurationCannotAddHookPoint()
        {
            var configuration = new DomainConfiguration();

            configuration.EnsureCommitted();

            Assert.Throws <InvalidOperationException>(() => configuration.AddHookPoint(typeof(object), new object()));
        }
Beispiel #12
0
        public void NewDomainContextIsConfiguredCorrectly()
        {
            var configuration = new DomainConfiguration();

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

            Assert.Same(configuration, context.Configuration);
        }
Beispiel #13
0
        public void SourceOfComposableFunctionThrowsIfNotMapped()
        {
            var configuration = new DomainConfiguration();

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

            Assert.Throws <NotSupportedException>(() => Domain.Source(context, "Namespace", "Function", arguments));
        }
Beispiel #14
0
        public void SourceOfEntityContainerElementThrowsIfNotMapped()
        {
            var configuration = new DomainConfiguration();

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

            Assert.Throws <NotSupportedException>(() => Domain.Source(context, "Test", arguments));
        }
Beispiel #15
0
        public void GenericSourceOfComposableFunctionThrowsIfWrongType()
        {
            var configuration = new DomainConfiguration();
            var modelMapper   = new TestModelMapper();

            configuration.SetHookPoint(typeof(IModelMapper), modelMapper);
            configuration.EnsureCommitted();
            var context   = new DomainContext(configuration);
            var arguments = new object[0];

            Assert.Throws <ArgumentException>(() => Domain.Source <object>(context, "Namespace", "Function", arguments));
        }
Beispiel #16
0
        public void SourceQueryProviderCannotExecute()
        {
            var configuration = new DomainConfiguration();
            var modelMapper   = new TestModelMapper();

            configuration.SetHookPoint(typeof(IModelMapper), modelMapper);
            configuration.EnsureCommitted();
            var context = new DomainContext(configuration);

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

            Assert.Throws <NotSupportedException>(() => source.Provider.Execute(null));
        }
Beispiel #17
0
        public void SourceQueryableCannotEnumerate()
        {
            var configuration = new DomainConfiguration();
            var modelMapper   = new TestModelMapper();

            configuration.SetHookPoint(typeof(IModelMapper), modelMapper);
            configuration.EnsureCommitted();
            var context = new DomainContext(configuration);

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

            Assert.Throws <NotSupportedException>(() => (source as IEnumerable).GetEnumerator());
        }
Beispiel #18
0
        public void ExpandedDomainBaseIsInitializedCorrectly()
        {
            var domain           = new TestDomain();
            var expandableDomain = domain as IExpandableDomain;
            var derivedConfig    = new DomainConfiguration(
                expandableDomain.Configuration);

            derivedConfig.EnsureCommitted();

            expandableDomain.Initialize(derivedConfig);
            Assert.True(expandableDomain.IsInitialized);
            Assert.Same(derivedConfig,
                        expandableDomain.Context.Configuration);
        }
        public void InvocationContextGetsHookPointsCorrectly()
        {
            var configuration = new DomainConfiguration();
            var singletonHookPoint = new object();
            configuration.SetHookPoint(typeof(object), singletonHookPoint);
            var multiCastHookPoint = new object();
            configuration.AddHookPoint(typeof(object), multiCastHookPoint);
            configuration.EnsureCommitted();

            var domainContext = new DomainContext(configuration);
            var context = new InvocationContext(domainContext);

            Assert.Same(singletonHookPoint, context.GetHookPoint<object>());
            Assert.True(context.GetHookPoints<object>()
                .SequenceEqual(new object[] { multiCastHookPoint }));
        }
        public void InvocationContextGetsHookPointsCorrectly()
        {
            var configuration      = new DomainConfiguration();
            var singletonHookPoint = new object();

            configuration.SetHookPoint(typeof(object), singletonHookPoint);
            var multiCastHookPoint = new object();

            configuration.AddHookPoint(typeof(object), multiCastHookPoint);
            configuration.EnsureCommitted();

            var domainContext = new DomainContext(configuration);
            var context       = new InvocationContext(domainContext);

            Assert.Same(singletonHookPoint, context.GetHookPoint <object>());
            Assert.True(context.GetHookPoints <object>()
                        .SequenceEqual(new object[] { multiCastHookPoint }));
        }
        public void ExtendModelAsync_DoesntUpdatesModel_IfWithoutOnModelCreatingMethod()
        {
            // Arrange
            var domain = new AnyDomain();
            var type = domain.GetType();
            var extender = new ConventionalModelExtender(type);
            var domainConfig = new DomainConfiguration();
            domainConfig.EnsureCommitted();
            var domainContext = new DomainContext(domainConfig);
            domainContext.SetProperty(type.AssemblyQualifiedName, domain);
            var model = GetModel();
            var context = new ModelContext(domainContext) { Model = model };

            // Act
            extender.ExtendModelAsync(context, new CancellationToken());

            // Assert
            Assert.Same(model, context.Model);
            Assert.Empty(model.SchemaElements.OfType<IEdmOperation>());
        }
Beispiel #22
0
        public async Task GetModelAsyncCorrectlyUsesModelHandler()
        {
            var configuration = new DomainConfiguration();
            var modelHandler  = new TestModelHandler();

            configuration.SetHookPoint(typeof(IModelHandler), modelHandler);
            configuration.EnsureCommitted();
            var context = new DomainContext(configuration);

            modelHandler.DomainContext = context;
            modelHandler.Model         = new EdmModel();

            var domainModel = await Domain.GetModelAsync(context);

            var domainModelType = typeof(Domain).Assembly.GetType(
                "Microsoft.Restier.Core.Model.DomainModel");

            Assert.True(domainModelType.IsAssignableFrom(domainModel.GetType()));
            Assert.Same(modelHandler.Model, domainModelType
                        .GetProperty("InnerModel").GetValue(domainModel));
        }
Beispiel #23
0
        public async Task SubmitAsyncCorrectlyUsesSubmitHandler()
        {
            var configuration = new DomainConfiguration();
            var modelHandler  = new TestModelHandler();
            var modelMapper   = new TestModelMapper();
            var submitHandler = new TestSubmitHandler();

            configuration.SetHookPoint(typeof(IModelHandler), modelHandler);
            configuration.SetHookPoint(typeof(IModelMapper), modelMapper);
            configuration.SetHookPoint(typeof(ISubmitHandler), submitHandler);
            configuration.EnsureCommitted();
            var context = new DomainContext(configuration);

            modelHandler.DomainContext  = context;
            modelHandler.Model          = new EdmModel();
            submitHandler.DomainContext = context;
            submitHandler.ChangeSet     = new ChangeSet();

            var submitResult = await Domain.SubmitAsync(context);

            Assert.Same(submitHandler.ChangeSet,
                        submitResult.CompletedChangeSet);
        }
        public async Task GetModelUsingDefaultModelHandler()
        {
            var configuration = new DomainConfiguration();
            configuration.SetHookPoint(
                typeof(IModelProducer), new TestModelProducer());
            configuration.AddHookPoint(
                typeof(IModelExtender), new TestModelExtender(2));
            configuration.AddHookPoint(
                typeof(IModelExtender), new TestModelExtender(3));
            configuration.AddHookPoint(
                typeof(IModelVisibilityFilter),
                new TestModelVisibilityFilter());
            configuration.EnsureCommitted();
            var context = new DomainContext(configuration);

            var model = await Domain.GetModelAsync(context);
            Assert.Equal(3, model.SchemaElements.Count());
            Assert.Null(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.Null(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"));
        }
Beispiel #25
0
        public void ExpandedDomainBaseIsInitializedCorrectly()
        {
            var domain = new TestDomain();
            var expandableDomain = domain as IExpandableDomain;
            var derivedConfig = new DomainConfiguration(
                expandableDomain.Configuration);
            derivedConfig.EnsureCommitted();

            expandableDomain.Initialize(derivedConfig);
            Assert.True(expandableDomain.IsInitialized);
            Assert.Same(derivedConfig,
                expandableDomain.Context.Configuration);
        }