Beispiel #1
0
        public void BasicUsage()
        {
            var observers = new ObserverSet <DummyObserver>();
            var dummy     = new DummyObserver();
            var weakDummy = new DummyObserver();

            observers.Add(dummy);
            observers.AddWeak(weakDummy);
            observers.Use(d => d.Used = true);
            Assert.True(dummy.Used);
            Assert.True(weakDummy.Used);
        }
Beispiel #2
0
        public async Task ObserverTest_CreateObjectReference_ThrowsForInvalidArgumentTypes()
        {
            TestInitialize();

            // Attempt to create an object reference to a Grain class.
            await Assert.ThrowsAsync <ArgumentException>(() => this.Client.CreateObjectReference <ISimpleGrainObserver>(new DummyObserverGrain()));

            // Attempt to create an object reference to an existing GrainReference.
            var observer  = new DummyObserver();
            var reference = await this.Client.CreateObjectReference <ISimpleGrainObserver>(observer);

            await Assert.ThrowsAsync <ArgumentException>(() => this.Client.CreateObjectReference <ISimpleGrainObserver>(reference));
        }
Beispiel #3
0
        public void UsageCount()
        {
            var observers = new ObserverSet <DummyObserver>();
            var dummyA    = new DummyObserver();
            var dummyB    = new DummyObserver();

            observers.Add(dummyA);
            observers.Use(d => d.UsedCount++);
            Assert.AreEqual(1, dummyA.UsedCount);

            observers.Add(dummyB);
            observers.Use(d => d.UsedCount++);
            Assert.AreEqual(2, dummyA.UsedCount);
            Assert.AreEqual(1, dummyB.UsedCount);

            observers.Remove(dummyA);
            observers.Use(d => d.UsedCount++);
            Assert.AreEqual(2, dummyA.UsedCount);
            Assert.AreEqual(2, dummyB.UsedCount);
        }