public static ISession OpenTemporarySession()
        {
            lock (factorylock)
            {
                if (_sessionSource == null)
                {
                    var persistenceModel = new PersistenceModel();
                    persistenceModel.AddMappingsFromAssembly(typeof(JiraIssueMap).Assembly);

                    var sqLiteConfiguration = new SQLiteConfiguration()
                                              .InMemory()
                                              .ShowSql();

                    var sessionSource = new SessionSource(sqLiteConfiguration.ToProperties(), persistenceModel);

                    _sessionSource = sessionSource;
                }
            }

            var session = _sessionSource.CreateSession();

            _sessionSource.BuildSchema(session);

            return(session);
        }
Exemplo n.º 2
0
    private static void BuildSchema(FluentConfiguration configuration)
    {
        var sessionSource = new SessionSource(configuration);
        var session       = sessionSource.CreateSession();

        sessionSource.BuildSchema(session);
    }
Exemplo n.º 3
0
        /// <summary>
        /// Configures the storage with the user supplied persistence configuration
        /// Azure tables are created if requested by the user
        /// </summary>
        /// <param name="config"></param>
        /// <param name="connectionString"></param>
        /// <param name="createSchema"></param>
        /// <returns></returns>
        public static Configure AzureSubcriptionStorage(this Configure config,
                                                        string connectionString,
                                                        bool createSchema)
        {
            var database = MsSqlConfiguration.MsSql2005
                           .ConnectionString(connectionString)
                           .Provider(typeof(TableStorageConnectionProvider).AssemblyQualifiedName)
                           .Dialect(typeof(TableStorageDialect).AssemblyQualifiedName)
                           .Driver(typeof(TableStorageDriver).AssemblyQualifiedName)
                           .ProxyFactoryFactory(typeof(ProxyFactoryFactory).AssemblyQualifiedName);

            var fluentConfiguration = Fluently.Configure()
                                      .Database(database)
                                      .Mappings(m => m.FluentMappings.Add(typeof(SubscriptionMap)));
            var configuration = fluentConfiguration.BuildConfiguration();

            var sessionSource = new SessionSource(fluentConfiguration);

            if (createSchema)
            {
                using (var session = sessionSource.CreateSession())
                {
                    new SchemaExport(configuration).Execute(true, true, false, session.Connection, null);
                    session.Flush();
                }
            }

            config.Configurer.RegisterSingleton <ISessionSource>(sessionSource);
            config.Configurer.ConfigureComponent <SubscriptionStorage>(DependencyLifecycle.InstancePerCall);

            return(config);
        }
Exemplo n.º 4
0
 protected virtual void Before_each_test()
 {
     SessionSource = new SessionSource(new TestModel());
     Session       = SessionSource.CreateSession();
     SessionSource.BuildSchema(Session);
     CreateInitialData(Session);
     Session.Clear();
 }
 public void AutoCriarBancoDeDados()
 {
     if (_fluentConfiguration != null)
     {
         var      sessionSource = new SessionSource(_fluentConfiguration);
         ISession session       = sessionSource.CreateSession();
         sessionSource.BuildSchema(session);
     }
 }
Exemplo n.º 6
0
        private void TestConnection(string connectionString)
        {
            SessionSource sessionSource = SqLiteConnector.CreateDebugSessionSource(connectionString);

            using (ISession session = sessionSource.CreateSession())
            {
                sessionSource.BuildSchema(session);
            }
        }
 protected virtual void Context()
 {
     SessionSource = new SessionSource(new TModel());
     Session       = SessionSource.CreateSession();
     SessionSource.BuildSchema(Session);
     CreateInitialData(Session);
     Session.Flush();
     Session.Clear();
 }
Exemplo n.º 8
0
        public void ReturnsFalseIfEmailBelongsToUser()
        {
            var repository = new UserRepository(null, SessionSource.CreateSession());
            var user       = new User {
                Name = "test", Credentials = new Credentials("*****@*****.**", "pass")
            };

            repository.Save(user);
            Assert.False(repository.EmailExists(user));
        }
Exemplo n.º 9
0
        public void ReturnsFalseIfEmailIsntInUse()
        {
            var user = new User {
                Credentials = new Credentials {
                    Email = "*****@*****.**"
                }
            };
            var repository = new UserRepository(null, SessionSource.CreateSession());

            Assert.False(repository.EmailExists(user));
        }
Exemplo n.º 10
0
        public void Should_map_session_fields()
        {
            var speaker = new Speaker("Joe", "Schmoe");
            var session = new Session("Foo", new string('a', 5000), speaker);

            SaveEntities(session);

            var loaded = SessionSource.CreateSession().Load <Session>(session.Id);

            loaded.Title.ShouldEqual(session.Title);
            loaded.Abstract.ShouldEqual(session.Abstract);
        }
Exemplo n.º 11
0
        public void Should_get_events_by_name()
        {
            var conference = new Conference("Foo");

            SaveEntities(conference);

            var repos = new ConferenceRepository(SessionSource.CreateSession());

            var loaded = repos.GetByName("Foo");

            loaded.ShouldEqual(conference);
        }
Exemplo n.º 12
0
        public void Should_map_all_event_fields_correctly()
        {
            var newEvent = new Conference("Some event");

            SaveEntities(newEvent);

            var newSession = SessionSource.CreateSession();

            var savedEvent = newSession.Load <Conference>(newEvent.Id);

            savedEvent.Name.ShouldEqual(newEvent.Name);
        }
Exemplo n.º 13
0
        public void ReturnsTrueIfEmailExistsForDifferentUser()
        {
            var repository = new UserRepository(null, SessionSource.CreateSession());
            var user       = new User {
                Name = "test", Credentials = new Credentials("*****@*****.**", "pass")
            };

            repository.Save(new User {
                Name = "test", Credentials = new Credentials("*****@*****.**", "pass")
            });
            Assert.True(repository.EmailExists(user));
        }
Exemplo n.º 14
0
        public void Should_cascade_to_speaker()
        {
            var speaker = new Speaker("Joe", "Schmoe");
            var session = new Session("Foo", "Bar", speaker);

            SaveEntities(session);

            var loaded = SessionSource.CreateSession().Load <Session>(session.Id);

            loaded.Speaker.ShouldEqual(speaker);

            loaded.Speaker.GetSessions().Count().ShouldEqual(1);
        }
Exemplo n.º 15
0
        public void Should_cascade_attendee()
        {
            var attendee = new Attendee("Joe", "Schmoe");
            var newEvent = new Conference("Some event");

            attendee.RegisterFor(newEvent);

            SaveEntities(newEvent);

            var loaded = SessionSource.CreateSession().Load <Conference>(newEvent.Id);

            loaded.GetAttendees().Count().ShouldEqual(1);
            loaded.GetAttendees().ElementAt(0).Conference.ShouldEqual(loaded);
        }
Exemplo n.º 16
0
        public void Should_map_all_speaker_fields()
        {
            var speaker = new Speaker("Joe", "Schmoe")
            {
                Bio = "I come from France"
            };

            SaveEntities(speaker);

            var loaded = SessionSource.CreateSession().Load <Speaker>(speaker.Id);

            loaded.FirstName.ShouldEqual(speaker.FirstName);
            loaded.LastName.ShouldEqual(speaker.LastName);
            loaded.Bio.ShouldEqual(speaker.Bio);
        }
Exemplo n.º 17
0
        public void Should_cascade_session()
        {
            var newEvent = new Conference("Some event");
            var session  = new Session("Foo", "Bar", new Speaker("Joe", "Schmoe"));

            newEvent.AddSession(session);

            SaveEntities(newEvent);

            var loaded = SessionSource.CreateSession().Load <Conference>(newEvent.Id);

            loaded.SessionCount.ShouldEqual(1);
            loaded.GetSessions().Count().ShouldEqual(1);
            loaded.GetSessions().ElementAt(0).Conference.ShouldEqual(loaded);
        }
        public void SetupContext()
        {
            var cfg = new SQLiteConfiguration()
                      .InMemory()
                      .ShowSql();

            SessionSource = new SessionSource(cfg.ToProperties(), new TModel());
            Session       = SessionSource.CreateSession();
            SessionSource.BuildSchema(Session);

            Context();
            Session.Flush();
            Session.Clear();

            Because();
        }
Exemplo n.º 19
0
        public void ReturnsNullIfPasswordsDontMatch()
        {
            var encryptor  = Dynamic <IEncryptor>();
            var repository = new UserRepository(encryptor, SessionSource.CreateSession());

            encryptor.Expect(e => e.IsMatch("marron", "hashed")).Return(false);

            ReplayAll();
            repository.Save(new User {
                Name = "#18", Credentials = new Credentials {
                    Email = "*****@*****.**", Password = "******"
                }
            });
            Assert.Null(repository.FindByCredentials(new Credentials("*****@*****.**", "marron")));
            encryptor.VerifyAllExpectations();
        }
Exemplo n.º 20
0
        public void ReturnsDeveloperIfCredentialsAreValid()
        {
            var encryptor  = Dynamic <IEncryptor>();
            var repository = new UserRepository(encryptor, SessionSource.CreateSession());

            encryptor.Stub(e => e.IsMatch(null, null)).IgnoreArguments().Return(true);

            ReplayAll();
            repository.Save(new User {
                Name = "#18", Credentials = new Credentials {
                    Email = "*****@*****.**", Password = "******"
                }
            });
            var user = repository.FindByCredentials(new Credentials("*****@*****.**", "marron"));

            Assert.Equal("#18", user.Name);
        }
Exemplo n.º 21
0
        public void Should_map_attendee_fields()
        {
            var attendee = new Attendee("Joe", "Schmoe")
            {
                Email = "*****@*****.**",
                State = "TX"
            };

            SaveEntities(attendee);

            var loaded = SessionSource.CreateSession().Load <Attendee>(attendee.Id);

            loaded.FirstName.ShouldEqual(attendee.FirstName);
            loaded.LastName.ShouldEqual(attendee.LastName);
            loaded.Email.ShouldEqual(attendee.Email);
            loaded.State.ShouldEqual(attendee.State);
        }
Exemplo n.º 22
0
        public NHibernateConfig()
        {
            var config = new SQLiteConfiguration()
                         .InMemory()
                         .ShowSql()
                         .Raw("hibernate.generate_statistics", "true");

            var nhConfig = Fluently.Configure()
                           .Database(config)
                           .Mappings(mappings =>
                                     mappings.FluentMappings.AddFromAssemblyOf <CustomerMap>()
                                     .Conventions.AddFromAssemblyOf <IdGenerationConvention>())
                           .ExposeConfiguration(x => new SchemaExport(x).Execute(true, true, false));

            var SessionSource = new SessionSource(nhConfig);

            Session = SessionSource.CreateSession();
            SessionSource.BuildSchema(Session);
        }
Exemplo n.º 23
0
        public void Should_map_all_event_fields_correctly()
        {
            var dateTime = new DateTime(2013, 10, 1);

            var newEvent = new Conference("Some event")
            {
                Location = "Copenhagen",
                Date     = dateTime
            };

            SaveEntities(newEvent);

            var newSession = SessionSource.CreateSession();

            var savedEvent = newSession.Load <Conference>(newEvent.Id);

            savedEvent.Name.ShouldEqual(newEvent.Name);
            savedEvent.Location.ShouldEqual(newEvent.Location);
            savedEvent.Date.ShouldEqual(dateTime);
        }
        static ISession Start(FluentConfiguration instanceBuilderConfiguration, bool reloadDb)
        {
            try
            {
                if (reloadDb)
                {
                    IManagerDataBase managerDataBase = new NhibernateManagerDataBase(instanceBuilderConfiguration);
                    if (!managerDataBase.IsExist())
                    {
                        managerDataBase.Create();
                    }

                    managerDataBase.Update();
                }

                var sessionSource = new SessionSource(instanceBuilderConfiguration);
                return(sessionSource.CreateSession());
            }
            catch (Exception e)
            {
                Clipboard.SetText("Exception in  build configuration {0}".F(e));
                return(null);
            }
        }
Exemplo n.º 25
0
        public void ReturnsNullIfUserNotFound()
        {
            var repository = new UserRepository(null, SessionSource.CreateSession());

            Assert.Null(repository.FindByCredentials(new Credentials("*****@*****.**", "marron")));
        }