Skip to content

Commit adca869

Browse files
committed
Merge pull request #430 from hazzik/NH-2887
NH-2887 - Allow to use relative URIs with UriType
2 parents d645313 + 8059ea1 commit adca869

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/NHibernate.Test/TypesTest/UriTypeFixture.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,36 @@ public void ReadWrite()
4040
}
4141
}
4242

43+
44+
[Test(Description = "NH-2887")]
45+
public void ReadWriteRelativeUri()
46+
{
47+
using (var s = OpenSession())
48+
{
49+
var entity = new UriClass { Id = 1 };
50+
entity.Url = new Uri("/", UriKind.Relative);
51+
s.Save(entity);
52+
s.Flush();
53+
}
54+
55+
using (var s = OpenSession())
56+
{
57+
var entity = s.Get<UriClass>(1);
58+
Assert.That(entity.Url, Is.Not.Null);
59+
Assert.That(entity.Url.OriginalString, Is.EqualTo("/"));
60+
entity.Url = new Uri("/2010/10/nhibernate-30-cookbook.html", UriKind.Relative);
61+
s.Save(entity);
62+
s.Flush();
63+
}
64+
using (var s = OpenSession())
65+
{
66+
var entity = s.Get<UriClass>(1);
67+
Assert.That(entity.Url.OriginalString, Is.EqualTo("/2010/10/nhibernate-30-cookbook.html"));
68+
s.Delete(entity);
69+
s.Flush();
70+
}
71+
}
72+
4373
[Test]
4474
public void InsertNullValue()
4575
{

src/NHibernate/Type/UriType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public override System.Type ReturnedClass
2828

2929
public object StringToObject(string xml)
3030
{
31-
return new Uri(xml);
31+
return new Uri(xml, UriKind.RelativeOrAbsolute);
3232
}
3333

3434
public override void Set(IDbCommand cmd, object value, int index)

0 commit comments

Comments
 (0)