Esempio n. 1
0
        public void InitializeShouldLog()
        {
            var sfp = new MultiSessionFactoryProvider();

            Assert.That(Spying.Logger <MultiSessionFactoryProvider>().Execute(sfp.Initialize).WholeMessage,
                        Text.Contains("Initialize new session factories reading the configuration."));
        }
Esempio n. 2
0
        public void DisposeDoNotInitialize()
        {
            var sfp = new MultiSessionFactoryProvider();

            Assert.That(Spying.Logger <MultiSessionFactoryProvider>().Execute(sfp.Dispose).WholeMessage,
                        Text.DoesNotContain("Initialize new session factories reading the configuration."));
        }
Esempio n. 3
0
        public void ShouldInitializeOnlyOneTime()
        {
            var sfp = new MultiSessionFactoryProvider();

            Assert.That(sfp.GetFactory(null), Is.Not.Null);

            Assert.That(Spying.Logger <MultiSessionFactoryProvider>().Execute(sfp.Initialize).WholeMessage,
                        Text.DoesNotContain("Initialize new session factories reading the configuration."));
        }
Esempio n. 4
0
        public void ShouldHasOnlyTwoInstancesOfFactory()
        {
            var sfp = new MultiSessionFactoryProvider();

            Assert.That(sfp.Count(), Is.EqualTo(2));
            IEnumerator en = ((IEnumerable)sfp).GetEnumerator();
            int         i  = 0;

            while (en.MoveNext())
            {
                i++;
            }
            Assert.That(i, Is.EqualTo(2));
        }
Esempio n. 5
0
        public void ThrowSpecificExceptionForInvalidFactoryName()
        {
            var sfp = new MultiSessionFactoryProvider();

            sfp.Initialize();
            try
            {
                sfp.GetFactory("NotExistFactory");
            }
            catch (ArgumentException e)
            {
                Assert.That(e.Message, Text.StartsWith("The session-factory-id was not register"));
            }
        }
Esempio n. 6
0
        public void WorkWitheDefaultAndSpecificSessionFactory()
        {
            var sfp = new MultiSessionFactoryProvider();

            Assert.That(sfp.GetFactory(null), Is.Not.Null);
            ISessionFactory sf1 = sfp.GetFactory(null);
            ISessionFactory sf2 = sfp.GetFactory(null);

            Assert.That(ReferenceEquals(sf1, sf2));

            ISessionFactory sfp1 = sfp.GetFactory("FACTORY1");

            Assert.That(ReferenceEquals(sf1, sfp1));
            ISessionFactory sfp2 = sfp.GetFactory("FACTORY2");

            Assert.That(!ReferenceEquals(sfp1, sfp2));
        }
Esempio n. 7
0
        public void ShouldExecuteDisposeOlnyOneForEachFactory()
        {
            MultiSessionFactoryProvider sfp;
            ISessionFactory             sf1;
            int disposed = 0;

            using (sfp = new MultiSessionFactoryProvider())
            {
                sfp.BeforeCloseSessionFactory += ((sender, e) => disposed++);
                sf1 = sfp.GetFactory(null);
            }
            Assert.That(disposed, Is.EqualTo(2));
            Assert.That(sf1.IsClosed);
            disposed = 0;
            sfp.Dispose();
            Assert.That(disposed, Is.EqualTo(0));
        }
Esempio n. 8
0
        public void ConfiguringOneSessionFactoryWithoutName()
        {
            var sfp = new MultiSessionFactoryProvider(new SpecificFileConfigurationLoader("TestConfigWithFactoryName.xml"));

            Assert.Throws <ArgumentException>(() => sfp.GetFactory(null));
        }