public void ShouldManageMoreThanOneObjectPerType() { var viewData = new ViewDataDictionary { { "key1", new Url("/1") }, { "key2", new Url("/2") } }; Assert.That(viewData.Get <Url>("key1").Value, Is.EqualTo("/1")); Assert.That(viewData.Get <Url>("key2").Value, Is.EqualTo("/2")); }
public void ShouldRetrieveSingleObjectByType() { var viewData = new ViewDataDictionary(); var url = new Url("/asdf"); //arbitrary object viewData.Add(url); Assert.That(viewData.Get <Url>(), Is.EqualTo(url)); Assert.That(viewData.Get(typeof(Url)), Is.EqualTo(url)); }
public void ShouldInitializeWithProxiesAndResolveCorrectly() { var messageProxy = MockRepository.GenerateStub <MailMessage>(); var xmlDocumentProxy = MockRepository.GenerateStub <XmlDocument>(); var viewData = new ViewDataDictionary(); viewData.Add(messageProxy).Add(xmlDocumentProxy); Assert.That(viewData.Get <MailMessage>(), Is.EqualTo(messageProxy)); Assert.That(viewData.Get <XmlDocument>(), Is.EqualTo(xmlDocumentProxy)); }
/// <summary> /// Gets typed value from the ViewDataDictionary or valueIfNull /// </summary> public static T Get <T>(this ViewDataDictionary viewData, string key, T valueIfNull) { if (viewData[key] == null) { return(valueIfNull); } return(viewData.Get <T>(key)); }
/// <summary> /// Gets typed value from the ViewDataDictionary or the type default /// </summary> public static T GetDefault <T>(this ViewDataDictionary viewData, string key) { if (viewData[key] == null) { return(default(T)); } return(viewData.Get <T>(key)); }
public void ShouldHandleProxiedObjectsByType() { var mailMessageStub = MockRepository.GenerateStub<MailMessage>(); var viewData = new ViewDataDictionary(); viewData.Add(mailMessageStub); var message = viewData.Get<MailMessage>(); Assert.That(message, Is.EqualTo(mailMessageStub)); }
public void ShouldGetObjectBasedOnType() { var url = new Url("/1"); var identity = new GenericIdentity("name"); var viewData = new ViewDataDictionary(); viewData.Add(identity).Add(url); viewData.Get(typeof(MailMessage)); }
public void ShouldHandleProxiedObjectsByType() { var mailMessageStub = MockRepository.GenerateStub <MailMessage>(); var viewData = new ViewDataDictionary(); viewData.Add(mailMessageStub); var message = viewData.Get <MailMessage>(); Assert.That(message, Is.EqualTo(mailMessageStub)); }
public static bool GetOrSetThenGet(this ViewDataDictionary v, string key, bool?newVal = null, bool force = false) { if (newVal.HasValue && !v.ContainsKey(key)) { if (force || !v.ContainsKey(key)) { v[key] = newVal.Value; } } return(v.Get <bool>(key)); }
public void ShouldGetObjectBasedOnType() { var url = new Url("/1"); var identity = new GenericIdentity("name"); var viewData = new ViewDataDictionary(); viewData.Add(identity).Add(url); viewData.Get(typeof(MailMessage)); }
//ViewData extensions public static T Get <T>(this ViewDataDictionary bag) { return(bag.Get <T>(getKey(typeof(T)))); }
public void ShouldManageMoreThanOneObjectPerType() { var viewData = new ViewDataDictionary {{"key1", new Url("/1")}, {"key2", new Url("/2")}}; Assert.That(viewData.Get<Url>("key1").Value, Is.EqualTo("/1")); Assert.That(viewData.Get<Url>("key2").Value, Is.EqualTo("/2")); }
public void ShouldInitializeWithProxiesAndResolveCorrectly() { var messageProxy = MockRepository.GenerateStub<MailMessage>(); var xmlDocumentProxy = MockRepository.GenerateStub<XmlDocument>(); var viewData = new ViewDataDictionary(); viewData.Add(messageProxy).Add(xmlDocumentProxy); Assert.That(viewData.Get<MailMessage>(), Is.EqualTo(messageProxy)); Assert.That(viewData.Get<XmlDocument>(), Is.EqualTo(xmlDocumentProxy)); }
public void ShouldGetMeaningfulExceptionIfObjectDoesntExistByKey() { var viewData = new ViewDataDictionary(); var url = viewData.Get<Url>("foobar"); }
public void Get_should_return_default_value_when_type_does_not_exist() { Assert.Equal(0, viewData.Get <int>()); }
public void ShouldGetMeaningfulExceptionIfObjectDoesntExistByKey() { var viewData = new ViewDataDictionary(); var url = viewData.Get <Url>("foobar"); }
public void ShouldRetrieveSingleObjectByType() { var viewData = new ViewDataDictionary(); var url = new Url("/asdf"); //arbitrary object viewData.Add(url); Assert.That(viewData.Get<Url>(), Is.EqualTo(url)); Assert.That(viewData.Get(typeof(Url)), Is.EqualTo(url)); }
public static T Peek <T>(this ViewDataDictionary storageProvider) { return(storageProvider.Get <T>()); }