Ejemplo n.º 1
0
        public void Should_Sync_DB_With_InMemory_Collection()
        {
            using (DatabaseDataContext db = new DatabaseDataContext())
            {
                // Load all assemblies
                foreach (AssemblyInfo info in db.AssemblyInfo_Get(null, null, null, null, null, null, null, true))
                {
                    PluginLoader.Add(info.Version + ", " + info.Name, info.ReadURL); // Add AssemblyIdentifier !!!!!!!!!!!!!!
                }
            }

            using( IJobManager mgr = new JobManager() )
            {
                bool isSynced = false;
                mgr.SynchronizeOnce();
                mgr.SyncCompleted += (sender, eventArgs) => isSynced = true;

                Timing.WaitUntil(() => isSynced, 10000, "Wait til JobManager is synced");

                // Change the Jobs
                foreach (IJob engineJob in mgr)
                {
                    engineJob.StatusID = 1000;
                }

                isSynced = false;
                mgr.SynchronizeOnce();  // Resync, to make sure changes in the InMemory collection is syncronised as well.
                mgr.SyncCompleted += (sender, eventArgs) => isSynced = true;

                Timing.WaitUntil(() => isSynced, 10000, "Wait til JobManager is synced");

                _DB.Dispose();
                _DB = new DatabaseDataContext();

                int count = _DB.Job_GetUnfinishedJobs().ToList().Count;

                Assert.AreEqual(1, mgr.ToList().Count);

                // Check if all the in memory objects are in the DB, and has the correct values
                foreach (IJob engineJob in mgr)
                {
                    int currentCount = 0;

                    foreach (Data.Job job in _DB.Job_GetUnfinishedJobs().ToList())
                    {
                        currentCount++;

                        if( Compare( engineJob, job ) )
                            break;

                        if( currentCount == count )
                            Assert.Fail(job.ID + " didn't compare correctly");
                    }
                }
            }
        }