Example #1
0
        public void Assure_only_given_userDB_is_replaced_with_saved_DB()
        {
            DeleteDatabaseIfExists();
            RecreateSessionFactory();
            repository = new UserdbDatabaseRepository(sessionFactory);
            var firstDB = new Userdb("default");
            firstDB.AddUser(new User("haldis"));

            var secondDB = new Userdb("not_default");
            secondDB.AddUser(new User("kari"));

            repository.Save(firstDB);
            repository.Save(secondDB);

            var firstDBUpdate = new Userdb("default");
            firstDBUpdate.AddUser(new User("tuxbear"));

            repository.Save(firstDBUpdate);

            var result = repository.Get(new AllSpecification<Userdb>());
            result.Count().ShouldBe(2);
            result.ElementAt(0).Name.ShouldBe("default");
            result.ElementAt(0).Users.First().Username.ShouldBe("tuxbear");
            result.ElementAt(1).Name.ShouldBe("not_default");
            result.ElementAt(1).Users.First().Username.ShouldBe("kari");

        }
Example #2
0
        private void SaveCurrentUserdb()
        {
            var userdb = new Userdb(viewModel.CurrentDBName);

            foreach (var userViewModel in viewModel.Users)
            {
                userdb.AddUser(CreateUserDomainModelFromUserViewModel(userViewModel));
            }

            userdbPersisterRepository.Save(userdb);
        }
        public void Assure_data_is_persisted()
        {
            Scenario.StartNew(this, scenario =>
            {
                scenario.Given(Database_is_created).
                    And(WebServiceClient_is_created);

                scenario.When("save", () =>
                {
                    var userdb = new Userdb("default");

                    userdb.AddUser(new User("ghansen")
                    {
                        Email = "*****@*****.**",
                        Firstname = "Gøran",
                        Surname = "Hansen",
                        ImageUrl = "http://goeran.no/avatar.jpg"
                    });
                    userRepositoryServiceClient.Save(new [] {userdb});
                });

                scenario.Then("assure data is persisted", () =>
                {
                    var user = databaseSession.CreateCriteria(typeof(User)).List<User>().
                        Where(u => u.Username == "ghansen").SingleOrDefault();
                    user.ShouldNotBeNull();
                    user.Database.ShouldNotBeNull();
                });
            });
        }