Skip to content

Commit 1eaa462

Browse files
committed
NH-3900 - Replace ExpectedExceptionAttribute with Assert delegate.
1 parent d4e8f28 commit 1eaa462

File tree

6 files changed

+65
-45
lines changed

6 files changed

+65
-45
lines changed

src/NHibernate.Test.Linq/Linq/ByMethod/DistinctTests.cs

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -98,36 +98,46 @@ public void DistinctOnTypeProjectionWithHqlMethodIsOk()
9898
}
9999

100100
[Test]
101-
[ExpectedException(typeof(NotSupportedException), ExpectedMessage = "Cannot use distinct on result that depends on methods for which no SQL equivalent exist.")]
102101
public void DistinctOnTypeProjectionWithCustomProjectionMethodsIsBlocked1()
103102
{
104103
// Sort of related to NH-2645.
105104

106-
OrderDto[] result = db.Orders
107-
.Select(x => new OrderDto
108-
{
109-
ShippingDate = Transform(x.ShippingDate),
110-
OrderDate = Transform(x.OrderDate)
111-
})
112-
.Distinct()
113-
.ToArray();
105+
Assert.That(
106+
() =>
107+
{
108+
OrderDto[] result = db.Orders
109+
.Select(x => new OrderDto
110+
{
111+
ShippingDate = Transform(x.ShippingDate),
112+
OrderDate = Transform(x.OrderDate)
113+
})
114+
.Distinct()
115+
.ToArray();
116+
},
117+
Throws.TypeOf<NotSupportedException>()
118+
.And.Message.EqualTo("Cannot use distinct on result that depends on methods for which no SQL equivalent exist."));
114119
}
115120

116121

117122
[Test]
118-
[ExpectedException(typeof(NotSupportedException), ExpectedMessage = "Cannot use distinct on result that depends on methods for which no SQL equivalent exist.")]
119123
public void DistinctOnTypeProjectionWithCustomProjectionMethodsIsBlocked2()
120124
{
121125
// Sort of related to NH-2645.
122126

123-
OrderDto[] result = db.Orders
124-
.Select(x => new OrderDto
127+
Assert.That(
128+
() =>
125129
{
126-
ShippingDate = x.ShippingDate,
127-
OrderDate = x.OrderDate.Value.AddMonths(5), // As of 2012-01-25, AddMonths() is executed locally.
128-
})
129-
.Distinct()
130-
.ToArray();
130+
OrderDto[] result = db.Orders
131+
.Select(x => new OrderDto
132+
{
133+
ShippingDate = x.ShippingDate,
134+
OrderDate = x.OrderDate.Value.AddMonths(5), // As of 2012-01-25, AddMonths() is executed locally.
135+
})
136+
.Distinct()
137+
.ToArray();
138+
},
139+
Throws.TypeOf<NotSupportedException>()
140+
.And.Message.EqualTo("Cannot use distinct on result that depends on methods for which no SQL equivalent exist."));
131141
}
132142
}
133143
}

src/NHibernate.Test.Linq/Linq/ByMethod/SumTests.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@ namespace NHibernate.Test.Linq.ByMethod
77
public class SumTests : LinqTestCase
88
{
99
[Test]
10-
[ExpectedException]
1110
public void EmptySumDecimal()
1211
{
13-
db.OrderLines.Where(ol => false).Sum(ol => ol.Discount);
12+
Assert.That(
13+
() =>
14+
{
15+
db.OrderLines.Where(ol => false).Sum(ol => ol.Discount);
16+
}, Throws.InstanceOf<HibernateException>());
1417
}
1518

1619
[Test]
@@ -48,4 +51,4 @@ public void SumSingle()
4851
Assert.Greater(total, 0);
4952
}
5053
}
51-
}
54+
}
Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
1-
using NUnit.Framework;
1+
using System;
2+
using NUnit.Framework;
23

34
namespace NHibernate.Test
45
{
5-
public class KnownBugAttribute : ExpectedExceptionAttribute
6+
public class KnownBugAttribute : IgnoreAttribute
67
{
8+
public string UserMessage { get; set; }
9+
710
public KnownBugAttribute(string bug)
11+
: base("Known bug " + bug)
812
{
913
UserMessage = "Known bug " + bug;
1014
}
1115

12-
public KnownBugAttribute(string bug, System.Type exceptionType)
13-
: base(exceptionType)
16+
public KnownBugAttribute(string bug, System.Type exceptionType)
17+
: base("Known bug " + bug)
1418
{
1519
UserMessage = "Known bug " + bug;
1620
}
1721

1822
public KnownBugAttribute(string bug, string exceptionName)
19-
: base(exceptionName)
23+
: base("Known bug " + bug)
2024
{
2125
UserMessage = "Known bug " + bug;
2226
}
2327
}
24-
}
28+
}

src/NHibernate.Test/NHSpecificTest/NH2065/Fixture.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ protected override void OnTearDown()
4040
}
4141

4242
[Test]
43-
[ExpectedException(
44-
ExpectedException=typeof(HibernateException),
45-
ExpectedMessage="reassociated object has dirty collection: NHibernate.Test.NHSpecificTest.NH2065.Person.Children")]
4643
public void GetGoodErrorForDirtyReassociatedCollection()
4744
{
4845
Person person;
@@ -59,7 +56,11 @@ public void GetGoodErrorForDirtyReassociatedCollection()
5956
using (var s = OpenSession())
6057
using (s.BeginTransaction())
6158
{
62-
s.Lock(person, LockMode.None);
59+
Assert.That(
60+
() =>
61+
{
62+
s.Lock(person, LockMode.None);
63+
}, Throws.TypeOf<HibernateException>().And.Message.EqualTo("reassociated object has dirty collection: NHibernate.Test.NHSpecificTest.NH2065.Person.Children"));
6364
}
6465
}
6566

src/NHibernate.Test/NHSpecificTest/NH2297/Fixture.cs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,9 @@ namespace NHibernate.Test.NHSpecificTest.NH2297
99
[TestFixture]
1010
public class Fixture // Purposefully doesn't inherit from BugTestCase
1111
{
12-
[TestCase(".MappingsNames.hbm.xml",
13-
ExpectedException = typeof (InvalidOperationException),
14-
ExpectedMessage =
15-
"ICompositeUserType NHibernate.Test.NHSpecificTest.NH2297.InvalidNamesCustomCompositeUserType returned a null value for 'PropertyNames'."
16-
)]
17-
[TestCase(".MappingsTypes.hbm.xml",
18-
ExpectedException = typeof (InvalidOperationException),
19-
ExpectedMessage =
20-
"ICompositeUserType NHibernate.Test.NHSpecificTest.NH2297.InvalidTypesCustomCompositeUserType returned a null value for 'PropertyTypes'."
21-
)]
22-
public void InvalidCustomCompositeUserTypeThrowsMeaningfulException(string mappingFile)
12+
[TestCase(".MappingsNames.hbm.xml", "ICompositeUserType NHibernate.Test.NHSpecificTest.NH2297.InvalidNamesCustomCompositeUserType returned a null value for 'PropertyNames'.")]
13+
[TestCase(".MappingsTypes.hbm.xml", "ICompositeUserType NHibernate.Test.NHSpecificTest.NH2297.InvalidTypesCustomCompositeUserType returned a null value for 'PropertyTypes'.")]
14+
public void InvalidCustomCompositeUserTypeThrowsMeaningfulException(string mappingFile, string expectedExceptionMessage)
2315
{
2416
var cfg = new Configuration();
2517

@@ -36,7 +28,12 @@ public void InvalidCustomCompositeUserTypeThrowsMeaningfulException(string mappi
3628
cfg.AddResource(MappingsAssembly + "." + "NHSpecificTest." + bugNumber + mappingFile, assembly);
3729

3830
// build session factory creates the invalid custom type mapper, and throws the exception
39-
cfg.BuildSessionFactory();
31+
Assert.That(
32+
() =>
33+
{
34+
cfg.BuildSessionFactory();
35+
},
36+
Throws.InvalidOperationException.And.Message.EqualTo(expectedExceptionMessage));
4037
}
4138
}
4239
}

src/NHibernate.Test/UtilityTest/TypeNameParserFixture.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,15 @@ public void ParseComplexGenericTypeName()
5959
CheckInput(typeName, expectedTypeName, null);
6060
}
6161

62-
[Test, Ignore("Not a big problem because the next type request will throw the exception"), ExpectedException(typeof(ParserException))]
62+
[Test, Ignore("Not a big problem because the next type request will throw the exception")]
6363
public void ParseUnmatchedBracket()
6464
{
65-
TypeNameParser.Parse("SomeName[");
65+
Assert.That(
66+
() =>
67+
{
68+
TypeNameParser.Parse("SomeName[");
69+
},
70+
Throws.TypeOf<ParserException>());
6671
}
6772

6873
[Test]
@@ -295,4 +300,4 @@ public void ComplexNestedWithGeneric()
295300
CheckInput(typeof(Aa<int>.Bb<int, short, string>.C).FullName, typeof(Aa<int>.Bb<int, short, string>.C).FullName, null);
296301
}
297302
}
298-
}
303+
}

0 commit comments

Comments
 (0)