目前有没有好的node.js(服务器端js)单元测试框架?我正在寻找比Assert模块更深入的东西.
我想将对象序列化为字符串,然后返回.
我们使用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#中做压缩和解压缩字符串.有一个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) 我试图使用一个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)
思考?
我创建了一个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) 下面的方法是我想在该线程中完成的:
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)
两者都不编译,怎么办?
我试图序列化一些"懒惰创建"各种列表的遗留对象.我无法改变遗留行为.
我把它归结为这个简单的例子:
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) 我最近开始研究新的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) 我想转换像这样的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)
我想得到这个字符串.
c# ×6
javascript ×2
json.net ×2
.net ×1
.net-2.0 ×1
adfs ×1
anonymous ×1
compression ×1
katana ×1
list ×1
negotiate ×1
node.js ×1
ntlm ×1
nuget ×1
owin ×1
powershell ×1
protobuf-net ×1
string ×1
unit-testing ×1
wcf ×1
xml ×1