Esempio n. 1
0
        public void OnAfterDeserializeShould_RestoreHostingServicesInstancesIfStillAlive()
        {
            m_Manager.Initialize(m_Settings);
            var svc = m_Manager.AddHostingService(typeof(TestHostingService), "test");

            Assert.IsTrue(m_Manager.HostingServices.Contains(svc));

            var generator = new ObjectIDGenerator();
            var id        = generator.GetId(svc, out bool firstTime);

            Assert.IsTrue(firstTime);

            m_Manager.OnBeforeSerialize();
            var serializedData = Serialize(m_Manager);

            svc       = null;
            m_Manager = null;
            m_Settings.HostingServicesManager = null;

            var newManager = new HostingServicesManager();

            m_Settings.HostingServicesManager = newManager;
            newManager.Initialize(m_Settings);

            Deserialize(newManager, serializedData);
            newManager.OnAfterDeserialize();

            Assert.IsNotEmpty(newManager.HostingServices);
            svc = newManager.HostingServices.FirstOrDefault();
            Assert.NotNull(svc);
            var id2 = generator.GetId(svc, out firstTime);

            Assert.IsFalse(firstTime);
            Assert.AreEqual(id, id2);

            m_Manager = newManager;
        }