/
DynamoDBTests.cs
107 lines (94 loc) · 3.81 KB
/
DynamoDBTests.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Amazon.Auth.AccessControlPolicy;
using Amazon.Auth.AccessControlPolicy.ActionIdentifiers;
using Amazon.DynamoDBv2.DocumentModel;
using Amazon.DynamoDBv2.DataModel;
using ThirdParty.Json.LitJson;
namespace AWSSDK_DotNet35.UnitTests
{
[TestClass]
public class DynamoDBEntryTests
{
[TestMethod]
[TestCategory("DynamoDBv2")]
public void TestDynamoDBEqualsOverrides()
{
var ddbeType = typeof(DynamoDBEntry);
var ddbeSubTypes = GetSubTypes(ddbeType);
foreach(var subType in ddbeSubTypes)
{
var equalsMethod = subType.GetMethod("Equals", new Type[] { typeof(object) });
Assert.IsTrue(equalsMethod.DeclaringType == subType, "Testing that type {0} implements Equals", subType.FullName);
}
Console.WriteLine(ddbeSubTypes.Count);
}
[TestMethod]
[TestCategory("DynamoDBv2")]
public void TestContextConfig()
{
// Test in response to GitHub issue
// https://github.com/aws/aws-sdk-net/issues/209
var config = new DynamoDBContextConfig()
{
TableNamePrefix = "Test"
};
Assert.AreEqual("Test", config.TableNamePrefix);
}
private static List<Type> GetSubTypes(Type baseType)
{
var assembly = baseType.Assembly;
var allTypes = assembly.GetTypes();
var subTypes = new List<Type>();
foreach (var type in allTypes)
{
if (baseType.IsAssignableFrom(type) &&
baseType != type)
subTypes.Add(type);
}
return subTypes;
}
[TestMethod]
[TestCategory("DynamoDBv2")]
public void DocumentFromJsonTest()
{
string jsonDocument =
@"{
""Zero"" : 0,
""PInt"" : 2147483647,
""NInt"" : -2147483648,
""UInt"" : 4294967295,
""Long"" : 4294967296,
""PLong"" : 9223372036854775807,
""NLong"" : -9223372036854775808,
""ULong"" : 18446744073709551615,
""Double"" : 0.0,
""PDouble"": 1.7976931348623157E+308,
""NDouble"": -1.7976931348623157E+308
}";
var dynamoDBDocument = Document.FromJson(jsonDocument);
Assert.IsNotNull(dynamoDBDocument);
Assert.AreEqual(0, dynamoDBDocument["Zero"].AsInt());
Assert.AreEqual(2147483647, dynamoDBDocument["PInt"].AsInt());
Assert.AreEqual(-2147483648, dynamoDBDocument["NInt"].AsInt());
Assert.AreEqual(4294967295, dynamoDBDocument["UInt"].AsUInt());
Assert.AreEqual(4294967296, dynamoDBDocument["Long"].AsLong());
Assert.AreEqual(9223372036854775807, dynamoDBDocument["PLong"].AsLong());
Assert.AreEqual(-9223372036854775808, dynamoDBDocument["NLong"].AsLong());
Assert.AreEqual(18446744073709551615, dynamoDBDocument["ULong"].AsULong());
Assert.AreEqual(0.0, dynamoDBDocument["Double"].AsDouble());
Assert.AreEqual(1.7976931348623157E+308, dynamoDBDocument["PDouble"].AsDouble());
Assert.AreEqual(-1.7976931348623157E+308, dynamoDBDocument["NDouble"].AsDouble());
JsonData jsonOriginal = JsonMapper.ToObject(jsonDocument);
JsonData jsonNew = JsonMapper.ToObject(dynamoDBDocument.ToJson());
foreach (string property in jsonOriginal.PropertyNames)
{
Assert.AreEqual(jsonOriginal[property].ToString(), jsonNew[property].ToString());
}
}
}
}