public void MainTest()
        {
            Require.ProviderIs(StorageProvider.SqlServer);
            var initialConfig = DomainConfigurationFactory.Create();

            initialConfig.Types.Register(typeof(model.MainTestModel.TestEntity));
            initialConfig.Types.Register(typeof(model.MainTestModel.TestEntity2));
            initialConfig.UpgradeMode = DomainUpgradeMode.Recreate;
            using (var domain = Domain.Build(initialConfig)) { }

            // useful work
            var configration = DomainConfigurationFactory.Create();

            configration.Types.Register(typeof(model.MainTestModel.TestEntity));
            configration.Types.Register(typeof(model.MainTestModel.TestEntity2));
            configration.UpgradeMode = DomainUpgradeMode.PerformSafely;

            Exception exception = null;
            int       step      = 0;

            for (var i = 0; i < 30; i++, step++)
            {
                try {
                    using (var domain = Domain.Build(configration)) { }
                }
                catch (Exception e) {
                    exception = e;
                    break;
                }
            }
            Assert.That(exception, Is.Null);
            Assert.That(step, Is.EqualTo(30));
        }
        public void Main()
        {
            Require.ProviderIs(StorageProvider.SqlServer);

            // Initialize domain
            Domain domain;

            try
            {
                var domainConfig = DomainConfigurationFactory.Create();
                domainConfig.NamingConvention.NamespacePolicy = NamespacePolicy.AsIs;

                // Load assemblies with persistent classes from configuration :
                TestLog.Info("Loading plugins...");

                domainConfig.Types.Register(typeof(QueueProcessor).Assembly, typeof(QueueProcessor).Namespace);

                domainConfig.UpgradeMode = DomainUpgradeMode.Recreate;
                domain = Domain.Build(domainConfig);
            }
            catch (DomainBuilderException e)
            {
                TestLog.Error("Domain build failed: " + e.ToString());
                throw;
            }

            string key = CreateObjects.CreateTestEchoQueueProcessor(domain);

            IList <object> workList = QueueProcessor.GetWork(key, domain);

            foreach (object workUnit in workList)
            {
                QueueProcessor.Execute(key, workUnit, domain);
            }
        }
예제 #3
0
        public void InternalTest(Func <DomainConfiguration, Domain> generator)
        {
            var config = DomainConfigurationFactory.Create();

            config.Types.Register(typeof(IHasName).Assembly, typeof(IHasName).Namespace);
            var domain = generator(config);

            using (var session = domain.OpenSession())
                using (var t = session.OpenTransaction()) {
                    new A()
                    {
                        Name = "A"
                    };
                    new B()
                    {
                        Name = "B"
                    };
                    new C()
                    {
                        Name = "C"
                    };
                    var hasNames = session.Query.All <IHasName>().ToList();
                    Assert.AreEqual(2, hasNames.Count);
                    t.Complete();
                }
        }
        public void MainTest()
        {
            var configuration = DomainConfigurationFactory.Create();

            configuration.Types.Register(typeof(Test));
            configuration.Types.Register(typeof(Test2));

            configuration.UpgradeMode = DomainUpgradeMode.Recreate;

            using (var domain = Domain.Build(configuration)) {
                using (var session = domain.OpenSession())
                    using (session.Activate())
                        using (var t = session.OpenTransaction()) {
                            var test2 = new Test2();
                            var test  = new Test {
                                Name   = "",
                                Struct = new StructType {
                                    Item = test2
                                }
                            };
                            t.Complete();
                        }

                using (var session = domain.OpenSession())
                    using (session.Activate())
                        using (var t = session.OpenTransaction()) {
                            var test2   = Session.Current.Query.All <Test2>().SingleOrDefault();
                            var result2 = test2.StructSet.OfType <Test>().ToList();
                        }
            }
        }
        private void BuildDomain(DomainUpgradeMode upgradeMode)
        {
            CleanDomain();

            var config = DomainConfigurationFactory.Create();

            config.NamingConvention.NamespacePolicy = NamespacePolicy.Synonymize;
            config.NamingConvention.NamespaceSynonyms[typeof(NonClustered.Root).Namespace]    = "NC";
            config.NamingConvention.NamespaceSynonyms[typeof(Clustered.Root).Namespace]       = "C";
            config.NamingConvention.NamespaceSynonyms[typeof(CustomClustered.Root).Namespace] = "CC";
            config.NamingConvention.NamespaceSynonyms[typeof(ErrorCases.DuplicateClusteredIndex).Namespace] = "E";

            foreach (var type in domainTypes)
            {
                config.Types.Register(type);
            }
            config.Types.Register(typeof(SingleTableSchemaModifier).Assembly, typeof(SingleTableSchemaModifier).Namespace);

            config.UpgradeMode = upgradeMode;
            if (inheritanceSchema != null)
            {
                InheritanceSchemaModifier.ActivateModifier(inheritanceSchema.Value);
            }
            else
            {
                InheritanceSchemaModifier.DeactivateModifiers();
            }

            domain = Domain.Build(config);
        }
        public void MainTest()
        {
            var configuration1 = DomainConfigurationFactory.Create();

            configuration1.Types.Register(typeof(InconsistentDefaultDateTimeValuesModel1.MyEntity));
            configuration1.UpgradeMode = DomainUpgradeMode.Recreate;

            using (var domain1 = Domain.Build(configuration1))
                using (var session = domain1.OpenSession())
                    using (var ts = session.OpenTransaction()) {
                        new InconsistentDefaultDateTimeValuesModel1.MyEntity();
                        ts.Complete();
                    }

            var configuration2 = DomainConfigurationFactory.Create();

            configuration2.Types.Register(typeof(InconsistentDefaultDateTimeValuesModel2.MyEntity));
            configuration2.Types.Register(typeof(Upgrader));
            configuration2.UpgradeMode = DomainUpgradeMode.Perform;

            using (var domain2 = Domain.Build(configuration2))
                using (var session = domain2.OpenSession())
                    using (var ts = session.OpenTransaction()) {
                        var count = session.Query.All <InconsistentDefaultDateTimeValuesModel2.MyEntity>().Count();
                        Assert.AreEqual(1, count);
                        session.Query.All <InconsistentDefaultDateTimeValuesModel2.MyEntity>().First(entity => entity.Value == DateTime.MinValue);
                        ts.Complete();
                    }
        }
        public async Task ConnectionExtensionExistanceAsyncTest(int amoundOtAccessors)
        {
            var domainConfig = DomainConfigurationFactory.Create();

            domainConfig.UpgradeMode = DomainUpgradeMode.Recreate;

            foreach (var accessor in GetAccessors(amoundOtAccessors))
            {
                domainConfig.Types.Register(accessor);
            }

            await using (var domain = await Domain.BuildAsync(domainConfig))
                await using (var session = await domain.OpenSessionAsync()) {
                    var nativeHandler = (SqlSessionHandler)session.Handler;
                    var extensions    = nativeHandler.Connection.Extensions;
                    if (amoundOtAccessors > 0)
                    {
                        Assert.That(extensions.Count, Is.EqualTo(1));
                        var extension = extensions.Get <DbConnectionAccessorExtension>();
                        Assert.That(extension, Is.Not.Null);
                        Assert.That(extension.Accessors.Count, Is.EqualTo(amoundOtAccessors));
                    }
                    else
                    {
                        Assert.That(extensions.Count, Is.EqualTo(0));
                    }
                }
        }
        public void ConnectionExtensionExistanceTest(int includeHandlersCount)
        {
            var domainConfig = DomainConfigurationFactory.Create();

            domainConfig.UpgradeMode = DomainUpgradeMode.Recreate;

            foreach (var accessor in GetAccessors(includeHandlersCount))
            {
                domainConfig.Types.Register(accessor);
            }

            using (var domain = Domain.Build(domainConfig))
                using (var session = domain.OpenSession()) {
                    var nativeHandler = (SqlSessionHandler)session.Handler;
                    var extensions    = nativeHandler.Connection.Extensions;
                    if (includeHandlersCount > 0)
                    {
                        Assert.That(extensions.Count, Is.EqualTo(1));
                        var extension = extensions.Get <DbConnectionAccessorExtension>();
                        Assert.That(extension, Is.Not.Null);
                        Assert.That(extension.Accessors.Count, Is.EqualTo(includeHandlersCount));
                    }
                    else
                    {
                        Assert.That(extensions.Count, Is.EqualTo(0));
                    }
                }
        }
        public void MediaTest()
        {
            var config = DomainConfigurationFactory.Create();

            config.Types.Register(typeof(Media));
            config.Types.Register(typeof(Track <SimpleMedia>));
            config.Types.Register(typeof(Track <ComplexMedia>));
            config.Types.Register(typeof(SimpleTrack));
            config.Types.Register(typeof(ComplexTrack));
            var domain = Domain.Build(config);

            using (var session = domain.OpenSession())
                using (var t = session.OpenTransaction()) {
                    new SimpleTrack(TimeSpan.FromMinutes(5), TimeSpan.FromMinutes(10), new SimpleMedia()
                    {
                        Description = "Simple", Foo = 23
                    });
                    new ComplexTrack(TimeSpan.FromMinutes(6), TimeSpan.FromMinutes(15), new ComplexMedia()
                    {
                        Description = "Simple", Bar = DateTime.Now
                    });
                    var listSimpleMedia  = session.Query.All <Track <SimpleMedia> >().ToList();
                    var listComplexMedia = session.Query.All <Track <ComplexMedia> >().ToList();
                    Assert.AreEqual(1, listSimpleMedia.Count);
                    Assert.AreEqual(1, listComplexMedia.Count);
                }
        }
예제 #10
0
        private async Task BuildDomainAsync(string version, DomainUpgradeMode upgradeMode, int?keyCacheSize, params Type[] types)
        {
            if (domain != null)
            {
                domain.Dispose();
            }

            var configuration = DomainConfigurationFactory.Create();

            configuration.UpgradeMode = upgradeMode;
            foreach (var type in types)
            {
                configuration.Types.Register(type);
            }

            if (keyCacheSize.HasValue)
            {
                configuration.KeyGeneratorCacheSize = keyCacheSize.Value;
            }

            configuration.Types.Register(typeof(Upgrader));
            using (Upgrader.Enable(version)) {
                domain = await Domain.BuildAsync(configuration);
            }
        }
        private Xtensive.Orm.Configuration.DomainConfiguration BuildConfiguration0()
        {
            var config = DomainConfigurationFactory.Create();

            config.Types.Register(CompileAssembly(0), "Modules.Model");
            return(config);
        }
        public void MainTest()
        {
            Require.ProviderIs(StorageProvider.SqlServer);

            var configuration = DomainConfigurationFactory.Create();

            configuration.UpgradeMode = DomainUpgradeMode.Recreate;
            configuration.Types.Register(typeof(SomeEntity1));
            configuration.Types.Register(typeof(SomeEntity2));

            using (var domain = Domain.Build(configuration))
                using (var session = domain.OpenSession())
                    using (var transaction = session.OpenTransaction()) {
                        var accessor = session.Services.Get <DirectSqlAccessor>();
                        using (var command = accessor.CreateCommand()) {
                            command.CommandText = CreateIndexQuery;
                            _ = command.ExecuteNonQuery();
                        }
                        transaction.Complete();
                    }

            configuration             = DomainConfigurationFactory.Create();
            configuration.UpgradeMode = DomainUpgradeMode.Perform;
            configuration.Types.Register(typeof(SomeEntity1));
            configuration.Types.Register(typeof(CustomUpgradeHandler));

            Assert.DoesNotThrow(() => Domain.Build(configuration).Dispose());
        }
        public void MainTest()
        {
            var domainConfiguration = DomainConfigurationFactory.Create();

            domainConfiguration.UpgradeMode = DomainUpgradeMode.Recreate;
            foreach (var type in typeof(FormElement).Assembly.GetTypes())
            {
                if (typeof(IEntityBase).IsAssignableFrom(type))
                {
                    domainConfiguration.Types.Register(type);
                }
            }
            using (var domain = Domain.Build(domainConfiguration)) {
                using (var session = domain.OpenSession())
                    using (session.Activate())
                        using (var transaction = Session.Current.OpenTransaction()) {
                            var externalDataField = new ExternalDataField(Guid.NewGuid())
                            {
                                SysName = "ee"
                            };
                            var eee = new FormElement.TpVisibleEnable(Guid.NewGuid(), externalDataField);

                            transaction.Complete();
                        }

                using (var session = domain.OpenSession())
                    using (session.Activate())
                        using (var transaction = Session.Current.OpenTransaction()) {
                            var e1 = Query.All <ExternalDataField>().Single();
                            e1.Remove();
                            transaction.Complete();
                        }
            }
        }
예제 #14
0
        private Task <Domain> BuildDomainAsync(DomainUpgradeMode mode)
        {
            var configuration = DomainConfigurationFactory.Create();

            configuration.UpgradeMode = mode;
            return(Domain.BuildAsync(configuration));
        }
예제 #15
0
        private void CreateAccessor()
        {
            var nodeConfiguration = new NodeConfiguration();
            var configuration     = DomainConfigurationFactory.Create();
            var descriptor        = ProviderDescriptor.Get(configuration.ConnectionInfo.Provider);
            var driverFactory     = (SqlDriverFactory)Activator.CreateInstance(descriptor.DriverFactory);
            var storageDriver     = StorageDriver.Create(driverFactory, configuration);
            var nameBuilder       = new NameBuilder(configuration, storageDriver.ProviderInfo);
            var handlerFactory    = (HandlerFactory)Activator.CreateInstance(descriptor.HandlerFactory);

            var accessor = new UpgradeServiceAccessor {
                Configuration  = configuration,
                StorageDriver  = storageDriver,
                NameBuilder    = nameBuilder,
                HandlerFactory = handlerFactory
            };

            configuration.Lock();
            var connection = storageDriver.CreateConnection(null);

            connection.Open();
            accessor.MappingResolver = MappingResolver.Create(configuration, nodeConfiguration, storageDriver.GetDefaultSchema(connection));
            if (storageDriver.ProviderInfo.Supports(ProviderFeatures.SingleConnection))
            {
                accessor.RegisterTemporaryResource(connection);
            }
            else
            {
                accessor.RegisterResource(connection);
            }
            accessor.Connection = connection;
            accessor.Connection.Extensions.AddOne(new TypeDelegator(typeof(IProviderExecutor)));

            this.accessor = accessor;
        }
예제 #16
0
        private Domain BuildDomain(DomainUpgradeMode mode)
        {
            var configuration = DomainConfigurationFactory.Create();

            configuration.UpgradeMode = mode;
            return(Domain.Build(configuration));
        }
예제 #17
0
        protected virtual DomainConfiguration BuildConfiguration()
        {
            var configuration = DomainConfigurationFactory.Create();

            RegisterTypes(configuration);
            return(configuration);
        }
예제 #18
0
        public void CombinedTest()
        {
            if (domain != null)
            {
                domain.DisposeSafely();
            }

            var configuration = DomainConfigurationFactory.Create();

            configuration.UpgradeMode = DomainUpgradeMode.Recreate;
            configuration.Types.Register(typeof(PropertyVersion <decimal?>));
            domain = Domain.Build(configuration);
            using (var session = domain.OpenSession()) {
                using (var t = session.OpenTransaction()) {
                    var v = new PropertyVersion <decimal?>()
                    {
                        PropertyValue = 123
                    };
                    t.Complete();
                }
                using (var t = session.OpenTransaction()) {
                    var count = session.Query.All <PropertyVersion <decimal?> >().Count();
                    Assert.AreEqual(1, count);
                    var v = session.Query.All <PropertyVersion <decimal?> >().FirstOrDefault();
                    Assert.IsNotNull(v);
                    Assert.AreEqual(123, v.PropertyValue);
                    t.Complete();
                }
            }
        }
        public async Task SessionConnectionAccessorsAsyncTest()
        {
            var domainConfig = DomainConfigurationFactory.Create();

            domainConfig.UpgradeMode = DomainUpgradeMode.Recreate;
            domainConfig.Types.Register(typeof(DummyEntity));
            domainConfig.Types.Register(typeof(MyConnectionAccessor));

            Guid?first = null;

            await using (var domain = await Domain.BuildAsync(domainConfig))
                await using (var session = await domain.OpenSessionAsync()) {
                    var nativeHandler    = (SqlSessionHandler)session.Handler;
                    var extension        = nativeHandler.Connection.Extensions.Get <DbConnectionAccessorExtension>();
                    var accessorInstance = (MyConnectionAccessor)extension.Accessors.First();
                    Assert.That(accessorInstance.ConnectionOpeningCounter, Is.Not.EqualTo(0));
                    Assert.That(accessorInstance.ConnectionOpenedCounter, Is.Not.EqualTo(0));
                    first = accessorInstance.UniqueInstanceIdentifier;
                }

            Guid?second = null;

            await using (var domain = await Domain.BuildAsync(domainConfig))
                await using (var session = await domain.OpenSessionAsync()) {
                    var nativeHandler    = (SqlSessionHandler)session.Handler;
                    var extension        = nativeHandler.Connection.Extensions.Get <DbConnectionAccessorExtension>();
                    var accessorInstance = (MyConnectionAccessor)extension.Accessors.First();
                    Assert.That(accessorInstance.ConnectionOpeningCounter, Is.Not.EqualTo(0));
                    Assert.That(accessorInstance.ConnectionOpenedCounter, Is.Not.EqualTo(0));
                    second = accessorInstance.UniqueInstanceIdentifier;
                }

            Assert.That(first != null && second != null && first != second, Is.True);
        }
예제 #20
0
        private Domain BuildDomain(DomainUpgradeMode upgradeMode, Type sampleType)
        {
            var configuration = DomainConfigurationFactory.Create();

            configuration.UpgradeMode = upgradeMode;
            configuration.Types.Register(sampleType.Assembly, sampleType.Namespace);
            return(Domain.Build(configuration));
        }
예제 #21
0
        private DomainConfiguration BuildDomainConfiguration()
        {
            var configuration = DomainConfigurationFactory.Create();

            configuration.UpgradeMode = DomainUpgradeMode.Recreate;
            ApplyCustomConfigurationSettings(configuration);
            return(configuration);
        }
        private DomainConfiguration BuildConfiguration(Type t)
        {
            var config = DomainConfigurationFactory.Create();

            config.Types.Register(t.Assembly, t.Namespace);
            config.UpgradeMode = DomainUpgradeMode.Recreate;
            return(config);
        }
예제 #23
0
        public void MainAsyncTest()
        {
            var configuration = DomainConfigurationFactory.Create();

            configuration.Types.Register(typeof(UpgradeHandler1));
            configuration.Types.Register(typeof(UpgradeHandler2));
            _ = Assert.ThrowsAsync <DomainBuilderException>(async() => await Domain.BuildAsync(configuration));
        }
예제 #24
0
        protected virtual DomainConfiguration BuildConfiguration()
        {
            var configuration = DomainConfigurationFactory.Create();

            configuration.Types.Register(typeof(ITrackingMonitor).Assembly);
            configuration.Types.Register(typeof(AutoBuildTest).Assembly);
            return(configuration);
        }
예제 #25
0
        protected virtual DomainConfiguration BuildInitialConfiguration()
        {
            var configuration = DomainConfigurationFactory.Create();

            configuration.Types.Register(typeof(CleanupUpgradeHandler));
            configuration.UpgradeMode = DomainUpgradeMode.Recreate;
            return(configuration);
        }
        protected virtual DomainConfiguration BuildUpgradeConfiguration()
        {
            var configuration = DomainConfigurationFactory.Create();

            configuration.UpgradeMode = DomainUpgradeMode.Recreate;
            configuration.Types.Register(typeof(TestEntity));
            return(configuration);
        }
        private void BuildDomain(Type type, DomainUpgradeMode upgradeMode)
        {
            var configuration = DomainConfigurationFactory.Create();

            configuration.Types.Register(type);
            configuration.UpgradeMode = upgradeMode;
            Domain.Build(configuration).Dispose();
        }
        protected override DomainConfiguration BuildConfiguration()
        {
            var configuration = DomainConfigurationFactory.Create();

            configuration.Types.Register(typeof(Book).Assembly, typeof(Book).Namespace);
            configuration.UpgradeMode = DomainUpgradeMode.Recreate;
            return(configuration);
        }
        private Task <Domain> BuildDomainAsync(Type sampleType, DomainUpgradeMode mode)
        {
            var configuration = DomainConfigurationFactory.Create();

            configuration.UpgradeMode = mode;
            configuration.Types.Register(sampleType.Assembly, sampleType.Namespace);
            return(Domain.BuildAsync(configuration));
        }
        public void MainTest()
        {
            var configuration = DomainConfigurationFactory.Create();

            configuration.Types.Register(typeof(UpgradeHandler1));
            configuration.Types.Register(typeof(UpgradeHandler2));
            AssertEx.Throws <DomainBuilderException>(() => Domain.Build(configuration));
        }