Add support for uint, long types.

This commit is contained in:
Denis-Cosmin Nutiu 2021-04-30 15:55:11 +03:00
parent 13a4e1f219
commit 3edb8bc2d7
4 changed files with 42 additions and 2 deletions

View file

@ -87,6 +87,32 @@ namespace FirebaseRestTranslator.UnitTests
Assert.Equal(expectedJson, actualJson);
}
[Fact]
public void Test_FirebaseTranslator_IntegerValue_Uint()
{
var data = new Dictionary<string, object>()
{
["myKey"] = (uint) 23
};
var expectedJson = "{\"name\":\"Test_FirebaseTranslator\",\"fields\":{\"myKey\":{\"integerValue\":23}}}";
var result = Translator.Translate("Test_FirebaseTranslator", data);
var actualJson = JsonConvert.SerializeObject(result);
Assert.Equal(expectedJson, actualJson);
}
[Fact]
public void Test_FirebaseTranslator_IntegerValue_Long()
{
var data = new Dictionary<string, object>()
{
["myKey"] = (long) 23
};
var expectedJson = "{\"name\":\"Test_FirebaseTranslator\",\"fields\":{\"myKey\":{\"integerValue\":23}}}";
var result = Translator.Translate("Test_FirebaseTranslator", data);
var actualJson = JsonConvert.SerializeObject(result);
Assert.Equal(expectedJson, actualJson);
}
[Fact]
public void Test_FirebaseTranslator_DoubleValue()
{

View file

@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<PackageId>FirebaseRestTranslator</PackageId>
<Version>0.1.1</Version>
<Version>0.1.2</Version>
<Authors>Denis Nutiu</Authors>
<Company>NucuLabs</Company>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>

View file

@ -41,10 +41,18 @@ namespace FirebaseRestTranslator
{
return BuildString(v);
}
case uint v:
{
return BuildInteger(v);
}
case int v:
{
return BuildInteger(v);
}
case long v:
{
return BuildInteger(v);
}
case double v:
{
return BuildDouble(v);
@ -112,7 +120,7 @@ namespace FirebaseRestTranslator
return BuildSimpleValue("stringValue", value);
}
private static Dictionary<string, object> BuildInteger(int value)
private static Dictionary<string, object> BuildInteger(long value)
{
return BuildSimpleValue("integerValue", value);
}

View file

@ -22,3 +22,9 @@ See the tests for usage.
Assert.Equal(expectedJson, actualJson);
}
```
# Changelog
### 0.1.2
- Added support for uint, long types.