Example #1
0
        public void ServiceManager_Test01()
        {
            PropertyOwner propertyOwner = new PropertyOwner();
            Service1      s1            = new Service1();
            bool          added         = false;
            bool          removed       = false;

            ServiceManager.AdviseServiceAdded <IService1>(propertyOwner, null, s => { added = true; });

            // Verify notifications not sent out when advising
            added.Should().BeFalse();

            // Verify notifications not sent out after adding other service
            ServiceManager.AddService <Service1>(s1, propertyOwner, null);
            added.Should().BeFalse();

            // Verify added notification sent out after adding this service
            ServiceManager.AddService <IService1>(s1, propertyOwner, null);
            added.Should().BeTrue();

            added = false;
            ServiceManager.AdviseServiceRemoved <IService1>(propertyOwner, null, s => { removed = true; });

            // Verify notifications not sent out after removing other service
            ServiceManager.RemoveService <Service1>(propertyOwner);
            removed.Should().BeFalse();

            // Verify removed notification sent out after adding this service
            ServiceManager.RemoveService <IService1>(propertyOwner);
            removed.Should().BeTrue();

            // Verify we aren't still listening to advised events
            ServiceManager.AddService <IService1>(s1, propertyOwner, null);
            added.Should().BeFalse();

            // Verify notification sent out when advising to existing service
            ServiceManager.AdviseServiceAdded <IService1>(propertyOwner, null, s => { added = true; });
            added.Should().BeTrue();
        }