-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for DateTime behaviour, fix typo (#84)
Fixes #63.
- Loading branch information
Showing
3 changed files
with
44 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System; | ||
using System.IO; | ||
using NUnit.Framework; | ||
|
||
namespace ValveKeyValue.Test | ||
{ | ||
class KVDateTimeTestCase | ||
{ | ||
[Test] | ||
public void InvalidCast() | ||
{ | ||
var obj = new KVObject("test", "some value that could be a date"); | ||
Assert.That( | ||
() => obj.Value.ToDateTime(default), | ||
Throws.InstanceOf<InvalidCastException>()); | ||
} | ||
|
||
[Test] | ||
public void DeserializeDateTimeNotSupported() | ||
{ | ||
var obj = new KVObject("test", new[] | ||
{ | ||
new KVObject("Value", "some value that could be a date") | ||
}); | ||
using var ms = new MemoryStream(); | ||
var serializer = KVSerializer.Create(KVSerializationFormat.KeyValues1Text); | ||
|
||
serializer.Serialize(ms, obj); | ||
ms.Seek(0, SeekOrigin.Begin); | ||
|
||
Assert.That( | ||
() => serializer.Deserialize<SerializedType>(ms), | ||
Throws.InstanceOf<NotSupportedException>() | ||
.With.Message.EqualTo("Converting to DateTime is not supported. (key = Value, type = String)")); | ||
} | ||
|
||
class SerializedType | ||
{ | ||
public DateTime Value { get;set; } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters