Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用查询Twitter API的Windows 8 metro应用程序创建单元测试(由linqtotwitter nuGet编写)_C#_Api_Unit Testing_Twitter_Windows 8 - Fatal编程技术网

C# 如何使用查询Twitter API的Windows 8 metro应用程序创建单元测试(由linqtotwitter nuGet编写)

C# 如何使用查询Twitter API的Windows 8 metro应用程序创建单元测试(由linqtotwitter nuGet编写),c#,api,unit-testing,twitter,windows-8,C#,Api,Unit Testing,Twitter,Windows 8,我正在Windows8中开发一个应用程序,该应用程序通过linqtotwitter nuGet查询Twitter API。 因此,我有一些函数,比如getFollowers(),getfollower(),getScreenName()getUserInformation()。 我所有的函数都在查询Twitter,我不知道如何用这些函数创建单元测试 有人能给我举个例子吗 例如,有一个my getFollowers()函数: public List<string> Recuperer

我正在Windows8中开发一个应用程序,该应用程序通过linqtotwitter nuGet查询Twitter API。 因此,我有一些函数,比如
getFollowers()
getfollower()
getScreenName()
getUserInformation()
。 我所有的函数都在查询Twitter,我不知道如何用这些函数创建单元测试

有人能给我举个例子吗

例如,有一个my getFollowers()函数:

 public List<string> RecupererFollower()
    {
        _log.Info("Fonction récupérer follower");
        _log.Info("On recherche les follower de "+MainPage.texte);
        _log.Info("Cette fonction va créer une liste des id des follower de"+MainPage.texte);

        List<string> idFollowers=new List<string>();
        var followers =
            (from follower in MainPage.twitterCtxProp.SocialGraph
             where follower.Type == SocialGraphType.Followers &&
                   follower.ScreenName == MainPage.texte 
             select follower)
             .ToList();
        idFollowers = followers[0].IDs;

        return idFollowers;

    }
public List RecupererFollower()
{
_log.Info(“Fonction récupérer follower”);
_log.Info(“On recherche les follower de”+MainPage.texte);
_log.Info(“Cette fonction va créer une liste des id des follower de”+MainPage.texte);
List idFollowers=新列表();
变量跟随者=
(来自MainPage.twitterCtxProp.SocialGraph中的关注者)
其中follower.Type==SocialGraphType.Followers&&
follower.ScreenName==MainPage.texte
选择跟随者)
.ToList();
idFollowers=followers[0]。ID;
返回idFollowers;
}
如何使用它创建测试? 什么是模拟对象


谢谢

我想看看您使用的Twitter API是否实现了一个接口(它可能实现了)。如果是这样,那么您应该能够模拟该连接,并测试您的代码是否达到了预期的效果,然后它使用预期的参数调用API方法

本质上是一种断开测试代码与更复杂或运行速度较慢的代码,或连接到另一个系统(如数据库或twitter)的代码的连接的方法

如果您不熟悉模拟框架,请查看这些建议框架的文档:或。就个人而言,我更喜欢Rhino,并且发现它有更好的文档。但是有很多选择

对于上面的示例,您可以使用如下内容“模拟”对twitterapi的调用,然后您的代码将使用您提供的结果,就好像它调用了twitter一样

mockTwitterAPI.Setup(x => x.SocialGraph).Returns(MyCustomDataForThisTest());

由于与.NET4.5Framework不兼容,我无法安装这些nuGet…您可以下载其中任何一个并直接引用二进制文件。在这两种情况下,它只是一个单一的参考。虽然我不确定nuget为什么不让您安装它们——但我在4.5项目中使用它们。