public string Generate(string targetNamespace) { _logger?.WriteInfo($"Generating classes in namespace '{targetNamespace}"); var shell = new Shell(this) { Namespace = targetNamespace }; foreach (var item in _graphTypesToGenerate) { _logger?.WriteInfo($"Generating GraphType for '{item.Type.Name}"); if (item.Type.IsEnum) { shell.Classes.Add(new EnumerationGraphType(this, item)); } else { shell.Classes.Add(new GraphType(this, item)); } } foreach (var item in _dataLoaderTypesToGenerate) { _logger?.WriteInfo($"Generating DataLoaders for '{item.Type.Name}"); var dataLoaderClass = new DataLoaderExtensions(this, item); if (dataLoaderClass.DataLoaders.Any()) { shell.Classes.Add(dataLoaderClass); } } return(shell.Classes.Any() ? shell.ToString() : null); }
public async Task LoadAsync_MultipleKeysAsParams_CallsSingularMultipleTimes() { var mock = GetMockDataLoader(); var users = await DataLoaderExtensions.LoadAsync(mock.Object, 1, 2).GetResultAsync().ConfigureAwait(false); users.ShouldNotBeNull(); users.Length.ShouldBe(2, "Should return array of same length as number of keys provided"); users[0].ShouldNotBeNull(); users[1].ShouldNotBeNull(); users[0].UserId.ShouldBe(1); users[1].UserId.ShouldBe(2); mock.Verify(x => x.LoadAsync(It.IsAny <int>()), Times.Exactly(2)); }
public async Task LoadAsync_MultipleKeys_CallsSingularMultipleTimes() { var mock = GetMockDataLoader(); var keys = new[] { 1, 2 }; var users = await DataLoaderExtensions.LoadAsync(mock.Object, keys).GetResultAsync(); users.ShouldNotBeNull(); users.Length.ShouldBe(keys.Length, "Should return array of same length as number of keys provided"); users[0].ShouldNotBeNull(); users[1].ShouldNotBeNull(); users[0].UserId.ShouldBe(keys[0]); users[1].UserId.ShouldBe(keys[1]); mock.Verify(x => x.LoadAsync(It.IsAny <int>()), Times.Exactly(keys.Length)); }