Removing files related to unused classes (addition to previous contribution)

This commit is contained in:
Suha Can
2010-12-04 14:43:24 -08:00
parent 10e27ac0a6
commit 848fa508bd
3 changed files with 1 additions and 104 deletions

View File

@@ -1,51 +0,0 @@
using System;
using System.Collections.Generic;
using System.Web.Mvc;
using NUnit.Framework;
using Orchard.Mvc.ModelBinders;
using Orchard.Utility;
namespace Orchard.Tests.Mvc.ModelBinders {
[TestFixture]
public class KeyedListModelBinderTests {
private class Foo {
public string Name { get; set; }
public string Value { get; set; }
}
[Test]
public void BinderShouldBindValues() {
var controllerContext = new ControllerContext();
var binders = new ModelBinderDictionary {
{ typeof(Foo), new DefaultModelBinder() }
};
var input = new FormCollection {
{ "fooInstance[Bar1].Value", "bar1value" },
{ "fooInstance[Bar2].Value", "bar2value" }
};
var foos = new[] {
new Foo {Name = "Bar1", Value = "uno"},
new Foo {Name = "Bar2", Value = "dos"},
new Foo {Name = "Bar3", Value = "tres"},
};
var providers = new EmptyModelMetadataProvider();
var bindingContext = new ModelBindingContext {
ModelMetadata = providers.GetMetadataForType(() => foos, foos.GetType()),
ModelName = "fooInstance",
ValueProvider = input.ToValueProvider()
};
var binder = new KeyedListModelBinder<Foo>(binders, foo => foo.Name);
var result = (IList<Foo>)binder.BindModel(controllerContext, bindingContext);
Assert.That(result.Count, Is.EqualTo(3));
Assert.That(result[0].Value, Is.EqualTo("bar1value"));
Assert.That(result[1].Value, Is.EqualTo("bar2value"));
}
}
}

View File

@@ -328,9 +328,7 @@
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<Folder Include="Mvc\ModelBinders\" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

View File

@@ -1,50 +0,0 @@
using System;
using System.Collections.Generic;
using System.Web.Mvc;
namespace Orchard.Mvc.ModelBinders {
public class KeyedListModelBinder<T> : IModelBinder {
private readonly ModelBinderDictionary _binders;
private readonly ModelMetadataProvider _providers;
private readonly Func<T, string> _keySelector;
public KeyedListModelBinder(
ModelBinderDictionary binders,
Func<T, string> keySelector) {
_binders = binders;
_providers = ModelMetadataProviders.Current;
_keySelector = keySelector;
}
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) {
var binder = _binders.GetBinder(typeof(T));
// given an existing collection
var model = (IList<T>)bindingContext.Model;
if (model != null) {
foreach (var item in model) {
// only update non-null collections
if (Equals(item, default(T)))
continue;
// that have a key value
var key = _keySelector(item);
if (string.IsNullOrEmpty(key))
continue;
// use the configured binder to update the rest of the properties on the object
var currentItem = item;
var itemContext = new ModelBindingContext {
ModelMetadata = _providers.GetMetadataForType(() => currentItem, typeof(T)),
ModelName = bindingContext.ModelName + "[" + key + "]",
ModelState = bindingContext.ModelState,
PropertyFilter = bindingContext.PropertyFilter,
ValueProvider = bindingContext.ValueProvider,
};
binder.BindModel(controllerContext, itemContext);
}
}
return model;
}
}
}