-
Notifications
You must be signed in to change notification settings - Fork 0
/
MobileServiceTableTest.cs
109 lines (96 loc) · 3.67 KB
/
MobileServiceTableTest.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
108
109
using System;
using NUnit.Framework;
namespace Test.coUnity.WindowsAzure.MobileServices
{
[TestFixture]
public class MobileServiceTableTest : TestBase
{
[Test]
public void CanInsert()
{
var o = new TestType { IntColumn = 17, TextColumn = "some text to be stored"};
Client.GetTable<TestType>().Insert(o);
Assert.AreNotEqual(0, o.Id);
}
[Test]
public void CanInsertAndSelect()
{
var now = DateTime.Now;
var o = new TestType
{
Bool = true,
DateTime = now,
Double = 17.17,
Float = 13.13888999,
IntColumn = 7,
TextColumn = "some text to be stored"
};
var table = Client.GetTable<TestType>();
table.Insert(o);
var target = table.Get(o.Id);
Assert.IsNotNull(target);
Assert.AreEqual(o.Id, target.Id);
Assert.AreEqual(o.Bool, target.Bool);
Assert.That(o.DateTime, Is.EqualTo(target.DateTime).Within(TimeSpan.FromMilliseconds(1))); //datetime is truncated on insert
Assert.That(now, Is.EqualTo(target.DateTime).Within(TimeSpan.FromMilliseconds(1))); //datetime is truncated on insert
Assert.AreEqual(o.Double, target.Double);
Assert.AreEqual(o.Float, target.Float);
Assert.AreEqual(o.IntColumn, target.IntColumn);
Assert.AreEqual(o.TextColumn, target.TextColumn);
}
[Test]
public void CanUpdate()
{
var o = new TestType
{
Bool = true,
DateTime = DateTime.UtcNow,
Double = 17.17,
Float = 13.13888999,
IntColumn = 7,
TextColumn = "some text to be stored"
};
var table = Client.GetTable<TestType>();
table.Insert(o);
o.Bool = false;
o.DateTime = o.DateTime.AddHours(1);
o.Double = o.Double + 17;
o.Float = o.Float + 17;
o.TextColumn = o.TextColumn + o.TextColumn;
o.IntColumn = o.IntColumn + o.IntColumn;
table.Update(o);
var target = table.Get(o.Id);
Assert.IsNotNull(target);
Assert.AreEqual(o.Id, target.Id);
Assert.AreEqual(o.Bool, target.Bool);
Assert.That(o.DateTime, Is.EqualTo(target.DateTime).Within(TimeSpan.FromMilliseconds(1))); //datetime is truncated on insert
Assert.AreEqual(o.Double, target.Double);
Assert.AreEqual(o.Float, target.Float);
Assert.AreEqual(o.IntColumn, target.IntColumn);
Assert.AreEqual(o.TextColumn, target.TextColumn);
}
[Test]
public void CanDelete()
{
var o = new TestType { IntColumn = 17, TextColumn = "some text to be stored" };
var table = Client.GetTable<TestType>();
table.Insert(o);
table.Delete(o);
Assert.IsNull(table.Get(o.Id));
}
[ExpectedException(typeof(ArgumentException))]
[Test]
public void CannotInsertWithSetId()
{
var obj = new TestType { Id = 1000, IntColumn = 17, TextColumn = "some text to be stored" };
Client.GetTable<TestType>().Insert(obj);
}
[Test]
public void CanInsertIdOnly()
{
var obj = new OnlyId();
Client.GetTable<OnlyId>().Insert(obj);
Assert.AreNotEqual(0, obj.Id);
}
}
}