Jo Shields a575963da9 Imported Upstream version 3.6.0
Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
2014-08-13 10:39:27 +01:00

48 lines
1.5 KiB
C#

// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System;
using System.Web.Mvc;
using Xunit;
namespace Microsoft.Web.Mvc.ModelBinding.Test
{
public class ComplexModelDtoModelBinderProviderTest
{
[Fact]
public void GetBinder_TypeDoesNotMatch_ReturnsNull()
{
// Arrange
ComplexModelDtoModelBinderProvider provider = new ComplexModelDtoModelBinderProvider();
ExtensibleModelBindingContext bindingContext = GetBindingContext(typeof(object));
// Act
IExtensibleModelBinder binder = provider.GetBinder(null, bindingContext);
// Assert
Assert.Null(binder);
}
[Fact]
public void GetBinder_TypeMatches_ReturnsBinder()
{
// Arrange
ComplexModelDtoModelBinderProvider provider = new ComplexModelDtoModelBinderProvider();
ExtensibleModelBindingContext bindingContext = GetBindingContext(typeof(ComplexModelDto));
// Act
IExtensibleModelBinder binder = provider.GetBinder(null, bindingContext);
// Assert
Assert.IsType<ComplexModelDtoModelBinder>(binder);
}
private static ExtensibleModelBindingContext GetBindingContext(Type modelType)
{
return new ExtensibleModelBindingContext
{
ModelMetadata = new EmptyModelMetadataProvider().GetMetadataForType(() => null, modelType)
};
}
}
}