public void PreservesObjectIdentityForRefTypes() { const string s = "whatever"; NeverNull <string> resultOfImplicitOp = s; Assert.That(resultOfImplicitOp.Value, Is.SameAs(s)); }
public void AssignsNullValueCorrectly() { const string input = "hello"; var x = NeverNull.Create(input); Assert.That(x.Value, Is.SameAs(input)); }
public void PreservesObjectIdentityForRefTypes() { const string s = "whatever"; NeverNull <string> neverNull = Create(s); string resultOfImplicitOp = neverNull; Assert.That(resultOfImplicitOp, Is.SameAs(s)); }
public void GuardsForNull() { // This is the case when someone manages to // create NeverNull<T> using default ctor. // The Value prop will throw with some meaningful // message. // The value will be null; var neverNull = new NeverNull <string>(); Assert.Throws <NullReferenceException>(() => { var value = neverNull.Value; }) .Message.Contains("did you call default constructor"); }
public void GuardsForNull_WithArrays() { // This is the case when someone manages to // create NeverNull<T> using arrays. // Same behaviour as if using the default ctor. // Encapsulated values of each array members will be null. var stuff = new NeverNull <string> [3]; var neverNull = stuff[0]; Assert.Throws <NullReferenceException>(() => { var value = neverNull.Value; }) .Message.Contains("did you call default constructor"); }
public void WorksWithReferenceTypes() { var x = NeverNull.Create("hello"); }
public static NeverNull <T> Create <T>(NeverNull <T> other) { return(new NeverNull <T>(other)); }