コード例 #1
0
ファイル: StorageManagerTest.cs プロジェクト: tuliosouza/ASG
        public void SaveGestureTest()
        {
            var threadBlocker = new AutoResetEvent(false);
            bool asyncCallbackReceived = false;

            // Data set
            string userName = GetUniqueGestureName(),
                gestureName = GetUniqueGestureName(),
                projectName = GetUniqueProjectName(),
                gestureData = "GestureData-" + Guid.NewGuid();

            StorageManager target = new StorageManager();
            target.Login(userName);

            // 1. Save a new gesture
            target.SaveGesture(projectName, gestureName, gestureData, (gestureReturnName, errorOnSave) =>
            {
                if (errorOnSave == null)
                {
                    // 2. Retrive data from storage to match
                    target.GetGesture(projectName, gestureReturnName, (projName, gesName, gesData, errorOnGet) =>
                    {
                        if (errorOnGet == null)
                        {
                            Assert.AreSame(gestureData, gesData, "Failed to save gesture data");
                        }
                        else
                        {
                            Assert.Fail(errorOnGet.Message);
                        }
                    });
                }
                else
                {
                    Assert.Fail(errorOnSave.Message);
                }

                asyncCallbackReceived = true;
                threadBlocker.Set();
            });

            threadBlocker.WaitOne();
            Assert.IsTrue(asyncCallbackReceived, "Failed to receive callback from the async method");
        }
コード例 #2
0
ファイル: StorageManagerTest.cs プロジェクト: tuliosouza/ASG
        public void GetGestureTest()
        {
            bool callbackReceived = false;
            var threadBlocker = new AutoResetEvent(false);

            // Data set
            string userName = GetUniqueGestureName(),
                gestureName = GetUniqueGestureName(),
                projectName = GetUniqueProjectName(),
                gestureData = "GestureData-" + Guid.NewGuid();

            StorageManager target = new StorageManager();
            target.Login(userName);

            // 1. Save the test data in storage
            target.SaveGesture(projectName, gestureName, gestureData, (gestureReturnName, errorOnSave) =>
            {
                if (errorOnSave == null)
                {
                    // 2. Get the data from storage and validate
                    target.GetGesture(projectName, gestureReturnName, (projName, gesName, gesData, errorOnGet) =>
                    {
                        if (errorOnGet == null)
                        {
                            // 4. Check the validation result
                            Assert.AreSame(projectName, projName, "Project name doesn't match with the expected value");
                            Assert.AreSame(gestureName, gesName, "Gesture name doesn't match with the expected value");
                            Assert.AreSame(gestureData, gesData, "Gesture data doesn't match with the expected value");
                        }
                        else
                        {
                            Assert.Fail(errorOnGet.Message);
                        }
                    });
                }
                else
                {
                    Assert.Fail(errorOnSave.Message);
                }

                callbackReceived = true;
                threadBlocker.Set();
            });

            threadBlocker.WaitOne();
            Assert.IsTrue(callbackReceived, "Failed to receive the callback from async method");
        }