public void RemoveCanBeUsedToUnregister() { var dictionary = new ModelBinderDictionary(new DefaultModelBinder()); dictionary.Add(typeof(DataSet), FakeBinder); dictionary.Remove(FakeBinder); dictionary.Add(typeof(DataSet), FakeBinder); dictionary.Remove(FakeBinder); dictionary.Add(typeof(DataSet), FakeBinder); }
public void ClearCanBeUsedToRemoveAllRegistrations() { var dictionary = new ModelBinderDictionary(new DefaultModelBinder()); dictionary.Add(typeof(DataSet), FakeBinder); Assert.IsTrue(dictionary.Contains(FakeBinder)); dictionary.Clear(); Assert.IsFalse(dictionary.Contains(FakeBinder)); }
public void ShouldResolveBindersViaInheritance() { var dictionary = new ModelBinderDictionary(new DefaultModelBinder()); dictionary.Add(typeof(IListSource), FakeBinder); var binder = dictionary.GetBinder(typeof(DataSet)); // DataSet implements IListSource Assert.AreSame(FakeBinder, binder); }
public void ShouldResolveBinder() { var dictionary = new ModelBinderDictionary(new DefaultModelBinder()); dictionary.Add(typeof(DataSet), FakeBinder); var binder = dictionary.GetBinder(typeof(DataSet)); Assert.AreSame(FakeBinder, binder); }
public void ContainsCanBeUsedToCheckForPriorRegistration() { var dictionary = new ModelBinderDictionary(new DefaultModelBinder()); Assert.IsFalse(dictionary.Contains(FakeBinder)); dictionary.Add(typeof(DataSet), FakeBinder); Assert.IsTrue(dictionary.Contains(FakeBinder)); dictionary.Remove(FakeBinder); Assert.IsFalse(dictionary.Contains(FakeBinder)); }
public void ShouldFallBackToDefaultBinder() { var dictionary = new ModelBinderDictionary(new DefaultModelBinder()); dictionary.Add(typeof(DataSet), FakeBinder); var binder = dictionary.GetBinder(typeof(int)); Assert.IsInstanceOf<DefaultModelBinder>(binder); }
public void MultipleBindersCannotBeRegisteredForSameType() { var dictionary = new ModelBinderDictionary(new DefaultModelBinder()); dictionary.Add(typeof(DataSet), FakeBinder); Assert.Throws<ArgumentException>(() => dictionary.Add(typeof(DataSet), FakeBinder)); }
public void ShouldAllowModelBindersToBeRegistered() { var dictionary = new ModelBinderDictionary(new DefaultModelBinder()); dictionary.Add(typeof(DataSet), FakeBinder); }