Exemplo n.º 1
0
        public async Task GetOrAddAsyncTestResultGetSet()
        {
            MetricReliableStateManager target = new MetricReliableStateManager(
                this.GetContext(),
                new JsonReliableStateSerializerResolver(),
                this.GetConfig(),
                new MockReliableStateManager());

            IReliableDictionary <int, string> dictionary = await target.GetOrAddAsync <IReliableDictionary <int, string> >("test://dictionary");

            string expected = "testvalue";

            using (ITransaction tx = target.CreateTransaction())
            {
                await dictionary.SetAsync(tx, 1, expected);

                await tx.CommitAsync();
            }

            using (ITransaction tx = target.CreateTransaction())
            {
                ConditionalValue <string> actual = await dictionary.TryGetValueAsync(tx, 1);

                Assert.AreEqual <string>(expected, actual.Value);
            }
        }
Exemplo n.º 2
0
        public async Task GetOrAddAsyncResultType()
        {
            MetricReliableStateManager target = new MetricReliableStateManager(
                this.GetContext(),
                new JsonReliableStateSerializerResolver(),
                this.GetConfig(),
                new MockReliableStateManager());

            IReliableDictionary <int, string> actual = await target.GetOrAddAsync <IReliableDictionary <int, string> >("test://dictionary");

            Assert.IsTrue(actual is MetricReliableDictionary <int, string>);
        }
Exemplo n.º 3
0
        public async Task EnumerateWithNonMetricCollections()
        {
            Uri dictionaryName = new Uri("test://dictionary");
            Uri queueName      = new Uri("test://queue");

            MetricReliableStateManager target = new MetricReliableStateManager(
                this.GetContext(),
                new JsonReliableStateSerializerResolver(),
                this.GetConfig(),
                new MockReliableStateManager());

            await target.GetOrAddAsync <IReliableDictionary <int, string> >(dictionaryName);

            await target.GetOrAddAsync <IReliableQueue <string> >(queueName);

            List <IReliableState> result = new List <IReliableState>();
            await target.ForeachAsync <IReliableState>(CancellationToken.None, x => result.Add(x));

            Assert.AreEqual <int>(2, result.Count);
            Assert.AreEqual <int>(1, result.Count(x => x.Name == queueName));
            Assert.AreEqual <int>(1, result.Count(x => x.Name == dictionaryName && x is MetricReliableDictionary <int, string>));
        }
Exemplo n.º 4
0
        public async Task GetAsyncWithResultType()
        {
            Uri name = new Uri("test://dictionary");
            MetricReliableStateManager target = new MetricReliableStateManager(
                this.GetContext(),
                new JsonReliableStateSerializerResolver(),
                this.GetConfig(),
                new MockReliableStateManager());

            await target.GetOrAddAsync <IReliableDictionary <int, string> >(name);

            ConditionalValue <IReliableDictionary <int, string> > actual = await target.TryGetAsync <IReliableDictionary <int, string> >(name);

            Assert.IsTrue(actual.HasValue);
            Assert.IsTrue(actual.Value is MetricReliableDictionary <int, string>);
        }
Exemplo n.º 5
0
        public async Task EnumerateSingleItem()
        {
            Uri name = new Uri("test://dictionary");
            MetricReliableStateManager target = new MetricReliableStateManager(
                this.GetContext(),
                new JsonReliableStateSerializerResolver(),
                this.GetConfig(),
                new MockReliableStateManager());

            await target.GetOrAddAsync <IReliableDictionary <int, string> >(name);

            IAsyncEnumerator <IReliableState> enumerator = target.GetAsyncEnumerator();

            bool next = await enumerator.MoveNextAsync(CancellationToken.None);

            MetricReliableDictionary <int, string> actual = enumerator.Current as MetricReliableDictionary <int, string>;

            Assert.IsNotNull(actual);
            Assert.AreEqual <Uri>(name, actual.Name);
            Assert.IsFalse(await enumerator.MoveNextAsync(CancellationToken.None));
        }