public void GetDefaultValueObject_ShouldKeepValues_WithoutDefaultAttributes() { SimpleObject2 testObject = null; var exception = Record.Exception(() => testObject = new SimpleObject2()); exception.Should().BeNull(); testObject.Should().NotBeNull(); testObject.Name.Should().Be("Simple"); testObject.Count.Should().Be(5); }
public void TryReadQueryAsSucceeds() { object value; UriBuilder address = new UriBuilder("http://some.host"); address.Query = "a=2"; Assert.True( address.Uri.TryReadQueryAs(typeof(SimpleObject1), out value), "Expected 'true' reading valid data" ); SimpleObject1 so1 = (SimpleObject1)value; Assert.NotNull(so1); Assert.Equal(2, so1.a); address.Query = "b=true"; Assert.True( address.Uri.TryReadQueryAs(typeof(SimpleObject2), out value), "Expected 'true' reading valid data" ); SimpleObject2 so2 = (SimpleObject2)value; Assert.NotNull(so2); Assert.True(so2.b, "Value should have been true"); address.Query = "c=hello"; Assert.True( address.Uri.TryReadQueryAs(typeof(SimpleObject3), out value), "Expected 'true' reading valid data" ); SimpleObject3 so3 = (SimpleObject3)value; Assert.NotNull(so3); Assert.Equal("hello", so3.c); address.Query = "c="; Assert.True( address.Uri.TryReadQueryAs(typeof(SimpleObject3), out value), "Expected 'true' reading valid data" ); so3 = (SimpleObject3)value; Assert.NotNull(so3); Assert.Equal("", so3.c); address.Query = "c=null"; Assert.True( address.Uri.TryReadQueryAs(typeof(SimpleObject3), out value), "Expected 'true' reading valid data" ); so3 = (SimpleObject3)value; Assert.NotNull(so3); Assert.Equal("null", so3.c); }