-
-
Notifications
You must be signed in to change notification settings - Fork 260
/
Copy pathConversionTests.cs
47 lines (40 loc) · 1.37 KB
/
ConversionTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Parse.Infrastructure.Utilities;
namespace Parse.Tests
{
[TestClass]
public class ConversionTests
{
struct DummyValueTypeA { }
struct DummyValueTypeB { }
[TestMethod]
public void TestToWithConstructedNullablePrimitive()
{
// Test conversion of double to nullable int
var result = Conversion.To<int?>((double) 4);
Assert.IsInstanceOfType(result, typeof(int?));
Assert.AreEqual(4, result);
}
[TestMethod]
public void TestToWithConstructedNullableNonPrimitive()
{
// Test invalid conversion between two nullable value types
Assert.ThrowsException<InvalidCastException>(() =>
{
Conversion.To<DummyValueTypeA?>(new DummyValueTypeB());
});
}
[TestMethod]
public void TestConvertToFloatUsingNonInvariantNumberFormat()
{
// Arrange
float inputValue = 1234.56f;
// Act
string jsonEncoded = JsonUtilities.Encode(inputValue);
float convertedValue = (float)Conversion.ConvertTo<float>(jsonEncoded);
// Assert
Assert.AreEqual(inputValue, convertedValue, "Converted value does not match the input value.");
}
}
}