refactor: use NUnit idiomatic constraints

Why?
Suppose you have this:
```cs
Assert.That(manager.networkAddress == "localhost");
```
and suppose it fails,   it will give you:
"Expected True,  but got False"
which does not give you anything useful.

Suppose you have this instead:
```cs
Assert.That(manager.networkAddress, Is.EqualTo("localhost"));
```
Suppose it fails,  now it will give you a much more useful error message:
"Expected 'localhost'  but got 'xxxxx'"

It makes debugging tests a lot easier.
This commit is contained in:
Paul Pacheco 2020-03-03 15:35:13 -06:00
parent fb9c55bf6e
commit 108c83a43a

View File

@ -25,35 +25,35 @@ public void TearDownNetworkManager()
[Test]
public void VariableTest()
{
Assert.That(manager.dontDestroyOnLoad == true);
Assert.That(manager.runInBackground == true);
Assert.That(manager.startOnHeadless == true);
Assert.That(manager.showDebugMessages == false);
Assert.That(manager.serverTickRate == 30);
Assert.That(manager.offlineScene == "");
Assert.That(manager.networkAddress == "localhost");
Assert.That(manager.maxConnections == 4);
Assert.That(manager.autoCreatePlayer == true);
Assert.That(manager.spawnPrefabs.Count == 0);
Assert.That(manager.numPlayers == 0);
Assert.That(manager.isNetworkActive == false);
Assert.That(manager.dontDestroyOnLoad, Is.True);
Assert.That(manager.runInBackground, Is.True);
Assert.That(manager.startOnHeadless, Is.True);
Assert.That(manager.showDebugMessages, Is.False);
Assert.That(manager.serverTickRate, Is.EqualTo(30));
Assert.That(manager.offlineScene, Is.Empty);
Assert.That(manager.networkAddress, Is.EqualTo("localhost"));
Assert.That(manager.maxConnections, Is.EqualTo(4));
Assert.That(manager.autoCreatePlayer, Is.True);
Assert.That(manager.spawnPrefabs, Is.Empty);
Assert.That(manager.numPlayers, Is.Zero);
Assert.That(manager.isNetworkActive, Is.False);
Assert.That(NetworkManager.networkSceneName == "");
Assert.That(NetworkManager.startPositionIndex == 0);
Assert.That(NetworkManager.startPositions.Count == 0);
Assert.That(NetworkManager.isHeadless == false);
Assert.That(NetworkManager.networkSceneName, Is.Empty);
Assert.That(NetworkManager.startPositionIndex, Is.Zero);
Assert.That(NetworkManager.startPositions, Is.Empty);
Assert.That(NetworkManager.isHeadless, Is.False);
}
[Test]
public void StartServerTest()
{
Assert.That(NetworkServer.active == false);
Assert.That(NetworkServer.active , Is.False);
manager.StartServer();
Assert.That(manager.isNetworkActive == true);
Assert.That(manager.isNetworkActive , Is.True);
Assert.That(manager.mode == NetworkManagerMode.ServerOnly);
Assert.That(NetworkServer.active == true);
Assert.That(NetworkServer.active , Is.True);
}
[Test]
@ -62,7 +62,7 @@ public void StopServerTest()
manager.StartServer();
manager.StopServer();
Assert.That(manager.isNetworkActive == false);
Assert.That(manager.isNetworkActive , Is.False);
Assert.That(manager.mode == NetworkManagerMode.Offline);
}
@ -71,7 +71,7 @@ public void StartClientTest()
{
manager.StartClient();
Assert.That(manager.isNetworkActive == true);
Assert.That(manager.isNetworkActive , Is.True);
Assert.That(manager.mode == NetworkManagerMode.ClientOnly);
manager.StopClient();
@ -83,7 +83,7 @@ public void StopClientTest()
manager.StartClient();
manager.StopClient();
Assert.That(manager.isNetworkActive == false);
Assert.That(manager.isNetworkActive , Is.False);
Assert.That(manager.mode == NetworkManagerMode.Offline);
}
@ -93,20 +93,20 @@ public void ShutdownTest()
manager.StartClient();
NetworkManager.Shutdown();
Assert.That(NetworkManager.startPositions.Count == 0);
Assert.That(NetworkManager.startPositionIndex == 0);
Assert.That(NetworkManager.startPositionIndex == 0);
Assert.That(NetworkManager.singleton == null);
Assert.That(NetworkManager.startPositions.Count , Is.Zero);
Assert.That(NetworkManager.startPositionIndex , Is.Zero);
Assert.That(NetworkManager.startPositionIndex , Is.Zero);
Assert.That(NetworkManager.singleton , Is.Null);
}
[Test]
public void RegisterStartPositionTest()
{
Assert.That(NetworkManager.startPositions.Count == 0);
Assert.That(NetworkManager.startPositions.Count , Is.Zero);
NetworkManager.RegisterStartPosition(gameObject.transform);
Assert.That(NetworkManager.startPositions.Count == 1);
Assert.That(NetworkManager.startPositions.Contains(gameObject.transform));
Assert.That(NetworkManager.startPositions.Count , Is.EqualTo(1));
Assert.That(NetworkManager.startPositions, Has.Member(gameObject.transform));
NetworkManager.UnRegisterStartPosition(gameObject.transform);
}
@ -114,26 +114,26 @@ public void RegisterStartPositionTest()
[Test]
public void UnRegisterStartPositionTest()
{
Assert.That(NetworkManager.startPositions.Count == 0);
Assert.That(NetworkManager.startPositions.Count , Is.Zero);
NetworkManager.RegisterStartPosition(gameObject.transform);
Assert.That(NetworkManager.startPositions.Count == 1);
Assert.That(NetworkManager.startPositions.Contains(gameObject.transform));
Assert.That(NetworkManager.startPositions.Count , Is.EqualTo(1));
Assert.That(NetworkManager.startPositions, Has.Member(gameObject.transform));
NetworkManager.UnRegisterStartPosition(gameObject.transform);
Assert.That(NetworkManager.startPositions.Count == 0);
Assert.That(NetworkManager.startPositions.Count , Is.Zero);
}
[Test]
public void GetStartPositionTest()
{
Assert.That(NetworkManager.startPositions.Count == 0);
Assert.That(NetworkManager.startPositions.Count , Is.Zero);
NetworkManager.RegisterStartPosition(gameObject.transform);
Assert.That(NetworkManager.startPositions.Count == 1);
Assert.That(NetworkManager.startPositions.Contains(gameObject.transform));
Assert.That(NetworkManager.startPositions.Count , Is.EqualTo(1));
Assert.That(NetworkManager.startPositions, Has.Member(gameObject.transform));
Assert.That(manager.GetStartPosition() == gameObject.transform);
Assert.That(manager.GetStartPosition(), Is.SameAs(gameObject.transform));
NetworkManager.UnRegisterStartPosition(gameObject.transform);
}