public void TryGetReturnsThePropertyValueIfNotNull() { const string expectedValue = "Something"; var someObject = new {SomeProperty = expectedValue}; Assert.AreEqual(expectedValue, someObject.TryGet(x => x.SomeProperty), "TryGet should have returned the property value"); }
public bool LoadPostData(string postDataKey, System.Collections.Specialized.NameValueCollection postCollection) { var hasData = postCollection.AllKeys.Any(k => k.Equals(postDataKey, StringComparison.OrdinalIgnoreCase)); if (hasData) { var val = postCollection.TryGet<string>(postDataKey, String.Empty); if (this.Checked != StringToBool(val)) { this.Checked = StringToBool(val); } } return hasData; }
public void TryGetReturnsNullIfSourceIsNull() { // ReSharper disable once RedundantAssignment var someObject = new {SomeProperty = "Something"}; someObject = null; Assert.IsNull(someObject.TryGet(x => x.SomeProperty), "TryGet should have returned null"); }