Ejemplo n.º 1
0
        public void ImportNew ()
        {
            RunAsync (async delegate {
                var workspaceData = await DataStore.PutAsync (new WorkspaceData () {
                    RemoteId = 1,
                    Name = "Test",
                    ModifiedAt = new DateTime (2014, 1, 2),
                });
                var userJson = new UserJson () {
                    Id = 1,
                    Name = "John",
                    DefaultWorkspaceId = 1,
                    ModifiedAt = new DateTime (2014, 1, 4),
                };

                var userData = await DataStore.ExecuteInTransactionAsync (ctx => converter.Import (ctx, userJson));
                Assert.AreNotEqual (Guid.Empty, userData.Id);
                Assert.AreEqual (1, userData.RemoteId);
                Assert.AreEqual ("John", userData.Name);
                Assert.AreEqual (new DateTime (2014, 1, 4), userData.ModifiedAt);
                Assert.IsFalse (userData.IsDirty);
                Assert.IsFalse (userData.RemoteRejected);
                Assert.IsNull (userData.DeletedAt);
            });
        }
Ejemplo n.º 2
0
        public void ImportUpdatedKeepDirtyLocal ()
        {
            RunAsync (async delegate {
                var workspaceData = await DataStore.PutAsync (new WorkspaceData () {
                    RemoteId = 1,
                    Name = "Test",
                    ModifiedAt = new DateTime (2014, 1, 2),
                });
                var userData = await DataStore.PutAsync (new UserData () {
                    RemoteId = 1,
                    Name = "",
                    DefaultWorkspaceId = workspaceData.Id,
                    ModifiedAt = new DateTime (2014, 1, 2, 10, 0, 0, DateTimeKind.Utc),
                    IsDirty = true,
                });
                var userJson = new UserJson () {
                    Id = 1,
                    Name = "John",
                    DefaultWorkspaceId = 1,
                    ModifiedAt = new DateTime (2014, 1, 2, 10, 0, 0, DateTimeKind.Utc).ToLocalTime (),
                };

                userData = await DataStore.ExecuteInTransactionAsync (ctx => converter.Import (ctx, userJson));
                Assert.AreEqual ("", userData.Name);
                Assert.AreEqual (new DateTime (2014, 1, 2, 10, 0, 0, DateTimeKind.Utc), userData.ModifiedAt);
            });
        }
Ejemplo n.º 3
0
        public void ImportPastDeleted ()
        {
            RunAsync (async delegate {
                var userData = await DataStore.PutAsync (new UserData () {
                    RemoteId = 1,
                    Name = "John",
                    ModifiedAt = new DateTime (2014, 1, 4),
                });

                var userJson = new UserJson () {
                    Id = 1,
                    DeletedAt = new DateTime (2014, 1, 2),
                };

                var ret = await DataStore.ExecuteInTransactionAsync (ctx => converter.Import (ctx, userJson));
                Assert.IsNull (ret);

                var rows = await DataStore.Table<UserData> ().Where (m => m.Id == userData.Id).ToListAsync ();
                Assert.That (rows, Has.Exactly (0).Count);
            });
        }
Ejemplo n.º 4
0
        public void ImportUpdated ()
        {
            RunAsync (async delegate {
                var workspaceData = await DataStore.PutAsync (new WorkspaceData () {
                    RemoteId = 1,
                    Name = "Test",
                    ModifiedAt = new DateTime (2014, 1, 2),
                });
                var userData = await DataStore.PutAsync (new UserData () {
                    RemoteId = 1,
                    Name = "",
                    DefaultWorkspaceId = workspaceData.Id,
                    ModifiedAt = new DateTime (2014, 1, 2, 10, 0, 0, DateTimeKind.Utc),
                });
                var userJson = new UserJson () {
                    Id = 1,
                    Name = "John",
                    DefaultWorkspaceId = 1,
                    ModifiedAt = new DateTime (2014, 1, 2, 10, 1, 0, DateTimeKind.Utc).ToLocalTime (), // JSON deserialized to local
                };

                userData = await DataStore.ExecuteInTransactionAsync (ctx => converter.Import (ctx, userJson));
                Assert.AreNotEqual (Guid.Empty, userData.Id);
                Assert.AreEqual (1, userData.RemoteId);
                Assert.AreEqual ("John", userData.Name);
                Assert.AreEqual (new DateTime (2014, 1, 2, 10, 1, 0, DateTimeKind.Utc), userData.ModifiedAt);
                Assert.IsFalse (userData.IsDirty);
                Assert.IsFalse (userData.RemoteRejected);
                Assert.IsNull (userData.DeletedAt);
            });

            // Warn the user that the test result might be invalid
            if (TimeZone.CurrentTimeZone.GetUtcOffset (DateTime.Now).TotalMinutes >= 0) {
                Assert.Inconclusive ("The test machine timezone should be set to GTM-1 or less to test datetime comparison.");
            }
        }