mirror of
https://github.com/AlexMacocian/MonoGame.Extended.git
synced 2026-07-15 15:09:29 +00:00
Resolves NullReferenceException When Getting Invalid Key From TiledMapProperties (#903)
* Add test to validate issue * Resolve issue
This commit is contained in:
committed by
GitHub
parent
9614a62292
commit
93473744d7
@@ -7,7 +7,7 @@ namespace MonoGame.Extended.Tiled
|
||||
public bool TryGetValue(string key, out string value)
|
||||
{
|
||||
bool result = TryGetValue(key, out TiledMapPropertyValue tmpVal);
|
||||
value = result ? null : tmpVal.Value;
|
||||
value = result ? tmpVal.Value : null;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
// Copyright (c) Craftwork Games. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
// See LICENSE file in the project root for full license information.
|
||||
|
||||
namespace MonoGame.Extended.Tiled.Tests;
|
||||
|
||||
public class TileMapPropertiesTest
|
||||
{
|
||||
// NullReferenceException in TiledMapProperties
|
||||
// https://github.com/craftworkgames/MonoGame.Extended/issues/901
|
||||
[Fact]
|
||||
public void TryGetValue_InvalidKey_ReturnsFalse()
|
||||
{
|
||||
TiledMapProperties properties = new TiledMapProperties();
|
||||
var result = properties.TryGetValue("invalid", out string value);
|
||||
Assert.False(result);
|
||||
Assert.True(string.IsNullOrEmpty(value));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TryGetValue_ValidKey_ReturnsFalse()
|
||||
{
|
||||
var expected = "value";
|
||||
TiledMapProperties properties = new TiledMapProperties();
|
||||
properties.Add("test", new TiledMapPropertyValue(expected));
|
||||
|
||||
var result = properties.TryGetValue("test", out string actual);
|
||||
|
||||
Assert.True(result);
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user