小编shy*_*kov的帖子

Node.js单元测试

目前有没有好的node.js(服务器端js)单元测试框架?我正在寻找比Assert模块更深入的东西.

javascript unit-testing node.js

163
推荐指数
5
解决办法
9万
查看次数

将Stream转换为String并返回...我们缺少什么?

我想将对象序列化为字符串,然后返回.

我们使用protobuf-net将对象转换为Stream并成功返回.

但是,Stream to string and back ...不太成功.经过StreamToString并且StringToStream,新Stream的没有被protobuf-net反序列化; 它提出了一个Arithmetic Operation resulted in an Overflow例外.如果我们反序列化原始流,它可以工作.

我们的方法:

public static string StreamToString(Stream stream)
{
    stream.Position = 0;
    using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
    {
        return reader.ReadToEnd();
    }
}

public static Stream StringToStream(string src)
{
    byte[] byteArray = Encoding.UTF8.GetBytes(src);
    return new MemoryStream(byteArray);
}
Run Code Online (Sandbox Code Playgroud)

我们的示例代码使用这两个:

MemoryStream stream = new MemoryStream();
Serializer.Serialize<SuperExample>(stream, test);
stream.Position = 0;
string strout = StreamToString(stream);
MemoryStream result = (MemoryStream)StringToStream(strout);
var other = …
Run Code Online (Sandbox Code Playgroud)

.net c# serialization protobuf-net deserialization

152
推荐指数
6
解决办法
32万
查看次数

使用C#压缩/解压缩字符串

我是.net的新手.我在C#中做压缩和解压缩字符串.有一个XML,我正在转换为字符串,之后我正在进行压缩和解压缩.我的代码中没有编译错误,除非我解压缩我的代码并返回我的字符串,它只返回XML的一半.

以下是我的代码,请在我错的地方纠正我.

码:

class Program
{
    public static string Zip(string value)
    {
        //Transform string into byte[]  
        byte[] byteArray = new byte[value.Length];
        int indexBA = 0;
        foreach (char item in value.ToCharArray())
        {
            byteArray[indexBA++] = (byte)item;
        }

        //Prepare for compress
        System.IO.MemoryStream ms = new System.IO.MemoryStream();
        System.IO.Compression.GZipStream sw = new System.IO.Compression.GZipStream(ms, System.IO.Compression.CompressionMode.Compress);

        //Compress
        sw.Write(byteArray, 0, byteArray.Length);
        //Close, DO NOT FLUSH cause bytes will go missing...
        sw.Close();

        //Transform byte[] zip data to string
        byteArray = ms.ToArray();
        System.Text.StringBuilder sB = new System.Text.StringBuilder(byteArray.Length);
        foreach (byte item …
Run Code Online (Sandbox Code Playgroud)

c# compression string .net-2.0

133
推荐指数
7
解决办法
18万
查看次数

使用Json.net反序列化JSON对象数组

我试图使用一个API,使用以下示例结构为他们返回的json

[
   {
      "customer":{
         "first_name":"Test",
         "last_name":"Account",
         "email":"test1@example.com",
         "organization":"",
         "reference":null,
         "id":3545134,
         "created_at":"2013-08-06T15:51:15-04:00",
         "updated_at":"2013-08-06T15:51:15-04:00",
         "address":"",
         "address_2":"",
         "city":"",
         "state":"",
         "zip":"",
         "country":"",
         "phone":""
      }
   },
   {
      "customer":{
         "first_name":"Test",
         "last_name":"Account2",
         "email":"test2@example.com",
         "organization":"",
         "reference":null,
         "id":3570462,
         "created_at":"2013-08-12T11:54:58-04:00",
         "updated_at":"2013-08-12T11:54:58-04:00",
         "address":"",
         "address_2":"",
         "city":"",
         "state":"",
         "zip":"",
         "country":"",
         "phone":""
      }
   }
]
Run Code Online (Sandbox Code Playgroud)

JSON.net可以使用类似以下结构的东西

{
    "customer": {
        ["field1" : "value", etc...],
        ["field1" : "value", etc...],
    }
}
Run Code Online (Sandbox Code Playgroud)

但我无法弄清楚如何让它对提供的结构感到满意.

使用默认的JsonConvert.DeserializeObject(content)会生成正确的Customer数,但所有数据都为null.

在CustomerList(下面)执行某些操作会导致"无法反序列化当前JSON数组"异常

public class CustomerList
{
    public List<Customer> customer { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

思考?

c# json.net

110
推荐指数
2
解决办法
19万
查看次数

WCFTestClient HTTP请求未经授权,客户端身份验证方案为"匿名"

我创建了一个WCF服务并将其部署在Server上.当我浏览这个服务时,它使用?wsdl URL给出了积极的回应.现在我正试图通过WCF测试客户端测试服务.它显示正确的元数据.但是当我尝试从服务中调用任何方法时,它会向我显示异常...这里是堆栈跟踪的错误细节.

HTTP请求未经授权,客户端身份验证方案为"匿名".从服务器收到的身份验证标头是"Negotiate,NTLM".

服务器堆栈跟踪:


System.ServiceModel.Channels.HttpChannelUtilities.ValidateAuthentication(HttpWebRequest请求,HttpWebResponse响应,WebException responseException,HttpChannelFactory factory)
HTTP请求未经授权使用客户端身份验证方案"Anonymous".从服务器收到的身份验证标头是"Negotiate,NTLM".

服务器堆栈跟踪:


System.ServiceModel.Channels.HttpChannelUtilities.ValidateAuthentication(HttpWebRequest请求,HttpWebResponse响应,WebException responseException,HttpChannelFactory工厂)

客户端绑定:

<bindings>
    <wsHttpBinding>
        <binding name="WSHttpBinding_IServiceMagicService" closeTimeout="00:01:00"
            openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
            bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
            maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
            messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
            allowCookies="false">
            <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                maxBytesPerRead="4096" maxNameTableCharCount="16384" />
            <reliableSession ordered="true" inactivityTimeout="00:10:00"
                enabled="false" />
            <security mode="None">
                <transport clientCredentialType="Windows" proxyCredentialType="None"
                    realm="" />
                <message clientCredentialType="Windows" negotiateServiceCredential="true"
                    establishSecurityContext="true" />
            </security>
        </binding>
    </wsHttpBinding>
</bindings>
Run Code Online (Sandbox Code Playgroud)

服务器绑定:

<bindings>
  <wsHttpBinding>
    <binding name="WSHttpBinding_SEOService" closeTimeout="00:10:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" bypassProxyOnLocal="true" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="999524288" maxReceivedMessageSize="655360000" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
      <readerQuotas maxDepth="32" maxStringContentLength="900000" …
Run Code Online (Sandbox Code Playgroud)

wcf ntlm anonymous wcftestclient negotiate

63
推荐指数
5
解决办法
24万
查看次数

如何创建一个线程?

下面的方法是我想在该线程中完成的:

public void Startup(int port,string path)
{
    Run(path);
    CRCCheck2();
    CRCCheck1();
    InitializeCodeCave((ushort)port);
}
Run Code Online (Sandbox Code Playgroud)

我试着用谷歌搜索,但没有任何效果

public void Test(int port,string path)
{
    Thread t = new Thread(Startup(port,path));
}

public void TestA(int port,string path)
{
    Thread t = new Thread(Startup);
    t.Start (port,path);
}
Run Code Online (Sandbox Code Playgroud)

两者都不编译,怎么办?

c# multithreading

54
推荐指数
4
解决办法
10万
查看次数

Newtonsoft Json.NET可以跳过序列化空列表吗?

我试图序列化一些"懒惰创建"各种列表的遗留对象.我无法改变遗留行为.

我把它归结为这个简单的例子:

public class Junk
{
    protected int _id;

    [JsonProperty( PropertyName = "Identity" )]
    public int ID 
    { 
        get
        {
            return _id;
        }

        set
        {
            _id = value;
        }
    }

    protected List<int> _numbers;
    public List<int> Numbers
    {
        get
        {
            if( null == _numbers )
            {
                _numbers = new List<int>( );
            }

            return _numbers;
        }

        set
        {
            _numbers = value;
        }
    }
}

class Program
{
    static void Main( string[] args )
    {
        Junk j = new Junk( ) { ID …
Run Code Online (Sandbox Code Playgroud)

c# serialization list json.net

54
推荐指数
3
解决办法
3万
查看次数

从Visual Studio外部使用NuGet powershell命令行开关

我试图在Visual Studio 2010中使用Package Manager控制台中我最喜欢的源代码控件.我遇到了另一个主题中描述的问题.现在最好的答案是将所有命令行内容从Visual Studio移到裸机Powershell.

但是这种情况下Visual Studio相关的命令行开关不起作用.例如,最关键的一个 - 我无法Update-Database从Entity Framework 运行命令.

是否可以在Powershell中以某种方式为当前项目注册Visual Studio特定的命令行开关?或者让Powershell自动从packages子文件夹中获取当前项目上下文?

powershell visual-studio-2010 nuget

36
推荐指数
3
解决办法
3万
查看次数

OWIN认证管道,以及如何正确使用Katana中间件?

我最近开始研究新的ASP.Net Identity框架和Katana中间件,那里有大量的代码和文档,但我看到的是很多相互矛盾的信息,我想这是一个代码更新频率增加的结果.

我期待使用WsFederation认证与内部ADFS分2次服,但方式OWIN认证管道工程有我有点困惑,我希望有人能提供一些确切的信息.

具体来说,我感兴趣的是应该连接中间件的顺序以及在各种场景中需要哪些模块,我想摆脱任何不需要的东西,同时确保过程尽可能安全.

例如,它似乎UseWsFederationAuthentication应该与之结合使用UseCookieAuthentication,但我不确定正确的AuthenticationType是什么(这篇帖子暗示它只是一个标识符字符串,但它的值是否显着?)或者即使我们仍然需要用SetDefaultSignInAsAuthenticationType.

我还注意到Katana项目讨论板上的这个帖子,Tratcher在那里提到了一个常见的错误,但是对于哪部分代码出错是不是很具体.

就个人而言,我现在使用以下(使用自定义SAML令牌处理程序将令牌字符串读入有效的XML文档),它对我有用,但它是否最佳?

var appURI = ConfigurationManager.AppSettings["app:URI"];
var fedPassiveTokenEndpoint = ConfigurationManager.AppSettings["wsFederation:PassiveTokenEndpoint"];
var fedIssuerURI = ConfigurationManager.AppSettings["wsFederation:IssuerURI"];
var fedCertificateThumbprint = ConfigurationManager.AppSettings["wsFederation:CertificateThumbprint"];

var audienceRestriction = new AudienceRestriction(AudienceUriMode.Always);

audienceRestriction.AllowedAudienceUris.Add(new Uri(appURI));

var issuerRegistry = new ConfigurationBasedIssuerNameRegistry();

issuerRegistry.AddTrustedIssuer(fedCertificateThumbprint, fedIssuerURI);

app.UseCookieAuthentication(
    new CookieAuthenticationOptions
    {
        AuthenticationType = WsFederationAuthenticationDefaults.AuthenticationType // "Federation"
    }
);

app.UseWsFederationAuthentication(
    new WsFederationAuthenticationOptions
    {
        Wtrealm = appURI,
        SignOutWreply = appURI,
        Configuration = new WsFederationConfiguration
        {
            TokenEndpoint = fedPassiveTokenEndpoint …
Run Code Online (Sandbox Code Playgroud)

c# adfs ws-federation owin katana

34
推荐指数
1
解决办法
2万
查看次数

将XML转换为String并附加到页面

我想转换像这样的xml元素:

<asin>?B0013FRNKG?</asin>?
Run Code Online (Sandbox Code Playgroud)

在javascript中输入字符串

我用过XMLSerializer:

new XMLSerializer().serializeToString(xml);
Run Code Online (Sandbox Code Playgroud)

字符串仅显示在alert()和控制台中.在页面上它只是说

[object Element][object Element]
Run Code Online (Sandbox Code Playgroud)

我想得到这个字符串.

javascript xml xml-serialization

29
推荐指数
2
解决办法
9万
查看次数