Exemplo n.º 1
0
        public async Task TestGetOrAddAsync()
        {
            var dict = new Dictionary<string, string>();
            await dict.GetOrAddAsync("x", () => Task.FromResult("a"));
            await dict.GetOrAddAsync("x", () => Task.FromResult("b"));

            dict.Should().Equal(new Dictionary<string, string> {["x"] = "a"});
        }
Exemplo n.º 2
0
        public async Task TestGetOrAddAsync()
        {
            var dict = new Dictionary <string, string>();
            await dict.GetOrAddAsync("x", () => Task.FromResult("a"));

            await dict.GetOrAddAsync("x", () => Task.FromResult("b"));

            dict.Should().Equal(new Dictionary <string, string> {
                ["x"] = "a"
            });
        }
Exemplo n.º 3
0
        private async Task <TableSet <T> > GetViewAsync <T>() where T : class, ITableEntity, new()
        {
            var value = await TableSets.GetOrAddAsync(typeof(T), async() =>
            {
                var view = tableClient.GetTableReference($"{this.options.Prefix}{this.GetViewAttribute(typeof(T)).TableName}");
                await view.CreateIfNotExistsAsync();
                var countryTable = new TableSet <T>(tableClient, $"{this.options.Prefix}{this.GetViewAttribute(typeof(T)).TableName}");
                return((object)countryTable);;
            });

            return((TableSet <T>)value);
        }
Exemplo n.º 4
0
        public async Task TestGetOrAddAsyncRace()
        {
            var mock1 = new Mock();
            var dict = new Dictionary<string, Mock> {["x"] = mock1};

            var mock2 = new Mock();
            var delayedSource = new TaskCompletionSource<Mock>();
            var task = dict.GetOrAddAsync("x", () => delayedSource.Task);
            delayedSource.SetResult(mock2);
            await task;

            dict.Should().Equal(new Dictionary<string, Mock> {["x"] = mock1});

            mock1.IsDisposed.Should().BeFalse();
            mock2.IsDisposed.Should().BeFalse();
        }
Exemplo n.º 5
0
        public async Task TestGetOrAddAsyncRace()
        {
            var mock1 = new Mock();
            var dict  = new Dictionary <string, Mock> {
                ["x"] = mock1
            };

            var mock2         = new Mock();
            var delayedSource = new TaskCompletionSource <Mock>();
            var task          = dict.GetOrAddAsync("x", () => delayedSource.Task);

            delayedSource.SetResult(mock2);
            await task;

            dict.Should().Equal(new Dictionary <string, Mock> {
                ["x"] = mock1
            });

            mock1.IsDisposed.Should().BeFalse();
            mock2.IsDisposed.Should().BeFalse();
        }
Exemplo n.º 6
0
 private Task <CloudTable> GetViewAsync(Type type) => Views.GetOrAddAsync(type, async() =>
 {
     var view = tableClient.GetTableReference($"{this.options.Prefix}{this.GetViewAttribute(type).TableName}");
     await view.CreateIfNotExistsAsync();
     return(view);
 });
Exemplo n.º 7
0
 private Task <CloudTable> GetTableAsync(Type type)
 => Tables.GetOrAddAsync(type, () => this.GetCloudTableAsync($"{this.options.Prefix}{this.GetTableAttribute(type).TableName}"));