public void CanConvert()
 {
     Assert.Equal(null, AmazingConverter.Convert(null, typeof(string)));
     Assert.Equal(0, AmazingConverter.Convert(null, typeof(int)));
     Assert.Equal(0.0f, AmazingConverter.Convert(0, typeof(float)));
     Assert.Equal(0, AmazingConverter.Convert(0L, typeof(int)));
     Assert.Equal("0", AmazingConverter.Convert(0, typeof(string)));
     Assert.Equal(DateTime.MinValue, AmazingConverter.Convert(null, typeof(DateTime)));
     Assert.Equal(35, AmazingConverter.Convert("35", typeof(int)));
     Assert.Equal((XName)"button", AmazingConverter.Convert("button", typeof(XName)));
 }
示例#2
0
 public void CanConvert()
 {
     Assert.AreEqual(null, AmazingConverter.Convert(null, typeof(string)), "reference type");
     Assert.AreEqual(0, AmazingConverter.Convert(null, typeof(int)), "value type");
     Assert.AreEqual(0.0f, AmazingConverter.Convert(0, typeof(float)), "int to float");
     Assert.AreEqual(0, AmazingConverter.Convert(0L, typeof(int)), "long to int");
     Assert.AreEqual("0", AmazingConverter.Convert(0, typeof(string)), "int to string");
     Assert.AreEqual(DateTime.MinValue, AmazingConverter.Convert(null, typeof(DateTime)), "date");
     Assert.AreEqual(35, AmazingConverter.Convert("35", typeof(int)), "string to int");
     Assert.AreEqual((XName)"button", AmazingConverter.Convert("button", typeof(XName)), "op_Implicit");
 }
 public void CanConvert()
 {
     AmazingConverter.Convert(null, typeof(string)).Should().BeNull();
     AmazingConverter.Convert(null, typeof(int)).Should().Be(0);
     AmazingConverter.Convert(0, typeof(float)).Should().Be(0.0f);
     AmazingConverter.Convert(0L, typeof(int)).Should().Be(0);
     AmazingConverter.Convert(0, typeof(string)).Should().Be("0");
     AmazingConverter.Convert(null, typeof(DateTime)).Should().Be(DateTime.MinValue);
     AmazingConverter.Convert("35", typeof(int)).Should().Be(35);
     AmazingConverter.Convert("button", typeof(XName)).Should().Be((XName)"button");
 }
        /// <summary>
        /// Maps a navigation parameters to target action parameter.
        /// </summary>
        /// <param name="request">The controller context.</param>
        /// <param name="bindingContext">The binding context.</param>
        /// <returns>
        /// The value that will be supplied to the action.
        /// </returns>
        public object BindModel(ResolvedNavigationRequest request, ModelBindingContext bindingContext)
        {
            var requestParameter = bindingContext.RouteValues.FirstOrDefault(x => string.Equals(x.Key, bindingContext.TargetParameterName, StringComparison.InvariantCultureIgnoreCase));

            if (requestParameter.Key == null)
            {
                TraceSources.MagellanSource.TraceError("DefaultModelBinder could not find a parameter '{0}' for the method '{1}' in the list of navigation parameters.", request.RouteValues, bindingContext.TargetParameterName);
                throw new ModelBindingException(bindingContext, request);
            }


            var source     = requestParameter.Value;
            var targetType = bindingContext.TargetParameterType;

            return(AmazingConverter.Convert(source, targetType));
        }
示例#5
0
 public T ExecuteScalar <T>(string query, CommandParameterValues args, int?commandTimeoutSeconds = null)
 {
     using (var command = sqlCommandFactory.CreateCommand(connection, transaction, query, args, commandTimeoutSeconds: commandTimeoutSeconds))
     {
         AddCommandTrace(command.CommandText);
         try
         {
             var result = command.ExecuteScalarWithRetry(GetRetryPolicy(RetriableOperation.Select));
             return((T)AmazingConverter.Convert(result, typeof(T)));
         }
         catch (SqlException ex)
         {
             throw WrapException(command, ex);
         }
         catch (Exception ex)
         {
             Log.DebugException($"Exception in relational transaction '{name}'", ex);
             throw;
         }
     }
 }