public void properties() { Assert.Throws <ArgumentNullException>(() => ObjectExtensions.Properties <object>(null, new Dictionary <string, object>())); Assert.Throws <ArgumentNullException>(() => new object().Properties((IDictionary <string, object>)null)); Assert.Throws <ArgumentNullException>(() => ObjectExtensions.Properties <object>(null, (object)null)); Assert.Throws <ArgumentNullException>(() => new object().Properties((object)null)); var subject = new TestObject(); var property = Guid.NewGuid().ToString(); Assert.Throws <ArgumentException>(() => subject.Properties(new Dictionary <string, object> { { "ReadOnlyProperty", property } })); Assert.True(ReferenceEquals(subject.Properties(new Dictionary <string, object> { { "PublicProperty", property }, { "property", new object() } }), subject)); Assert.Equal(property, subject.Property("PublicProperty")); Assert.Throws <ArgumentException>(() => subject.Properties(new { ReadOnlyProperty = property })); Assert.True(ReferenceEquals(subject.Properties(new { PublicProperty = property, property = new object() }), subject)); Assert.Equal(property, subject.Property("PublicProperty")); }
public void property() { Assert.Throws <ArgumentNullException>(() => ObjectExtensions.Property(null, "property")); Assert.Throws <ArgumentNullException>(() => new object().Property(null)); Assert.Throws <ArgumentException>(() => new object().Property(string.Empty)); Assert.Null(new object().Property("property")); var subject = new TestObject { PublicProperty = "value" }; Assert.Equal("value", subject.Property("PublicProperty").To <string>()); Assert.Throws <ArgumentNullException>(() => ObjectExtensions.Property <object>(null, "property", new object())); Assert.Throws <ArgumentNullException>(() => new object().Property(null, new object())); Assert.Throws <ArgumentException>(() => new object().Property(string.Empty, new object())); subject = new TestObject(); var property = Guid.NewGuid().ToString(); Assert.True(ReferenceEquals(subject.Property("PublicProperty", null), subject)); Assert.Throws <ArgumentException>(() => subject.Property("ReadOnlyProperty", property)); subject.Property("PublicStaticProperty", property); Assert.Equal(property, subject.Property("PublicStaticProperty")); subject.Property("ProtectedStaticProperty", property); Assert.Equal(property, subject.Property("ProtectedStaticProperty")); subject.Property("PrivateStaticProperty", property); Assert.Equal(property, subject.Property("PrivateStaticProperty")); subject.Property("PublicProperty", property); Assert.Equal(property, subject.Property("PublicProperty")); subject.Property("ProtectedProperty", property); Assert.Equal(property, subject.Property("ProtectedProperty")); subject.Property("PrivateProperty", property); Assert.Equal(property, subject.Property("PrivateProperty")); }
public void properties() { Assert.Throws<ArgumentNullException>(() => ObjectExtensions.Properties<object>(null, new Dictionary<string, object>())); Assert.Throws<ArgumentNullException>(() => new object().Properties((IDictionary<string, object>)null)); Assert.Throws<ArgumentNullException>(() => ObjectExtensions.Properties<object>(null, (object)null)); Assert.Throws<ArgumentNullException>(() => new object().Properties((object)null)); var subject = new TestObject(); var property = Guid.NewGuid().ToString(); Assert.Throws<ArgumentException>(() => subject.Properties(new Dictionary<string, object>{ { "ReadOnlyProperty", property } })); Assert.True(ReferenceEquals(subject.Properties(new Dictionary<string, object> { { "PublicProperty", property }, { "property", new object() } }), subject)); Assert.Equal(property, subject.Property("PublicProperty")); Assert.Throws<ArgumentException>(() => subject.Properties(new { ReadOnlyProperty = property })); Assert.True(ReferenceEquals(subject.Properties(new { PublicProperty = property, property = new object() }), subject)); Assert.Equal(property, subject.Property("PublicProperty")); }
public void property() { Assert.Throws<ArgumentNullException>(() => ObjectExtensions.Property(null, "property")); Assert.Throws<ArgumentNullException>(() => new object().Property(null)); Assert.Throws<ArgumentException>(() => new object().Property(string.Empty)); Assert.Null(new object().Property("property")); var subject = new TestObject { PublicProperty = "value" }; Assert.Equal("value", subject.Property("PublicProperty").To<string>()); Assert.Throws<ArgumentNullException>(() => ObjectExtensions.Property<object>(null, "property", new object())); Assert.Throws<ArgumentNullException>(() => new object().Property(null, new object())); Assert.Throws<ArgumentException>(() => new object().Property(string.Empty, new object())); subject = new TestObject(); var property = Guid.NewGuid().ToString(); Assert.True(ReferenceEquals(subject.Property("PublicProperty", null), subject)); Assert.Throws<ArgumentException>(() => subject.Property("ReadOnlyProperty", property)); subject.Property("PublicStaticProperty", property); Assert.Equal(property, subject.Property("PublicStaticProperty")); subject.Property("ProtectedStaticProperty", property); Assert.Equal(property, subject.Property("ProtectedStaticProperty")); subject.Property("PrivateStaticProperty", property); Assert.Equal(property, subject.Property("PrivateStaticProperty")); subject.Property("PublicProperty", property); Assert.Equal(property, subject.Property("PublicProperty")); subject.Property("ProtectedProperty", property); Assert.Equal(property, subject.Property("ProtectedProperty")); subject.Property("PrivateProperty", property); Assert.Equal(property, subject.Property("PrivateProperty")); }