public void NewInvocationContextIsConfiguredCorrectly() { var configuration = new DomainConfiguration(); configuration.EnsureCommitted(); var domainContext = new DomainContext(configuration); var context = new InvocationContext(domainContext); Assert.Same(domainContext, context.DomainContext); }
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); }
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")); }
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>()); }
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); }
public void DerivedConfigurationCannotCommitWithUncommittedBase() { var baseConfig = new DomainConfiguration(); var derivedConfig = new DomainConfiguration(baseConfig); Assert.Throws <InvalidOperationException>(() => derivedConfig.EnsureCommitted()); }
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()); }
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()); }
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" })); }
public void CommittedConfigurationCannotAddHookPoint() { var configuration = new DomainConfiguration(); configuration.EnsureCommitted(); Assert.Throws <InvalidOperationException>(() => configuration.AddHookPoint(typeof(object), new object())); }
public void NewDomainContextIsConfiguredCorrectly() { var configuration = new DomainConfiguration(); configuration.EnsureCommitted(); var context = new DomainContext(configuration); Assert.Same(configuration, context.Configuration); }
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)); }
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)); }
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)); }
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)); }
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()); }
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>()); }
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)); }
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")); }
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); }