Пример #1
0
        protected override StorageProvider CreateStorageProvider(
            IPersistenceExtension persistenceExtension,
            RdbmsProviderDefinition storageProviderDefinition,
            IStorageProviderCommandFactory <IRdbmsProviderCommandExecutionContext> commandFactory)
        {
            ArgumentUtility.CheckNotNull("persistenceExtension", persistenceExtension);
            ArgumentUtility.CheckNotNull("storageProviderDefinition", storageProviderDefinition);
            ArgumentUtility.CheckNotNull("commandFactory", commandFactory);

            return(ObjectFactory.Create <SecurityManagerRdbmsProvider> (
                       ParamList.Create(
                           storageProviderDefinition,
                           persistenceExtension,
                           commandFactory,
                           (Func <IDbConnection>)(() => new SqlConnection()))));
        }
Пример #2
0
        public void InstantiateAssembledType_WithExactAssembledType()
        {
            var assembledType  = ReflectionObjectMother.GetSomeType();
            var arguments      = ParamList.Create("abc", 7);
            var allowNonPublic = BooleanObjectMother.GetRandomBoolean();

            _constructorForAssembledTypeCacheMock
            .Setup(mock => mock.GetOrCreateConstructorCall(assembledType, arguments.FuncType, allowNonPublic))
            .Returns(new Func <string, int, object> ((s, i) => "blub"))
            .Verifiable();

            var result = _service.InstantiateAssembledType(assembledType, arguments, allowNonPublic);

            _typeCacheMock.Verify();
            Assert.That(result, Is.EqualTo("blub"));
        }
        public void CreateInstance_WithConcreteType()
        {
            var allowNonPublicCtor = BooleanObjectMother.GetRandomBoolean();
            var concreteType       = TypeFactory.GetConcreteType(typeof(BaseType1));
            var paramList          = ParamList.Create("blub");
            var fakeInstance       = new object();

            var reflectionServiceMock = MockRepository.GenerateStrictMock <IReflectionService>();

            _defaultPipelineMock.Stub(_ => _.ReflectionService).Return(reflectionServiceMock);
            reflectionServiceMock.Expect(_ => _.InstantiateAssembledType(concreteType, paramList, allowNonPublicCtor)).Return(fakeInstance);

            var instance = _implementation.CreateInstance(allowNonPublicCtor, concreteType, paramList);

            reflectionServiceMock.VerifyAllExpectations();
            Assert.That(instance, Is.SameAs(fakeInstance));
        }
Пример #4
0
        public void CreateObject_ConstructorArguments()
        {
            _reflectionServiceMock.Expect(mock => mock.GetTypeIDForRequestedType(_requestedType)).Return(_typeID);
            var arguments = ParamList.Create("abc", 7);

            _reflectionServiceMock
            .Expect(
                mock => mock.InstantiateAssembledType(
                    // Use strongly typed Equals overload.
                    Arg <AssembledTypeID> .Matches(id => id.Equals(_typeID)),
                    Arg.Is(arguments),
                    Arg.Is(false)))
            .Return("abc, 7");

            var result = _pipeline.Create(_requestedType, arguments);

            Assert.That(result, Is.EqualTo("abc, 7"));
        }
Пример #5
0
        public static SecurableObject NewObject(ClientTransaction clientTransaction, IObjectSecurityStrategy securityStrategy, Action <SecurableObject> ctorHandler = null)
        {
            var previousCtorHandler = _ctorHandler;

            _ctorHandler = ctorHandler;

            try
            {
                using (clientTransaction.EnterNonDiscardingScope())
                {
                    return(NewObject <SecurableObject> (ParamList.Create(securityStrategy)));
                }
            }
            finally
            {
                _ctorHandler = previousCtorHandler;
            }
        }
Пример #6
0
        public void CreateObject_ConstructorArguments()
        {
            _reflectionServiceMock.Setup(mock => mock.GetTypeIDForRequestedType(_requestedType)).Returns(_typeID).Verifiable();
            var arguments = ParamList.Create("abc", 7);

            _reflectionServiceMock
            .Setup(
                mock => mock.InstantiateAssembledType(
                    // Use strongly typed Equals overload.
                    It.Is <AssembledTypeID> (id => id.Equals(_typeID)),
                    arguments,
                    false))
            .Returns("abc, 7")
            .Verifiable();

            var result = _pipeline.Create(_requestedType, arguments);

            Assert.That(result, Is.EqualTo("abc, 7"));
        }
        public virtual IDomainObjectQueryGenerator CreateDomainObjectQueryGenerator(
            StorageProviderDefinition storageProviderDefinition,
            IMethodCallTransformerProvider methodCallTransformerProvider,
            ResultOperatorHandlerRegistry resultOperatorHandlerRegistry,
            IMappingConfiguration mappingConfiguration)
        {
            var rdmsStorageProviderDefinition =
                ArgumentUtility.CheckNotNullAndType <RdbmsProviderDefinition> ("storageProviderDefinition", storageProviderDefinition);

            ArgumentUtility.CheckNotNull("methodCallTransformerProvider", methodCallTransformerProvider);
            ArgumentUtility.CheckNotNull("resultOperatorHandlerRegistry", resultOperatorHandlerRegistry);
            ArgumentUtility.CheckNotNull("mappingConfiguration", mappingConfiguration);

            var storageTypeInformationProvider = CreateStorageTypeInformationProvider(rdmsStorageProviderDefinition);
            var sqlQueryGenerator = CreateSqlQueryGenerator(rdmsStorageProviderDefinition, methodCallTransformerProvider, resultOperatorHandlerRegistry);

            return(ObjectFactory.Create <DomainObjectQueryGenerator> (
                       ParamList.Create(sqlQueryGenerator, _typeConversionProvider, storageTypeInformationProvider, mappingConfiguration)));
        }
        protected virtual ISqlQueryGenerator CreateSqlQueryGenerator(
            RdbmsProviderDefinition storageProviderDefinition,
            IMethodCallTransformerProvider methodCallTransformerProvider,
            ResultOperatorHandlerRegistry resultOperatorHandlerRegistry,
            IRdbmsPersistenceModelProvider persistenceModelProvider)
        {
            ArgumentUtility.CheckNotNull("storageProviderDefinition", storageProviderDefinition);
            ArgumentUtility.CheckNotNull("methodCallTransformerProvider", methodCallTransformerProvider);
            ArgumentUtility.CheckNotNull("resultOperatorHandlerRegistry", resultOperatorHandlerRegistry);
            ArgumentUtility.CheckNotNull("persistenceModelProvider", persistenceModelProvider);

            var generator           = new UniqueIdentifierGenerator();
            var resolver            = CreateMappingResolver(storageProviderDefinition, persistenceModelProvider);
            var sqlPreparationStage = ObjectFactory.Create <DefaultSqlPreparationStage> (
                ParamList.Create(methodCallTransformerProvider, resultOperatorHandlerRegistry, generator));
            var mappingResolutionStage = ObjectFactory.Create <DefaultMappingResolutionStage> (ParamList.Create(resolver, generator));
            var sqlGenerationStage     = ObjectFactory.Create <ExtendedSqlGenerationStage> (ParamList.Empty);

            return(new SqlQueryGenerator(sqlPreparationStage, mappingResolutionStage, sqlGenerationStage));
        }
Пример #9
0
        public void InstantiateAssembledType_WithAssembledTypeID()
        {
            var typeID         = AssembledTypeIDObjectMother.Create();
            var arguments      = ParamList.Create("abc", 7);
            var allowNonPublic = BooleanObjectMother.GetRandomBoolean();

            _constructorCallCache
            .Expect(
                mock => mock.GetOrCreateConstructorCall(
                    // Use strongly typed Equals overload.
                    Arg <AssembledTypeID> .Matches(id => id.Equals(typeID)),
                    Arg.Is(arguments.FuncType),
                    Arg.Is(allowNonPublic)))
            .Return(new Func <string, int, object> ((s, i) => "blub"));

            var result = _service.InstantiateAssembledType(typeID, arguments, allowNonPublic);

            _typeCacheMock.VerifyAllExpectations();
            Assert.That(result, Is.EqualTo("blub"));
        }
Пример #10
0
        public void Create_10()
        {
            var paramList = ParamList.Create("s", 2, 3, 4, 5.0, 6, 7, 8, DateTime.MinValue, "10");

            Assert.That(paramList.GetParameterTypes(),
                        Is.EqualTo(new[] {
                typeof(string),
                typeof(int),
                typeof(int),
                typeof(int),
                typeof(double),
                typeof(int),
                typeof(int),
                typeof(int),
                typeof(DateTime),
                typeof(string)
            }));

            Assert.That(paramList.GetParameterValues(), Is.EqualTo(new object[] { "s", 2, 3, 4, 5.0, 6, 7, 8, DateTime.MinValue, "10" }));
        }
Пример #11
0
        public void NewObject()
        {
            var constructorParameters = ParamList.Create("Some Product");

            _eventSinkWithMock.Expect(mock => mock.RaiseNewObjectCreatingEvent(_typeDefinitionWithCreatorMock.ClassType));
            _persistenceStrategyMock.Expect(mock => mock.CreateNewObjectID(_typeDefinitionWithCreatorMock)).Return(_objectID1);

            _domainObjectCreatorMock
            .Expect(
                mock => mock.CreateNewObject(Arg <IObjectInitializationContext> .Is.Anything, Arg.Is(constructorParameters), Arg.Is(_transaction)))
            .WhenCalled(mi => CheckInitializationContext <NewObjectInitializationContext> (mi.Arguments[0], _objectID1, _transaction))
            .Return(_domainObject1);

            var result = _agent.NewObject(_typeDefinitionWithCreatorMock, constructorParameters);

            _eventSinkWithMock.VerifyAllExpectations();
            _persistenceStrategyMock.VerifyAllExpectations();
            _domainObjectCreatorMock.VerifyAllExpectations();

            Assert.That(result, Is.SameAs(_domainObject1));
        }
Пример #12
0
        public void ConstructorArguments_Generic()
        {
            var instance = _modifyingPipeline.Create <DomainType>();

            Assert.That(instance.String, Is.EqualTo("default .ctor"));

            var obj = new object();

            instance = _modifyingPipeline.Create <DomainType> (ParamList.Create(obj));
            Assert.That(instance.Obj, Is.SameAs(obj));

            instance = _modifyingPipeline.Create <DomainType> (ParamList.Create("abc"));
            Assert.That(instance.String, Is.EqualTo("abc"));

            instance = _modifyingPipeline.Create <DomainType> (ParamList.Create((IEnumerable <char>) "abc"));
            Assert.That(instance.Enumerable, Is.EqualTo("abc"));
            Assert.That(instance.String, Is.Null);

            instance = _modifyingPipeline.Create <DomainType> (ParamList.Create(new[] { 'a', 'b', 'c' }));
            Assert.That(instance.CharArray, Is.EqualTo(new[] { 'a', 'b', 'c' }));
        }
Пример #13
0
        public void Create_0_SameAsEmpty()
        {
            var paramList = ParamList.Create();

            Assert.That(paramList, Is.SameAs(ParamList.Empty));
        }
        public void SimplePropertyAccess_GetCustomMember2()
        {
            const string scriptFunctionSourceCode = @"
import clr
def PropertyPathAccess(cascade) :
  return cascade.Child.Child.Child.Child.Child.Child.Child.Child.Child.Name
";

            const int numberChildren                = 10;
            var       cascade                       = new Cascade(numberChildren);
            var       cascadeStableBinding          = new CascadeStableBinding(numberChildren);
            var       cascadeStableBindingFromMixin = ObjectFactory.Create <CascadeStableBindingFromMixin> (ParamList.Create(numberChildren));

            var privateScriptEnvironment = ScriptEnvironment.Create();

            privateScriptEnvironment.Import(typeof(TestDomain.Cascade).Assembly.GetName().Name, typeof(TestDomain.Cascade).Namespace, typeof(TestDomain.Cascade).Name);

            var propertyPathAccessScript = new ScriptFunction <Cascade, string> (
                _scriptContext, ScriptLanguageType.Python,
                scriptFunctionSourceCode, privateScriptEnvironment, "PropertyPathAccess"
                );

            var nrLoopsArray = new[] { 1, 1, 100000 };

            ScriptingHelper.ExecuteAndTime("SimplePropertyAccess_GetCustomMember2 (No StableBinding)", nrLoopsArray, () => propertyPathAccessScript.Execute(cascade));
            ScriptingHelper.ExecuteAndTime("SimplePropertyAccess_GetCustomMember2 (StableBinding from Mixin)", nrLoopsArray, () => propertyPathAccessScript.Execute(cascadeStableBindingFromMixin));
            ScriptingHelper.ExecuteAndTime("SimplePropertyAccess_GetCustomMember2 (StableBinding)", nrLoopsArray, () => propertyPathAccessScript.Execute(cascadeStableBinding));
        }
        public void WorksIfNoDefaultCtor()
        {
            ClassWithoutDefaultCtor c = ObjectFactory.Create <ClassWithoutDefaultCtor> (ParamList.Create(35));

            Assert.That(c.GetType(), Is.Not.EqualTo(typeof(ClassImplementingISerializable)));

            Assert.That(c.S, Is.EqualTo("35"));

            ClassWithoutDefaultCtor c2 = Serializer.SerializeAndDeserialize(c);

            Assert.That(c2, Is.Not.EqualTo(c));
            Assert.That(c2.S, Is.EqualTo("35"));
        }
        public void NewObject_WithCtorArgs()
        {
            var order    = Order.NewObject();
            var instance = (OrderItem)LifetimeService.NewObject(TestableClientTransaction, typeof(OrderItem), ParamList.Create(order));

            Assert.That(instance, Is.Not.Null);
            Assert.That(instance.Order, Is.SameAs(order));
        }
Пример #17
0
 public static AccessTypeDefinition NewObject(Guid metadataItemID, string name, int value)
 {
     return(NewObject <AccessTypeDefinition> (ParamList.Create(metadataItemID, name, value)));
 }
Пример #18
0
 public void WrongConstructorCannotBeInstantiated()
 {
     LifetimeService.NewObject(TestableClientTransaction, typeof(Order), ParamList.Create("foo", "bar", "foobar", (object)null));
 }
Пример #19
0
 public static ClassWithWrongConstructor NewObject(double d)
 {
     return(NewObject <ClassWithWrongConstructor>(ParamList.Create(d)));
 }
 public static TypeWithReference Create(string displayName)
 {
     return(ObjectFactory.Create <TypeWithReference> (true, ParamList.Create(displayName)));
 }
 public override IPersistenceStrategy CreatePersistenceStrategy(ClientTransaction constructedTransaction)
 {
     ArgumentUtility.CheckNotNull("constructedTransaction", constructedTransaction);
     return(ObjectFactory.Create <RootPersistenceStrategy> (true, ParamList.Create(constructedTransaction.ID)));
 }
 public static TypeWithReference Create(TypeWithReference firstValue, TypeWithReference secondValue)
 {
     return(ObjectFactory.Create <TypeWithReference> (true, ParamList.Create(firstValue, secondValue)));
 }
 public void NewObject_WrongCtorArgs()
 {
     LifetimeService.NewObject(TestableClientTransaction, typeof(OrderItem), ParamList.Create(0m));
 }
Пример #24
0
        public void ConstructorsAreReplicated4()
        {
            var c = ObjectFactory.Create <ClassWithCtors> (ParamList.Create("a"));

            Assert.That(c.O, Is.EqualTo("a"));
        }
 public void ProtectedNonDefaultConstructor_Mixed_AllowProtected()
 {
     using (MixinConfiguration.BuildFromActive().ForClass <TargetClassWithProtectedCtors>().Clear().AddMixins(typeof(NullMixin)).EnterScope())
     {
         Assert.That(ObjectFactory.Create <TargetClassWithProtectedCtors> (true, ParamList.Create(1)), Is.Not.Null);
     }
 }
 public void ProtectedNonDefaultConstructor_NonMixed_AllowProtected()
 {
     using (MixinConfiguration.BuildNew().EnterScope())
     {
         Assert.That(ObjectFactory.Create <TargetClassWithProtectedCtors> (true, ParamList.Create(1)), Is.Not.Null);
     }
 }
Пример #27
0
 public void ConstructorsAreReplicated2()
 {
     ObjectFactory.Create <ClassWithCtors> (ParamList.Create(2.0));
 }
Пример #28
0
        public void AllowNonPublic_True_WithoutModifications()
        {
            var instance1 = _nonModifyingPipeline.Create <DomainType> (ParamList.Create(7), allowNonPublicConstructor: true);
            var instance2 = (DomainType)_nonModifyingPipeline.Create(typeof(DomainType), ParamList.Create(8), allowNonPublicConstructor: true);

            Assert.That(instance1.String, Is.EqualTo("7"));
            Assert.That(instance2.String, Is.EqualTo("8"));
        }
Пример #29
0
 public static StateDefinition NewObject(string name, int value)
 {
     return(NewObject <StateDefinition> (ParamList.Create(name, value)));
 }
 public static DomainObjectWithSpecialConstructor NewObject(string s)
 {
     return(NewObject <DomainObjectWithSpecialConstructor>(ParamList.Create(s)));
 }