a575963da9
Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
47 lines
1.6 KiB
C#
47 lines
1.6 KiB
C#
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
|
|
|
|
using System.Globalization;
|
|
using System.Web.Routing;
|
|
using Xunit;
|
|
using Assert = Microsoft.TestCommon.AssertEx;
|
|
|
|
namespace System.Web.Mvc.Test
|
|
{
|
|
public class RouteDataValueProviderFactoryTest
|
|
{
|
|
[Fact]
|
|
public void GetValueProvider()
|
|
{
|
|
// Arrange
|
|
RouteDataValueProviderFactory factory = new RouteDataValueProviderFactory();
|
|
|
|
ControllerContext controllerContext = new ControllerContext();
|
|
controllerContext.RouteData = new RouteData();
|
|
controllerContext.RouteData.Values["forty-two"] = 42;
|
|
|
|
// Act
|
|
IValueProvider valueProvider = factory.GetValueProvider(controllerContext);
|
|
|
|
// Assert
|
|
Assert.IsType<RouteDataValueProvider>(valueProvider);
|
|
ValueProviderResult vpResult = valueProvider.GetValue("forty-two");
|
|
|
|
Assert.NotNull(vpResult);
|
|
Assert.Equal(42, vpResult.RawValue);
|
|
Assert.Equal("42", vpResult.AttemptedValue);
|
|
Assert.Equal(CultureInfo.InvariantCulture, vpResult.Culture);
|
|
}
|
|
|
|
[Fact]
|
|
public void GetValueProvider_ThrowsIfControllerContextIsNull()
|
|
{
|
|
// Arrange
|
|
RouteDataValueProviderFactory factory = new RouteDataValueProviderFactory();
|
|
|
|
// Act & assert
|
|
Assert.ThrowsArgumentNull(
|
|
delegate { factory.GetValueProvider(null); }, "controllerContext");
|
|
}
|
|
}
|
|
}
|