Skip to content

Commit

Permalink
Merge pull request #28 from nowsprinting/chore/refactor_tests
Browse files Browse the repository at this point in the history
Refactor tests
  • Loading branch information
nowsprinting committed Oct 28, 2023
2 parents 103dcb9 + 0b51995 commit a866d80
Showing 1 changed file with 16 additions and 34 deletions.
50 changes: 16 additions & 34 deletions Tests/Runtime/Constraints/DestroyedConstraintTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@
// This software is released under the MIT License.

using System;
using System.Diagnostics.CodeAnalysis;
using NUnit.Framework;
using UnityEngine;
using Object = UnityEngine.Object;

namespace TestHelper.Constraints
{
[SuppressMessage("ReSharper", "AccessToStaticMemberViaDerivedType")]
public class DestroyedConstraintTest
{
private static GameObject CreateDestroyedObject()
{
var gameObject = new GameObject();
Object.DestroyImmediate(gameObject);
GameObject.DestroyImmediate(gameObject);
return gameObject;
}

Expand All @@ -30,67 +31,48 @@ public void IsDestroyed_NotDestroyedGameObject_Failure()
{
var actual = new GameObject("Foo");

try
Assert.That(() =>
{
Assert.That(actual, Is.Destroyed);
Assert.Fail();
}
catch (AssertionException e)
{
Assert.That(e.Message, Is.EqualTo(
$" Expected: destroyed GameObject{Environment.NewLine} But was: <Foo (UnityEngine.GameObject)>{Environment.NewLine}"));
}
}, Throws.TypeOf<AssertionException>().With.Message.EqualTo(
$" Expected: destroyed GameObject{Environment.NewLine} But was: <Foo (UnityEngine.GameObject)>{Environment.NewLine}"));
}

[Test]
public void IsDestroyed_Null_Failure()
{
GameObject actual = null;

try
Assert.That(() =>
{
// ReSharper disable once ExpressionIsAlwaysNull
Assert.That(actual, Is.Destroyed);
Assert.Fail();
}
catch (AssertionException e)
{
Assert.That(e.Message, Is.EqualTo(
$" Expected: destroyed GameObject{Environment.NewLine} But was: null{Environment.NewLine}"));
}
}, Throws.TypeOf<AssertionException>().With.Message.EqualTo(
$" Expected: destroyed GameObject{Environment.NewLine} But was: null{Environment.NewLine}"));
}

[Test]
public void IsDestroyed_NotGameObject_Failure()
{
var actual = string.Empty;

try
Assert.That(() =>
{
Assert.That(actual, Is.Destroyed);
Assert.Fail();
}
catch (AssertionException e)
{
Assert.That(e.Message, Is.EqualTo(
$" Expected: destroyed GameObject{Environment.NewLine} But was: <string.Empty>{Environment.NewLine}"));
}
}, Throws.TypeOf<AssertionException>().With.Message.EqualTo(
$" Expected: destroyed GameObject{Environment.NewLine} But was: <string.Empty>{Environment.NewLine}"));
}

[Test]
public void IsNotDestroyed_DestroyedGameObject_Failure()
{
var actual = CreateDestroyedObject();

try
Assert.That(() =>
{
Assert.That(actual, Is.Not.Destroyed()); // Note: Use it in method style when with operators
Assert.Fail();
}
catch (AssertionException e)
{
Assert.That(e.Message, Is.EqualTo(
$" Expected: not destroyed GameObject{Environment.NewLine} But was: <null>{Environment.NewLine}"));
}
}, Throws.TypeOf<AssertionException>().With.Message.EqualTo(
$" Expected: not destroyed GameObject{Environment.NewLine} But was: <null>{Environment.NewLine}"));
}

[Test]
Expand Down

0 comments on commit a866d80

Please sign in to comment.