private static void ExtractData( IDictionary <string, string> aliases, IQueryResult mergedResult, QueryResultBuilder result) { var data = new ResultMap(); data.EnsureCapacity(aliases.Count); var i = 0; if (mergedResult.Data is not null) { foreach (KeyValuePair <string, string> alias in aliases) { if (mergedResult.Data.TryGetValue(alias.Key, out object?o)) { data.SetValue(i++, alias.Value, o); } } } else { foreach (KeyValuePair <string, string> alias in aliases) { data.SetValue(i++, alias.Value, null); } } result.SetData(data); }
public void Complete() { // arrange var resultMap = new ResultMap(); resultMap.EnsureCapacity(5); // act resultMap.SetValue(0, "abc1", "def"); resultMap.SetValue(2, "abc2", "def"); resultMap.SetValue(4, "abc3", "def"); resultMap.Complete(); // assert Assert.Collection( (IEnumerable <ResultValue>)resultMap, t => { Assert.Equal("abc1", t.Name); Assert.Equal("def", t.Value); }, t => { Assert.Equal("abc2", t.Name); Assert.Equal("def", t.Value); }, t => { Assert.Equal("abc3", t.Name); Assert.Equal("def", t.Value); }); }
public IResultMap Build() { if (_parsingResult is null) { // in the case that the request pipeline cached the parsed document, // we will set the parsing duration to 0. SetParsingResult(_startTimestamp, _startTimestamp); } if (_validationResult is null) { // in the case that the request pipeline cached the validation result, // we will set the validation duration to 0. SetValidationResult(_startTimestamp, _startTimestamp); } var executionResult = new ResultMap(); executionResult.EnsureCapacity(1); executionResult.SetValue(0, ApolloTracingResultKeys.Resolvers, BuildResolverResults()); var result = new ResultMap(); result.EnsureCapacity(7); result.SetValue(0, ApolloTracingResultKeys.Version, _apolloTracingVersion); result.SetValue(1, StartTime, _startTime.ToRfc3339DateTimeString()); result.SetValue(2, EndTime, _startTime.Add(_duration).ToRfc3339DateTimeString()); result.SetValue(3, Duration, _duration.Ticks * _ticksToNanosecondsMultiplicator); result.SetValue(4, Parsing, _parsingResult); result.SetValue(5, ApolloTracingResultKeys.Validation, _validationResult); result.SetValue(6, ApolloTracingResultKeys.Execution, executionResult); return(result); }
public void GetValue_ValueIsFound(int capacity) { // arrange var resultMap = new ResultMap(); resultMap.EnsureCapacity(capacity); resultMap.SetValue(0, "abc", "def"); resultMap.SetValue(1, "def", "def"); resultMap.SetValue(2, "ghi", "def"); // act ResultValue value = resultMap.GetValue("def", out int index); // assert Assert.Equal("def", value.Name); Assert.Equal(1, index); }
public ResultMap Create_And_Fill_ResultMap() { _resultMap.EnsureCapacity(Size); for (int i = 0; i < Size; i++) { _resultMap.SetValue(i, i.ToString(), i); } _resultMap.Clear(); return(_resultMap); }
private static QueryResultBuilder ExtractResult( IDictionary <string, string> aliases, IQueryResult mergedResult, ICollection <IError> handledErrors) { var result = QueryResultBuilder.New(); if (mergedResult.Data is not null) { var data = new ResultMap(); data.EnsureCapacity(aliases.Count); var i = 0; foreach (KeyValuePair <string, string> alias in aliases) { if (mergedResult.Data.TryGetValue(alias.Key, out object?o)) { data.SetValue(i++, alias.Value, o); } } result.SetData(data); } if (mergedResult.Errors is not null) { foreach (IError error in mergedResult.Errors) { if (TryResolveField(error, aliases, out string?responseName)) { handledErrors.Add(error); result.AddError(RewriteError(error, responseName)); } } } if (mergedResult.Extensions is not null) { result.SetExtensions(mergedResult.Extensions); } if (mergedResult.ContextData is not null) { foreach (KeyValuePair <string, object?> item in mergedResult.ContextData) { result.SetContextData(item.Key, item.Value); } } return(result); }
public void BuildResult_SimpleResultSet_SnapshotMatches() { // arrange var helper = new ResultHelper(CreatePool()); ResultMap map = helper.RentResultMap(1); map.SetValue(0, "abc", "def", false); helper.SetData(map); // act IReadOnlyQueryResult result = helper.BuildResult(); // assert result.ToJson().MatchSnapshot(); }
private ResultMap[] BuildResolverResults() { var i = 0; var results = new ResultMap[_resolverRecords.Count]; foreach (ApolloTracingResolverRecord record in _resolverRecords) { var result = new ResultMap(); result.EnsureCapacity(6); result.SetValue(0, ApolloTracingResultKeys.Path, record.Path); result.SetValue(1, ParentType, record.ParentType); result.SetValue(2, FieldName, record.FieldName); result.SetValue(3, ReturnType, record.ReturnType); result.SetValue(4, StartOffset, record.StartTimestamp - _startTimestamp); result.SetValue(5, Duration, record.EndTimestamp - record.StartTimestamp); results[i++] = result; } return(results); }