public void FormatOperator_ConfirmNamedOperationIsSupported() { string op = "add"; string formattedOp = InputFormatter.FormatOperator(op); Assert.AreEqual(op, formattedOp); }
public void ConfirmMultiplyNamedOperationIsNotSupported() { string op = "multiply"; string formattedOp = InputFormatter.FormatOperator(op); Assert.AreEqual("*", formattedOp); }
public VariableCoercionHelper(InputFormatter inputFormatter, InputParser inputParser) { _inputFormatter = inputFormatter ?? throw new ArgumentNullException(nameof(inputFormatter)); _inputParser = inputParser ?? throw new ArgumentNullException(nameof(inputParser)); }
public void ConfirmSubtractSymbolicOperationIsSupported() { string op = "-"; string formattedOp = InputFormatter.FormatOperator(op); Assert.AreEqual("-", formattedOp); }
public void ConfirmDivideNamedOperationIsNotSupported() { string op = "divide"; string formattedOp = InputFormatter.FormatOperator(op); Assert.AreEqual("/", formattedOp); }
public static void ConfigureMvc(this IServiceCollection services) { services.AddMvc(options => { options.ReturnHttpNotAcceptable = true; // Response types that should be applied to all action methods across all controllers options.Filters.Add(new ProducesResponseTypeAttribute(StatusCodes.Status400BadRequest)); options.Filters.Add(new ProducesResponseTypeAttribute(StatusCodes.Status401Unauthorized)); options.Filters.Add(new ProducesResponseTypeAttribute(StatusCodes.Status406NotAcceptable)); options.Filters.Add(new ProducesResponseTypeAttribute(StatusCodes.Status500InternalServerError)); OutputFormatter jsonOutputFormatter = options.OutputFormatters.OfType <JsonOutputFormatter>().First(); jsonOutputFormatter.SupportedMediaTypes.Add("application/vnd.the-phone-book.phonebook+json"); InputFormatter jsonInputFormatter = options.InputFormatters.OfType <JsonInputFormatter>().First(); jsonInputFormatter.SupportedMediaTypes.Add("application/vnd.the-phone-book.phonebookforupdate+json"); // All controllers will be locked down // Those that should not should apply the [AllowAnonymous] attribute options.Filters.Add(new AuthorizeFilter( new AuthorizationPolicyBuilder(JwtBearerDefaults.AuthenticationScheme) .RequireAuthenticatedUser().Build())); }) .AddJsonOptions(options => options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver()) .SetCompatibilityVersion(CompatibilityVersion.Version_2_2); }
public void ConfirmMultiplySymbolicOperationIsSupported() { string op = "*"; string formattedOp = InputFormatter.FormatOperator(op); Assert.AreEqual("*", formattedOp); }
public void ConfirmDivideSymbolicOperationIsSupported() { string op = "/"; string formattedOp = InputFormatter.FormatOperator(op); Assert.AreEqual("/", formattedOp); }
public void ConvertStringToNumber() { string num = "1"; double formattedNum = InputFormatter.FormatNumber(num); Assert.AreEqual(1, formattedNum); }
public void ConfirmAddNamedOperationIsNotSupported() { string op = "add"; string formattedOp = InputFormatter.FormatOperator(op); Assert.AreEqual("+", formattedOp); }
public void ConfirmSubtractNamedOperationIsNotSupported() { string op = "subtract"; string formattedOp = InputFormatter.FormatOperator(op); Assert.AreEqual("-", formattedOp); }
public void FormatNumber_ConvertStringToNumber() { string num = "1"; double number = Convert.ToDouble(num); double formattedNum = InputFormatter.FormatNumber(num); Assert.AreEqual(number, formattedNum); }
public ScopedVariableValue Resolve( IResolverContext context, ScopedVariableNode variable, IInputType targetType) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (variable == null) { throw new ArgumentNullException(nameof(variable)); } if (!ScopeNames.Fields.Equals(variable.Scope.Value)) { throw new ArgumentException( FieldScopedVariableResolver_CannotHandleVariable, nameof(variable)); } if (context.ObjectType.Fields.TryGetField(variable.Name.Value, out IObjectField? field)) { object parent = context.Parent <object>(); IValueNode?valueLiteral = null; if (parent is IReadOnlyDictionary <string, object> dict && dict.TryGetValue(field.Name, out var value)) { InputFormatter formatter = context.Service <InputFormatter>(); if (value is IValueNode v) { valueLiteral = v; } else if (field.Type.IsInputType() && field.Type is IInputType type) { valueLiteral = formatter.FormatValue(value, type, field.Name); } } return(new ScopedVariableValue ( variable.ToVariableName(), targetType.ToTypeNode(), valueLiteral ?? NullValueNode.Default, null )); } throw ThrowHelper.FieldScopedVariableResolver_InvalidFieldName( variable.Name.Value, context.Selection.SyntaxNode, context.Path); }
public void ParseValue_Should_Pass_When_NullValue(string typeName) { // arrange var inputFormatter = new InputFormatter(); INamedInputType type = CreateInputType(typeName); // act // assert Assert.Equal(NullValueNode.Default, inputFormatter.FormatValue(null, type)); }
public void Register(Version fromInclusive, Version toExclusive, InputFormatter formatter) { var range = new VersionRange(fromInclusive, toExclusive); if (_formatters.Any(f => f.Item1.IsOverlapping(range)) == true) { throw new ArgumentException("Version ranges must not overlap."); } _formatters.Add(new Tuple <VersionRange, InputFormatter>(range, formatter)); }
public void ParseValue_Should_Throw_When_InvalidType(string typeName) { // arrange var inputFormatter = new InputFormatter(); INamedInputType type = CreateInputType(typeName); // act // assert Assert.Throws <SerializationException>(() => inputFormatter.FormatValue("", type)); }
public HttpRouteBodyModelBinder( IHttpRequestStreamReaderFactory readerFactory, ILoggerFactory loggerFactory, ArrayPool <char> charPool, ObjectPoolProvider objectPoolProvider) { _input = new NewtonsoftJsonInputFormatter( loggerFactory.CreateLogger(typeof(HttpRouteBodyModelBinder)), HttpFormatters.Route.SerializerSettings, charPool, objectPoolProvider, new MvcOptions(), new MvcNewtonsoftJsonOptions()); _readerFactory = readerFactory.CreateReader; }
public void ParseValue_Should_Pass_When_Value(string typeName) { // arrange var inputFormatter = new InputFormatter(); INamedInputType type = CreateInputType(typeName); // act IValueNode literal = inputFormatter.FormatValue(_geometry, type); // assert literal.ToString().MatchSnapshot(); }
public BatchExecutor( IErrorHandler errorHandler, ITypeConverter typeConverter, InputFormatter inputFormatter) { _errorHandler = errorHandler ?? throw new ArgumentNullException(nameof(errorHandler)); _typeConverter = typeConverter ?? throw new ArgumentNullException(nameof(typeConverter)); _inputFormatter = inputFormatter ?? throw new ArgumentNullException(nameof(inputFormatter)); }
/// <exception cref="InvalidRouteException"></exception> /// <exception cref="WaypointNotFoundException"></exception> private Route ReadMainRoute(List <string> route) { var latLon = trk.PreferredFirstLatLon; var analyzer = new AutoSelectAnalyzer( InputFormatter.Split(CombineArray(route)), latLon, latLon, wptList); return(analyzer.Analyze()); }
public ScopedVariableValue Resolve( IResolverContext context, ScopedVariableNode variable, IInputType targetType) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (variable == null) { throw new ArgumentNullException(nameof(variable)); } if (targetType == null) { throw new ArgumentNullException(nameof(targetType)); } if (!ScopeNames.ContextData.Equals(variable.Scope.Value)) { throw new ArgumentException( ContextDataScopedVariableResolver_CannotHandleVariable, nameof(variable)); } context.ContextData.TryGetValue(variable.Name.Value, out var data); InputFormatter formatter = context.Service <InputFormatter>(); IValueNode literal = data switch { IValueNode l => l, null => NullValueNode.Default, _ => formatter.FormatValue(data, targetType, Path.New(variable.Name.Value)) }; return(new ScopedVariableValue ( variable.ToVariableName(), targetType.ToTypeNode(), literal, null )); } }
public void CreateVariableValue() { // arrange var inputFormatter = new InputFormatter(); ISchema schema = SchemaBuilder.New() .AddDocumentFromString("type Query { foo(a: String = \"bar\") : String a: String }") .Use(_ => _) .ModifyOptions(o => o.StrictValidation = false) .Create(); var context = new Mock <IResolverContext>(MockBehavior.Strict); context.SetupGet(t => t.ObjectType).Returns( schema.GetType <ObjectType>("Query")); context.SetupGet(t => t.Field).Returns( schema.GetType <ObjectType>("Query").Fields["foo"]); context.Setup(t => t.Parent <object>()) .Returns(new Dictionary <string, object> { { "a", "baz" } }); context.Setup(t => t.Service <InputFormatter>()).Returns(inputFormatter); var scopedVariable = new ScopedVariableNode( null, new NameNode("fields"), new NameNode("a")); // act var resolver = new FieldScopedVariableResolver(); ScopedVariableValue value = resolver.Resolve( context.Object, scopedVariable, schema.GetType <StringType>("String")); // assert Assert.Null(value.DefaultValue); Assert.Equal("__fields_a", value.Name); Assert.IsType <NamedTypeNode>(value.Type); Assert.Equal("baz", value.Value.Value); }
public void CreateVariableValue() { // arrange var inputFormatter = new InputFormatter(); ISchema schema = SchemaBuilder.New() .AddDocumentFromString("type Query { foo(a: String = \"bar\") : String }") .Use(_ => _) .ModifyOptions(o => o.StrictValidation = false) .Create(); ImmutableDictionary <string, object> contextData = ImmutableDictionary <string, object> .Empty .Add("a", "AbcDef"); var context = new Mock <IResolverContext>(MockBehavior.Strict); context.SetupGet(t => t.ScopedContextData).Returns(contextData); context.Setup(t => t.Service <InputFormatter>()).Returns(inputFormatter); var scopedVariable = new ScopedVariableNode( null, new NameNode("scopedContextData"), new NameNode("a")); // act var resolver = new ScopedContextDataScopedVariableResolver(); ScopedVariableValue value = resolver.Resolve( context.Object, scopedVariable, schema.GetType <StringType>("String")); // assert Assert.Null(value.DefaultValue); Assert.Equal("__scopedContextData_a", value.Name); Assert.Equal("String", Assert.IsType <NamedTypeNode>(value.Type).Name.Value); Assert.Equal("AbcDef", value.Value !.Value); }
/// <summary> /// Reads a record using the input formatter if required. /// </summary> /// <param name="reader">the reader to read from</param> /// <returns>the read record</returns> private T ReadRecord(IRecordReader <T> reader) { var record = reader.Read(); return(InputFormatter == null || record == null ? record : InputFormatter.Format(record)); }
public void SetUp() { sut = new InputFormatter(); }
public void DivideTwoNumbersWithSecondLargest() { double result = Calculator.Calculate(2, 4, InputFormatter.FormatOperator("divide")); Assert.AreEqual(2, result); }
public void MultiplyTwoNumbersWithMultiply() { double result = Calculator.Calculate(4, 2, InputFormatter.FormatOperator("multiply")); Assert.AreEqual(8, result); }
public void SubtractTwoNumbersFirstLargest() { double result = Calculator.Calculate(8, 2, InputFormatter.FormatOperator("subtract")); Assert.AreEqual(6, result); }
public void SubtractTwoNumbersWithSecondLargest() { double result = Calculator.Calculate(5, 8, InputFormatter.FormatOperator("subtract")); Assert.AreEqual(3, result); }
public void AddTwoNumbersWithAdd() { double result = Calculator.Calculate(12, 3, InputFormatter.FormatOperator("add")); Assert.AreEqual(15, result); }