views:

70

answers:

1
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsistec.Domain;
using Microsistec.Client;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
using Microsistec.Tools;
using System.Json;
using Microsistec.SystemConfig;
using System.Threading;
using Microsoft.Silverlight.Testing;

namespace Test
{

    [TestClass]
    public class SampleTest : SilverlightTest
    {

        [TestMethod, Asynchronous]
        public void login()
        {

            List<PostData> data = new List<PostData>();
            data.Add(new PostData("email", "xxx"));
            data.Add(new PostData("password", MD5.GetHashString("xxx")));
            WebClient.sendData(Config.DataServerURL + "/user/login", data, LoginCallBack);
            EnqueueCallback(?????????);
            EnqueueTestComplete();
        }

        [Asynchronous]
        public void LoginCallBack(object sender, System.Net.UploadStringCompletedEventArgs e)
        {
            string json = Microsistec.Client.WebClient.ProcessResult(e);
            var result = JsonArray.Parse(json);
            Assert.Equals("1", result["value"].ToString());
            TestComplete();
        }
    }

Im tring to set ???????? value but my callback is generic, it is setup on my WebClient .SendData, how i implement my EnqueueCallback to a my already functio LoginCallBack???

A: 

You have to take a different approach to make this work. Why do you want to enqueue LoginCallBack? It would get called asynchronously when sendData has ended, would it not?

Also, I see no point in having a TestComplete() in LoginCallBack and EnqueueTestComplete() in login. Would this not work:

[TestClass]
    public class SampleTest : SilverlightTest
    {

        [TestMethod, Asynchronous]
        public void login()
        {

            List<PostData> data = new List<PostData>();
            data.Add(new PostData("email", "xxx"));
            data.Add(new PostData("password", MD5.GetHashString("xxx")));
            WebClient.sendData(Config.DataServerURL + "/user/login", data, LoginCallBack);
        }

        [Asynchronous]
        public void LoginCallBack(object sender, System.Net.UploadStringCompletedEventArgs e)
        {
            string json = Microsistec.Client.WebClient.ProcessResult(e);
            var result = JsonArray.Parse(json);
            Assert.Equals("1", result["value"].ToString());
            TestComplete();
        }
    }

I'm unsure of how LoginCallback gets called but if you make sure that that happens it should make the test pass!

Gergely Orosz
thank's man , work !!!
CrazyJoe