Exemple #1
0
        public void GetAllProjectsTest()
        {
            var threadBlocker = new AutoResetEvent(false);
            bool asyncCallbackReceived = false;

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

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

            // 1. Create some gestures and projects
            target.SaveGesture(projectName, gestureName, gestureData, null);

            // 2. Creating inline function as the callback method
            GetAllProjectsCallback callback = (projects, error) =>
            {
                if (error == null)
                {
                    if (projects != null)
                    {
                        if (projects.Count == 1)
                        {
                            if (projects[0].ProjectName == projectName)
                            {
                                if (projects[0].GestureNames.Count == 1)
                                {
                                    if (projects[0].GestureNames[0] == gestureData)
                                    {
                                        Assert.AreSame(projects[0].GestureNames[0], gestureData, "Method failed to return expected values.");

                                    }
                                }
                            }
                        }
                    }
                }

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

            // 3. Test the method; the callback will validate the return values
            target.GetAllProjects(callback);

            threadBlocker.WaitOne();
            Assert.IsTrue(asyncCallbackReceived, "Failed to receive the async callback");
        }
        /// <summary>
        /// Provide the user name & project name to identify the gesture storage unit.
        /// </summary>
        /// <param name="accountName"></param>
        /// <param name="projectName"></param>
        public static void Init(string accountName, string projectName)
        {
            _userName = accountName;
            _projectname = projectName;
            _layoutRoot = new Canvas();
            _touchProvider = new VirtualTouchInputProvider();
            _storage = new StorageManager();
            _storage.Login(accountName);

            _recorder = new TouchInputRecorder();

            GestureFramework.Initialize(_touchProvider, _layoutRoot, Assembly.GetExecutingAssembly());

            _isInitialized = true;
        }
Exemple #3
0
        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");
        }
Exemple #4
0
        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");
        }