Ejemplo n.º 1
0
        public void TestRemoveOneProxy()
        {
            var storage = new ProxyStorage(_endPoint.Object, _channel.Object, _codeGenerator.Object);

            var proxy = storage.CreateProxy <IByReferenceType>(1234);

            proxy.Should().NotBeNull();

            storage.GetProxy <IByReferenceType>(1234).Should().BeSameAs(proxy);
            storage.GetExistingOrCreateNewProxy <IByReferenceType>(1234).Should().BeSameAs(proxy);
            IProxy actualProxy;
            int    unused;

            storage.TryGetProxy(1234, out actualProxy, out unused);
            actualProxy.Should().BeSameAs(proxy);

            storage.RemoveProxiesInRange(1234, 1234);
            new Action(() => storage.GetProxy <IByReferenceType>(1234)).ShouldThrow <ArgumentException>();
            var newProxy = storage.GetExistingOrCreateNewProxy <IByReferenceType>(1234);

            newProxy.Should().NotBeNull();
            newProxy.Should().NotBeSameAs(proxy);
            storage.TryGetProxy(1234, out actualProxy, out unused);
            actualProxy.Should().BeSameAs(newProxy);
        }
Ejemplo n.º 2
0
        public void TestRemoveSeveralProxies()
        {
            var storage = new ProxyStorage(_endPoint.Object, _channel.Object, _codeGenerator.Object);

            var proxies = Enumerable.Range(1000, 100).Select(i => storage.CreateProxy <IByReferenceType>((ulong)i))
                          .ToList();

            for (int i = 0; i < 100; ++i)
            {
                var objectId = (ulong)(1000 + i);
                storage.GetProxy <IByReferenceType>(objectId).Should().BeSameAs(proxies[i]);
            }

            storage.RemoveProxiesInRange(1042, 1058);

            for (int i = 0; i < 42; ++i)
            {
                var objectId = (ulong)(1000 + i);
                storage.GetProxy <IByReferenceType>(objectId).Should().BeSameAs(proxies[i]);
            }

            for (int i = 43; i < 59; ++i)
            {
                var objectId = (ulong)(1000 + i);
                new Action(() => storage.GetProxy <IByReferenceType>(objectId)).ShouldThrow <ArgumentException>();
                IProxy proxy;
                int    numProxies;
                storage.TryGetProxy(objectId, out proxy, out numProxies);
                proxy.Should().BeNull();
            }

            for (int i = 59; i < 100; ++i)
            {
                var objectId = (ulong)(1000 + i);
                storage.GetProxy <IByReferenceType>(objectId).Should().BeSameAs(proxies[i]);
            }
        }