Use Assert.Throws instead of ExpectedException

Summary:
Unity 5.6 doesn't have ExpectedException attribute.
Closes https://github.com/facebook/yoga/pull/486

Reviewed By: astreet

Differential Revision: D4739149

Pulled By: splhack

fbshipit-source-id: 9cc486a094c6e159b46fa7938669fecbf523c666
This commit is contained in:
Kazuki Sakamoto
2017-03-27 07:57:45 -07:00
committed by Facebook Github Bot
parent b283572453
commit d342fb1879

View File

@@ -73,25 +73,22 @@ namespace Facebook.Yoga
} }
[Test] [Test]
[ExpectedException("System.NullReferenceException")]
public void TestRemoveAtFromEmpty() public void TestRemoveAtFromEmpty()
{ {
YogaNode parent = new YogaNode(); YogaNode parent = new YogaNode();
parent.RemoveAt(0); Assert.Throws<NullReferenceException>(() => parent.RemoveAt(0));
} }
[Test] [Test]
[ExpectedException("System.ArgumentOutOfRangeException")]
public void TestRemoveAtOutOfRange() public void TestRemoveAtOutOfRange()
{ {
YogaNode parent = new YogaNode(); YogaNode parent = new YogaNode();
YogaNode child = new YogaNode(); YogaNode child = new YogaNode();
parent.Insert(0, child); parent.Insert(0, child);
parent.RemoveAt(1); Assert.Throws<ArgumentOutOfRangeException>(() => parent.RemoveAt(1));
} }
[Test] [Test]
[ExpectedException("System.InvalidOperationException")]
public void TestCannotAddChildToMultipleParents() public void TestCannotAddChildToMultipleParents()
{ {
YogaNode parent1 = new YogaNode(); YogaNode parent1 = new YogaNode();
@@ -99,7 +96,7 @@ namespace Facebook.Yoga
YogaNode child = new YogaNode(); YogaNode child = new YogaNode();
parent1.Insert(0, child); parent1.Insert(0, child);
parent2.Insert(0, child); Assert.Throws<InvalidOperationException>(() => parent2.Insert(0, child));
} }
[Test] [Test]
@@ -113,23 +110,21 @@ namespace Facebook.Yoga
} }
[Test] [Test]
[ExpectedException("System.InvalidOperationException")]
public void TestResetParent() public void TestResetParent()
{ {
YogaNode parent = new YogaNode(); YogaNode parent = new YogaNode();
YogaNode child = new YogaNode(); YogaNode child = new YogaNode();
parent.Insert(0, child); parent.Insert(0, child);
parent.Reset(); Assert.Throws<InvalidOperationException>(() => parent.Reset());
} }
[Test] [Test]
[ExpectedException("System.InvalidOperationException")]
public void TestResetChild() public void TestResetChild()
{ {
YogaNode parent = new YogaNode(); YogaNode parent = new YogaNode();
YogaNode child = new YogaNode(); YogaNode child = new YogaNode();
parent.Insert(0, child); parent.Insert(0, child);
child.Reset(); Assert.Throws<InvalidOperationException>(() => child.Reset());
} }
[Test] [Test]
@@ -174,7 +169,6 @@ namespace Facebook.Yoga
} }
[Test] [Test]
[ExpectedException("System.InvalidOperationException")]
public void TestChildWithMeasureFunc() public void TestChildWithMeasureFunc()
{ {
YogaNode node = new YogaNode(); YogaNode node = new YogaNode();
@@ -182,19 +176,20 @@ namespace Facebook.Yoga
return MeasureOutput.Make(100, 150); return MeasureOutput.Make(100, 150);
}); });
YogaNode child = new YogaNode(); YogaNode child = new YogaNode();
node.Insert(0, child); Assert.Throws<InvalidOperationException>(() => node.Insert(0, child));
} }
[Test] [Test]
[ExpectedException("System.InvalidOperationException")]
public void TestMeasureFuncWithChild() public void TestMeasureFuncWithChild()
{ {
YogaNode node = new YogaNode(); YogaNode node = new YogaNode();
YogaNode child = new YogaNode(); YogaNode child = new YogaNode();
node.Insert(0, child); node.Insert(0, child);
node.SetMeasureFunction((_, width, widthMode, height, heightMode) => { Assert.Throws<InvalidOperationException>(() =>
return MeasureOutput.Make(100, 150); node.SetMeasureFunction((_, width, widthMode, height, heightMode) => {
}); return MeasureOutput.Make(100, 150);
})
);
} }
[Test] [Test]