private void ExecuteProcess()
        {
            // create the session process
            var sessionProcess = _container.Get <ISynchronize>("Session", new IParameter[0]);
            var speakerProcess = _container.Get <ISynchronize>("Speaker", new IParameter[0]);

            using (var scope = new TransactionScope())
            {
                // synchronize speakrs (should go first since session has a dependancy here)
                Logger.Current.LogInformation("Synchronizing Speakers");
                var speakerChanges = speakerProcess.Synchronize();

                // now do the session data
                Logger.Current.LogInformation("Synchronizing Sessions");
                var sessionChanges = sessionProcess.Synchronize();

                // collect the changes and save them
                Logger.Current.LogInformation("Saving Delta Information");
                var allChanges = speakerChanges.Concat(sessionChanges).ToList();
                if (allChanges.Count > 0)
                {
                    var repository = _container.Get <IChangeRepository>();
                    repository.SaveRange(allChanges);
                }

                // complete the transaction
                Logger.Current.LogInformation("Completing the Procss");
                scope.Complete();
            }
        }
        public void test_that_if_a_session_exists_with_an_unmatching_speaker_id_that_session_is_not_saved()
        {
            // arrange
            var sessions = GetTestSessionList();

            sessions.Add(new Session
            {
                SessionId = 9999,
                Title     = "Some Title",
                Abstract  = "Some Abstract",
                End       = DateTime.Now,
                Start     = DateTime.Now,
                Level     = string.Empty,
                Room      = string.Empty,
                Track     = string.Empty,
                SpeakerId = 9999
            });
            var repository = new PollerContainer().Get <ISessionRepository>();

            // act
            repository.SaveRange(sessions);

            // assert
            Assert.IsNull(repository.Get(9999));
        }
Beispiel #3
0
        public void test_general_execution_of_session_worker_process()
        {
            var container = new PollerContainer();
            var process   = container.Get <ISynchronize>("Session");

            process.Synchronize();
        }
Beispiel #4
0
        public void test_that_given_an_invalid_primary_key_value_get_returns_a_null_session_change_instance()
        {
            // arrange
            var repository = new PollerContainer().Get <IChangeRepository>();

            // act
            var sessionChange = repository.Get(int.MaxValue);

            // assert
            Assert.IsNull(sessionChange);
        }
Beispiel #5
0
        public void test_that_given_a_non_matching_condition_get_returns_a_null_instance_of_sessionchange()
        {
            // arrange
            var repository = new PollerContainer().Get <IChangeRepository>();

            // act
            var sessionChange = repository.Get(sc => sc.Key == null);

            // assert
            Assert.IsNull(sessionChange);
        }
        public void test_that_get_with_a_condition_matching_a_speaker_returns_a_non_null_instance()
        {
            // arrange
            var repository = new PollerContainer().Get <ISpeakerRepository>();

            // act
            var speaker = repository.Get(sp => sp.Name != string.Empty);

            // assert
            Assert.IsNotNull(speaker);
        }
        public void test_that_get_with_an_invalid_key_value_returns_a_null_speaker_reference()
        {
            // arrange
            var repository = new PollerContainer().Get <ISpeakerRepository>();

            // act
            var speaker = repository.Get(int.MaxValue);

            // assert
            Assert.IsNull(speaker);
        }
        public void test_that_giving_an_invalid_session_id_to_get_returns_a_null_session_reference()
        {
            // arrange
            var container = new PollerContainer();

            // act
            var session = container.Get <ISessionRepository>().Get(int.MaxValue);

            // assert
            Assert.IsNull(session);
        }
        public void test_that_given_a_matching_condition_get_returns_a_non_null_session_references()
        {
            // arrange
            var container = new PollerContainer();

            // act
            var session = container.Get <ISessionRepository>().Get(s => s.Title != string.Empty);

            // assert
            Assert.IsNotNull(session);
        }
        public void test_that_session_data_can_retrieved_with_a_filter()
        {
            // arrange
            var container = new PollerContainer();

            // act
            var list = container.Get <ISessionRepository>().GetAll(s => s.Abstract.Contains("LINQ"));

            // assert
            Assert.AreNotEqual(0, list.Count);
        }
        public void test_that_a_get_with_a_condition_matching_no_items_returns_a_null_instance()
        {
            // arrange
            var repository = new PollerContainer().Get <ISpeakerRepository>();

            // act
            var speaker = repository.Get(sp => sp.Name == null);

            // assert
            Assert.IsNull(speaker);
        }
        public void test_that_session_data_can_retrieved_using_get_all()
        {
            // arrange
            var container = new PollerContainer();

            // act
            var list = container.Get <ISessionRepository>().GetAll();

            // assert
            Assert.AreNotEqual(0, list.Count);
        }
        public void test_that_get_by_a_valid_key_value_returns_a_non_null_speaker_with_the_given_key()
        {
            // arrange
            var repository = new PollerContainer().Get <ISpeakerRepository>();

            // act
            var speakerId = SpeakerTestDataFactory.GetValidSpeakerId();
            var speaker   = repository.Get(speakerId);

            // assert
            Assert.IsNotNull(speaker);
        }
Beispiel #14
0
        public void test_that_given_a_matching_condition_get_returns_a_non_null_instance_of_sessionchange()
        {
            // arrange
            var repository = new PollerContainer().Get <IChangeRepository>();

            // act
            var sessionChange = repository.Get(sc => sc.Key == "Title" && sc.EntityId == 1);

            // assert
            Assert.IsNotNull(sessionChange);
            Assert.AreEqual(1, sessionChange.EntityId);
        }
Beispiel #15
0
        public void test_that_given_a_valid_primary_key_value_get_returns_a_non_null_sessionchange_instance()
        {
            // arrange
            var repository = new PollerContainer().Get <IChangeRepository>();

            // act
            var lastSessionChangeId = GetLastChangeId();
            var sessionChange       = repository.Get(lastSessionChangeId);

            // assert
            Assert.IsNotNull(sessionChange);
            Assert.AreEqual(lastSessionChangeId, sessionChange.ChangeId);
        }
        public void test_that_given_a_range_of_sessions_those_sessions_are_saved_to_the_database_and_can_be_retrieved()
        {
            // arrange
            var sessions   = GetTestSessionList();
            var container  = new PollerContainer();
            var repository = container.Get <ISessionRepository>();

            // act
            repository.SaveRange(sessions);

            // assert
            Assert.IsTrue(sessions.Count >= repository.GetAll().Count);
        }
        public void test_that_requesting_a_session_using_get_with_a_valid_id_returns_the_appropriate_instance()
        {
            // arrange
            var container = new PollerContainer();
            int sessionId = int.MinValue;

            using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["MainConnectionString"].ConnectionString))
            {
                connection.Open();
                using (var command = new SqlCommand("select max(sessionId) from sessions", connection))
                {
                    sessionId = command.ExecuteScalar().ToString().AsInt();
                }
            }

            // act
            var session = container.Get <ISessionRepository>().Get(sessionId);

            // assert
            Assert.IsNotNull(session);
            Assert.AreEqual(sessionId, session.SessionId);
        }
        public void test_that_given_a_session_range_which_does_not_include_a_session_currently_in_the_database_that_session_should_be_removed()
        {
            // arrange
            var sessions   = GetTestSessionList();
            var container  = new PollerContainer();
            var repository = container.Get <ISessionRepository>();

            // add
            repository.SaveRange(sessions);

            // act
            sessions = repository.GetAll();
            var removedSessionId = sessions[0].SessionId;

            sessions.RemoveAt(0);
            var sessionCount = sessions.Count;

            repository.SaveRange(sessions);

            // assert
            Assert.IsNull(repository.Get(removedSessionId));
            Assert.AreEqual(sessionCount, repository.GetAll().Count);
        }
        public void test_that_given_a_master_with_sessions_matching_existing_sessions_sessions_are_updated_with_new_values()
        {
            // arrange
            var sessions             = GetTestSessionList();
            var originalSessionCount = sessions.Count;
            var container            = new PollerContainer();
            var repository           = container.Get <ISessionRepository>();

            // add test data
            repository.SaveRange(sessions);
            sessions = repository.GetAll();
            long sessionId = sessions[0].SessionId;

            // precondition
            Assert.AreNotEqual(0, sessionId);

            // act
            sessions[0].Title = "new title";
            repository.SaveRange(sessions);

            // assert
            Assert.AreEqual(originalSessionCount, repository.GetAll().Count);
            Assert.AreEqual("new title", repository.Get(sessionId).Title);
        }