aspnetcore/test/Microsoft.AspNet.Mvc.ModelB.../ValueProviders/QueryStringValueProviderFac...

43 lines
1.5 KiB
C#

// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Globalization;
using Microsoft.AspNet.Http;
#if ASPNET50
using Moq;
#endif
using Xunit;
namespace Microsoft.AspNet.Mvc.ModelBinding.Test
{
public class QueryStringValueProviderFactoryTest
{
private readonly QueryStringValueProviderFactory _factory = new QueryStringValueProviderFactory();
#if ASPNET50
[Fact]
public void GetValueProvider_ReturnsQueryStringValueProviderInstaceWithInvariantCulture()
{
// Arrange
var request = new Mock<HttpRequest>();
request.SetupGet(f => f.Query).Returns(Mock.Of<IReadableStringCollection>());
var context = new Mock<HttpContext>();
context.SetupGet(c => c.Items).Returns(new Dictionary<object, object>());
context.SetupGet(c => c.Request).Returns(request.Object);
var factoryContext = new ValueProviderFactoryContext(
context.Object,
new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase));
// Act
var result = _factory.GetValueProvider(factoryContext);
// Assert
var valueProvider = Assert.IsType<ReadableStringCollectionValueProvider<IQueryValueProviderMetadata>>(result);
Assert.Equal(CultureInfo.InvariantCulture, valueProvider.Culture);
}
#endif
}
}