Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit d962056

Browse files
committed
Add JSV Float tests
1 parent bae3652 commit d962056

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using NUnit.Framework;
2+
using ServiceStack.Text.Tests.Shared;
3+
4+
namespace ServiceStack.Text.Tests.JsvTests
5+
{
6+
public class JsvBasicDataTests
7+
{
8+
[Test]
9+
public void Can_serialize_ModelWithFloatTypes()
10+
{
11+
var dto = new ModelWithFloatTypes
12+
{
13+
Float = 1.1f,
14+
Double = 2.2d,
15+
Decimal = 3.3m
16+
};
17+
18+
var jsv = dto.ToJsv();
19+
Assert.That(jsv,Is.EqualTo("{Float:1.1,Double:2.2,Decimal:3.3}"));
20+
21+
var fromJsv = jsv.FromJsv<ModelWithFloatTypes>();
22+
Assert.That(fromJsv, Is.EqualTo(dto));
23+
24+
dto = new ModelWithFloatTypes
25+
{
26+
Float = 1111111.11f,
27+
Double = 2222222.22d,
28+
Decimal = 33333333.33m
29+
};
30+
31+
jsv = dto.ToJsv();
32+
Assert.That(jsv, Is.EqualTo("{Float:1111111,Double:2222222.22,Decimal:33333333.33}"));
33+
34+
fromJsv = jsv.FromJsv<ModelWithFloatTypes>();
35+
Assert.That(fromJsv, Is.EqualTo(dto));
36+
}
37+
}
38+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
namespace ServiceStack.Text.Tests.Shared
2+
{
3+
public class ModelWithFloatTypes
4+
{
5+
public float Float { get; set; }
6+
public double Double { get; set; }
7+
public decimal Decimal { get; set; }
8+
9+
protected bool Equals(ModelWithFloatTypes other)
10+
{
11+
return Float.Equals(other.Float) && Double.Equals(other.Double) && Decimal == other.Decimal;
12+
}
13+
14+
public override bool Equals(object obj)
15+
{
16+
if (ReferenceEquals(null, obj)) return false;
17+
if (ReferenceEquals(this, obj)) return true;
18+
if (obj.GetType() != this.GetType()) return false;
19+
return Equals((ModelWithFloatTypes) obj);
20+
}
21+
22+
public override int GetHashCode()
23+
{
24+
unchecked
25+
{
26+
var hashCode = Float.GetHashCode();
27+
hashCode = (hashCode * 397) ^ Double.GetHashCode();
28+
hashCode = (hashCode * 397) ^ Decimal.GetHashCode();
29+
return hashCode;
30+
}
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)