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"}); }
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" }); }
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); }
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(); }
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(); }
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); });
private Task <CloudTable> GetTableAsync(Type type) => Tables.GetOrAddAsync(type, () => this.GetCloudTableAsync($"{this.options.Prefix}{this.GetTableAttribute(type).TableName}"));