Beispiel #1
0
        public void MergeTest()
        {
            var    epoch       = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            string uniqueName  = ((DateTime.UtcNow - epoch).TotalSeconds).ToString();
            string uniqueName2 = uniqueName + "_";

            string failureMessage = string.Empty;

            UnAuthCredentials.Clear();

            using (CognitoSyncManager sm1 = new CognitoSyncManager(AuthCredentials, TestRunner.RegionEndpoint))
            {
                sm1.WipeData(false);
                UtilityMethods.Sleep(TimeSpan.FromMilliseconds(2000));
                using (Dataset d = sm1.OpenOrCreateDataset("test"))
                {
                    d.Put(uniqueName, uniqueName);
                    d.OnSyncSuccess += delegate(object s1, SyncSuccessEventArgs e1)
                    {
                        UnAuthCredentials.Clear();

                        using (CognitoSyncManager sm2 = new CognitoSyncManager(UnAuthCredentials, TestRunner.RegionEndpoint))
                        {
                            UtilityMethods.Sleep(TimeSpan.FromMilliseconds(2000));
                            using (Dataset d2 = sm2.OpenOrCreateDataset("test"))
                            {
                                d2.Put(uniqueName2, uniqueName2);
                                d2.OnSyncSuccess += delegate(object s2, SyncSuccessEventArgs e2)
                                {
                                    AuthCredentials.Clear();
                                    UnAuthCredentials.Clear();
                                    //now we will use auth credentials.
                                    using (CognitoSyncManager sm3 = new CognitoSyncManager(AuthCredentials, TestRunner.RegionEndpoint))
                                    {
                                        UtilityMethods.Sleep(TimeSpan.FromMilliseconds(2000));
                                        using (Dataset d3 = sm3.OpenOrCreateDataset("test"))
                                        {
                                            bool mergeTriggered = false;
                                            d3.OnSyncSuccess += (object sender, SyncSuccessEventArgs e) =>
                                            {
                                                if (!mergeTriggered)
                                                {
                                                    failureMessage += "Expecting DatasetMerged instead of OnSyncSuccess\n";
                                                }
                                            };
                                            d3.OnSyncFailure += (object sender, SyncFailureEventArgs e) =>
                                            {
                                                failureMessage += string.Format("Not expecting OnSyncFailure Got exception {0}\n", e.Exception.Message);
                                            };
                                            d3.OnSyncConflict += (Dataset dataset, List <SyncConflict> syncConflicts) =>
                                            {
                                                failureMessage += "Not expecting OnSyncConflict\n";
                                                return(false);
                                            };
                                            d3.OnDatasetDeleted += (Dataset dataset) =>
                                            {
                                                failureMessage += "Not expecting OnDatasetDeleted\n";
                                                return(false);
                                            };
                                            d3.OnDatasetMerged += (Dataset ds, List <string> datasetNames) =>
                                            {
                                                mergeTriggered = true;
                                                return(true);
                                            };
                                            RunAsSync(async() => await d3.SynchronizeAsync());
                                        }
                                    }
                                };
                                d2.OnSyncFailure += (object sender, SyncFailureEventArgs e) =>
                                {
                                    failureMessage += string.Format("Not expecting OnSyncFailure Got exception {0}\n", e.Exception.Message);
                                };
                                d2.OnSyncConflict += (Dataset dataset, List <SyncConflict> conflicts) =>
                                {
                                    failureMessage += "Not expecting OnSyncConflict\n";
                                    return(false);
                                };
                                d2.OnDatasetDeleted += (Dataset dataset) =>
                                {
                                    failureMessage += "Not expecting OnDatasetDeleted\n";
                                    return(false);
                                };
                                d2.OnDatasetMerged += (Dataset dataset, List <string> datasetNames) =>
                                {
                                    failureMessage += "Not expecting OnDatasetMerged\n";
                                    return(false);
                                };
                                RunAsSync(async() => await d2.SynchronizeAsync());
                            }
                        }
                    };
                    d.OnSyncFailure += delegate(object s, SyncFailureEventArgs e)
                    {
                        failureMessage += string.Format("Not expecting OnSyncFailure Got exception {0}\n", e.Exception.Message);
                    };
                    d.OnSyncConflict += (Dataset dataset, List <SyncConflict> syncConflicts) =>
                    {
                        failureMessage += "Not expecting OnSyncConflict\n";
                        return(false);
                    };
                    d.OnDatasetDeleted += (Dataset dataset) =>
                    {
                        failureMessage += "Not expecting OnDatasetDeleted\n";
                        return(false);
                    };
                    d.OnDatasetMerged += (Dataset dataset, List <string> datasetNames) =>
                    {
                        failureMessage += "Not expecting OnDatasetMerged\n";
                        return(false);
                    };
                    RunAsSync(async() => await d.SynchronizeAsync());
                }
            }
            if (!string.IsNullOrEmpty(failureMessage))
            {
                Assert.Fail(failureMessage);
            }
        }
Beispiel #2
0
        public void DatasetCloudStorageTest()
        {
            string failureMessage = string.Empty;

            using (CognitoSyncManager syncManager = new CognitoSyncManager(UnAuthCredentials, TestRunner.RegionEndpoint))
            {
                syncManager.WipeData(false);
                UtilityMethods.Sleep(TimeSpan.FromMilliseconds(2000));
                using (Dataset d = syncManager.OpenOrCreateDataset("testDataset2"))
                {
                    d.Put("key", "he who must not be named");

                    d.OnSyncSuccess += delegate(object sender, SyncSuccessEventArgs e)
                    {
                        d.ClearAllDelegates();
                        string erasedValue = d.Get("key");
                        syncManager.WipeData(false);
                        d.OnSyncSuccess += delegate(object sender2, SyncSuccessEventArgs e2)
                        {
                            string restoredValues = d.Get("key");
                            if (erasedValue == null)
                            {
                                failureMessage += "erasedValue should not be null\n";
                            }
                            if (restoredValues == null)
                            {
                                failureMessage += "restoredValues should not be null\n";
                            }
                            if (erasedValue != restoredValues)
                            {
                                failureMessage += "erasedValue should equal restoredValues\n";
                            }
                        };
                        d.OnSyncFailure += delegate(object sender2, SyncFailureEventArgs e2)
                        {
                            failureMessage += "sync failed\n";
                        };
                        RunAsSync(async() => await d.SynchronizeAsync());
                    };
                    d.OnSyncFailure += delegate(object sender, SyncFailureEventArgs e)
                    {
                        failureMessage += "sync failed\n";
                    };
                    d.OnSyncConflict += delegate(Dataset dataset, List <SyncConflict> conflicts)
                    {
                        failureMessage += "Expected SyncSuccess instead of SyncConflict\n";
                        return(false);
                    };
                    d.OnDatasetMerged += (Dataset dataset, List <string> datasetNames) =>
                    {
                        failureMessage += "Did not expect DatasetMerged\n";
                        return(false);
                    };
                    d.OnDatasetDeleted += (Dataset dataset) =>
                    {
                        failureMessage += "Did not expect DatasetDeleted\n";
                        return(false);
                    };
                    RunAsSync(async() => await d.SynchronizeAsync());
                }
            }
            if (!string.IsNullOrEmpty(failureMessage))
            {
                Assert.Fail(failureMessage);
            }
        }