Fix NRE in atmos helpers and add tests (#1775)
This commit is contained in:
160
Content.IntegrationTests/Tests/Atmos/AtmosHelpersTest.cs
Normal file
160
Content.IntegrationTests/Tests/Atmos/AtmosHelpersTest.cs
Normal file
@@ -0,0 +1,160 @@
|
|||||||
|
using System.Threading.Tasks;
|
||||||
|
using Content.Server.Atmos;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using Robust.Shared.Map;
|
||||||
|
|
||||||
|
namespace Content.IntegrationTests.Tests.Atmos
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
[TestOf(typeof(AtmosHelpersTest))]
|
||||||
|
public class AtmosHelpersTest : ContentIntegrationTest
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public async Task GetTileAtmosphereGridCoordinatesNullTest()
|
||||||
|
{
|
||||||
|
var server = StartServerDummyTicker();
|
||||||
|
|
||||||
|
server.Assert(() =>
|
||||||
|
{
|
||||||
|
Assert.DoesNotThrow(() =>
|
||||||
|
{
|
||||||
|
var atmosphere = default(GridCoordinates).GetTileAtmosphere();
|
||||||
|
|
||||||
|
Assert.Null(atmosphere);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
await server.WaitIdleAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task GetTileAirGridCoordinatesNullTest()
|
||||||
|
{
|
||||||
|
var server = StartServerDummyTicker();
|
||||||
|
|
||||||
|
server.Assert(() =>
|
||||||
|
{
|
||||||
|
Assert.DoesNotThrow(() =>
|
||||||
|
{
|
||||||
|
var air = default(GridCoordinates).GetTileAir();
|
||||||
|
|
||||||
|
Assert.Null(air);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
await server.WaitIdleAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task TryGetTileAtmosphereGridCoordinatesNullTest()
|
||||||
|
{
|
||||||
|
var server = StartServerDummyTicker();
|
||||||
|
|
||||||
|
server.Assert(() =>
|
||||||
|
{
|
||||||
|
Assert.DoesNotThrow(() =>
|
||||||
|
{
|
||||||
|
var hasAtmosphere = default(GridCoordinates).TryGetTileAtmosphere(out var atmosphere);
|
||||||
|
|
||||||
|
Assert.False(hasAtmosphere);
|
||||||
|
Assert.Null(atmosphere);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
await server.WaitIdleAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task TryGetTileTileAirGridCoordinatesNullTest()
|
||||||
|
{
|
||||||
|
var server = StartServerDummyTicker();
|
||||||
|
|
||||||
|
server.Assert(() =>
|
||||||
|
{
|
||||||
|
Assert.DoesNotThrow(() =>
|
||||||
|
{
|
||||||
|
var hasAir = default(GridCoordinates).TryGetTileAir(out var air);
|
||||||
|
|
||||||
|
Assert.False(hasAir);
|
||||||
|
Assert.Null(air);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
await server.WaitIdleAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task GetTileAtmosphereMapIndicesNullTest()
|
||||||
|
{
|
||||||
|
var server = StartServerDummyTicker();
|
||||||
|
|
||||||
|
server.Assert(() =>
|
||||||
|
{
|
||||||
|
Assert.DoesNotThrow(() =>
|
||||||
|
{
|
||||||
|
var atmosphere = default(MapIndices).GetTileAtmosphere(default);
|
||||||
|
|
||||||
|
Assert.Null(atmosphere);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
await server.WaitIdleAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task GetTileAirMapIndicesNullTest()
|
||||||
|
{
|
||||||
|
var server = StartServerDummyTicker();
|
||||||
|
|
||||||
|
server.Assert(() =>
|
||||||
|
{
|
||||||
|
Assert.DoesNotThrow(() =>
|
||||||
|
{
|
||||||
|
var air = default(MapIndices).GetTileAir(default);
|
||||||
|
|
||||||
|
Assert.Null(air);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
await server.WaitIdleAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task TryGetTileAtmosphereMapIndicesNullTest()
|
||||||
|
{
|
||||||
|
var server = StartServerDummyTicker();
|
||||||
|
|
||||||
|
server.Assert(() =>
|
||||||
|
{
|
||||||
|
Assert.DoesNotThrow(() =>
|
||||||
|
{
|
||||||
|
var hasAtmosphere = default(MapIndices).TryGetTileAtmosphere(default, out var atmosphere);
|
||||||
|
|
||||||
|
Assert.False(hasAtmosphere);
|
||||||
|
Assert.Null(atmosphere);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
await server.WaitIdleAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task TryGetTileAirMapIndicesNullTest()
|
||||||
|
{
|
||||||
|
var server = StartServerDummyTicker();
|
||||||
|
|
||||||
|
server.Assert(() =>
|
||||||
|
{
|
||||||
|
Assert.DoesNotThrow(() =>
|
||||||
|
{
|
||||||
|
var hasAir = default(MapIndices).TryGetTileAir(default, out var air);
|
||||||
|
|
||||||
|
Assert.False(hasAir);
|
||||||
|
Assert.Null(air);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
await server.WaitIdleAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,14 +20,16 @@ namespace Content.Server.Atmos
|
|||||||
return coordinates.GetTileAtmosphere()?.Air;
|
return coordinates.GetTileAtmosphere()?.Air;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool TryGetTileAtmosphere(this GridCoordinates coordinates, [NotNullWhen(true)] out TileAtmosphere atmosphere)
|
public static bool TryGetTileAtmosphere(this GridCoordinates coordinates, [MaybeNullWhen(false)] out TileAtmosphere atmosphere)
|
||||||
{
|
{
|
||||||
return (atmosphere = coordinates.GetTileAtmosphere()!) != default;
|
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
|
||||||
|
return !Equals(atmosphere = coordinates.GetTileAtmosphere()!, default);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool TryGetTileAir(this GridCoordinates coordinates, [NotNullWhen(true)] out GasMixture air)
|
public static bool TryGetTileAir(this GridCoordinates coordinates, [MaybeNullWhen(false)] out GasMixture air)
|
||||||
{
|
{
|
||||||
return !(air = coordinates.GetTileAir()!).Equals(default);
|
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
|
||||||
|
return !Equals(air = coordinates.GetTileAir()!, default);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TileAtmosphere? GetTileAtmosphere(this MapIndices indices, GridId gridId)
|
public static TileAtmosphere? GetTileAtmosphere(this MapIndices indices, GridId gridId)
|
||||||
@@ -43,14 +45,16 @@ namespace Content.Server.Atmos
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static bool TryGetTileAtmosphere(this MapIndices indices, GridId gridId,
|
public static bool TryGetTileAtmosphere(this MapIndices indices, GridId gridId,
|
||||||
[NotNullWhen(true)] out TileAtmosphere atmosphere)
|
[MaybeNullWhen(false)] out TileAtmosphere atmosphere)
|
||||||
{
|
{
|
||||||
return (atmosphere = indices.GetTileAtmosphere(gridId)!) != default;
|
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
|
||||||
|
return !Equals(atmosphere = indices.GetTileAtmosphere(gridId)!, default);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool TryGetTileAir(this MapIndices indices, GridId gridId, [NotNullWhen(true)] out GasMixture air)
|
public static bool TryGetTileAir(this MapIndices indices, GridId gridId, [MaybeNullWhen(false)] out GasMixture air)
|
||||||
{
|
{
|
||||||
return !(air = indices.GetTileAir(gridId)!).Equals(default);
|
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
|
||||||
|
return !Equals(air = indices.GetTileAir(gridId)!, default);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user