小编Enr*_*lio的帖子

如何将XML读入与其xsd匹配的类/类

所以我有一个XSD和一个以相同格式提供的web服务.

现在我可以继续将xml读入文档,从类中创建我的对象等......但我在想,必须有一些更简单的方法来做到这一点.

我对吗?;)

<ResultSet xsi:schemaLocation="urn:yahoo:maps http://api.local.yahoo.com/MapsService/V1/GeocodeResponse.xsd">
 <Result precision="address">
  <Latitude>47.643727</Latitude>
  <Longitude>-122.130474</Longitude>
  <Address>1 Microsoft Way, #Way1</Address>
  <City>Redmond</City>
  <State>WA</State>
  <Zip>98052-6399</Zip>
  <Country>US</Country>
 </Result>
</ResultSet>
Run Code Online (Sandbox Code Playgroud)

下面是使用xsd.exe自动生成的类(实际上是两个)

类图http://i43.tinypic.com/2rf7j41.png

.net c# xml xsd xsd.exe

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

使用PowerShell中的WinRM连接到远程服务器失败

我试图从我的计算机上运行PowerShell代码到我的计算机上的vm,但我不断收到此错误:

连接到远程服务器失败,并显示以下错误消息:WinRM客户端无法处理该请求.如果身份验证方案与Kerberos不同,或者客户端计算机未加入域,则必须使用HTTPS传输,或者必须将目标计算机添加到TrustedHosts配置设置.使用winrm.cmd配置TrustedHosts.请注意,TrustedHosts列表中的计算机可能未经过身份验证.您可以通过运行以下命令获取有关该信息的更多信息:winrm help config.有关详细信息,请参阅about_Remote_Troubleshooting帮助主题.

我的代码:

  string runasUsername = @"\aaa";
    string runasPassword = "aaa";
    SecureString ssRunasPassword = new SecureString();
    foreach (char x in runasPassword)
        ssRunasPassword.AppendChar(x);
    PSCredential credentials = new PSCredential(runasUsername, ssRunasPassword);

    var connInfo = new WSManConnectionInfo(new Uri("http://10.0.5.35/PowerShell"),
        "http://schemas.microsoft.com/powershell/Microsoft.Exchange",credentials);
    connInfo.AuthenticationMechanism = AuthenticationMechanism.Basic;

    var runspace = RunspaceFactory.CreateRunspace(connInfo);


    var domainName = "domainName.COM";
    var password = "ActiveDirectoryPassword1234";
    var ssPassword = new SecureString();
    foreach (char c in password)
        ssPassword.AppendChar(c);


    var command = new Command("New-Mailbox");

    command.Parameters.Add("FirstName", firstName);
    command.Parameters.Add("LastName", lastName);
    command.Parameters.Add("Password", ssPassword);
    command.Parameters.Add("ResetPasswordOnNextLogon", false);
    command.Parameters.Add("OrganizationalUnit", "NeumontStudents");

    runspace.Open(); <--//error …
Run Code Online (Sandbox Code Playgroud)

c# powershell winrm

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

使用AutoFixture创建递归树

我刚刚开始使用AutoFixture并拥有这个半复杂的数据结构,我想创建一些标本.在我正在使用的测试中,我不太关心数据结构的内容.我只想要合理的默认值.

此数据结构的一部分是递归树.更具体地说,一个类包含一些其他类的集合,其中包含自身的子列表.类似于:

public class A
{
   private IEnumerable<B> bNodes;
   public A(IEnumerable<B> bNodes)
   {
      this.bNodes = bNodes;
   }
}

public class B
{
   private IEnumerable<B> children;
   public B(IEnumerable<B> children)
   {
      this.children = children;
   }
}
Run Code Online (Sandbox Code Playgroud)

让我们假设我出于各种原因无法轻易改变这种结构.

如果我要求我的灯具创建一个ThrowingRecursionBehavior将开始咆哮B是递归的.

如果我用OmitOnRecursionBehavior替换ThrowingRecursionBehavior,我会得到一个ObjectCreateException.

如果我尝试类似:fixture.Inject(Enumerable.Empty()); 我从DictionaryFiller中得到"已添加相同键的项目".如果我用NullRecursionBehavior替换ThrowingRecursionBehavior,也会发生同样的事情.

我想要几件事.

  • 用空的B列表创建A样本的最佳方法是什么?
  • 什么是最好的方法来创建一个A标本与一些Bs包含几个带有几个孩子的B孩子(一棵小树)?

对于我的遗愿,指定一些递归深度可能会很好,在此之后使用Enumerable.Empty(或零大小的数组/ List或甚至为null).我知道AutoFixture可以非常灵活地扩展.因此,我认为应该可以创建一些完全符合这一要求的样本构建器.事实上,我会尝试使用自定义的ISpecimenBuilder,但也许有人已经有了一个更智能的解决方案.例如,在RecursionGuard中修改此行是否有意义:

public object Create(object request, ISpecimenContext context)
{
   if (this.monitoredRequests.Any(x => this.comparer.Equals(x, request)))
   ...
Run Code Online (Sandbox Code Playgroud)

public object Create(object request, ISpecimenContext context)
{
   if (this.monitoredRequests.Count(x => this.comparer.Equals(x, request)) > maxAllowedRecursions)
   ...
Run Code Online (Sandbox Code Playgroud)

c# unit-testing autofixture

13
推荐指数
1
解决办法
3364
查看次数

Grep Git分支名称,仅返回名称包含"主题"的分支

如果我有一个48个远程分支列表的回购,我可以做

git branch -a
Run Code Online (Sandbox Code Playgroud)

要列出所有这些,我如何grep通过那些只返回其名称包含的Theme

git grep git-branch

13
推荐指数
3
解决办法
7544
查看次数

GitHub上的审稿人和受让人之间有什么区别?

当我创建pull请求时,我可以看到两个选项作为ReviewersAssignees.那些有什么区别?我认为这是来自任何最新版本的github.

github pull-request

13
推荐指数
1
解决办法
4184
查看次数

请求WCF服务合同时出现HTTP错误请求错误

我有一个WCF服务,具有以下配置:

<system.serviceModel>
    <behaviors>
        <serviceBehaviors>
            <behavior name="MetadataEnabled">
                <serviceDebug includeExceptionDetailInFaults="true" />
                <serviceMetadata httpGetEnabled="true" />
            </behavior>
        </serviceBehaviors>
     </behaviors>
      <services>
          <service behaviorConfiguration="MetadataEnabled" name="MyNamespace.MyService">
              <endpoint name="BasicHttp"
                        address=""
                        binding="basicHttpBinding"
                        contract="MyNamespace.IMyServiceContract" />
              <endpoint name="MetadataHttp"
                        address="contract"
                        binding="mexHttpBinding" 
                        contract="IMetadataExchange" />
              <host>
                  <baseAddresses>
                      <add baseAddress="http://localhost/myservice" />
                  </baseAddresses>
              </host>
          </service>
    </services>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)

WcfSvcHost.exe进程中托管服务时,如果我浏览到URL:

HTTP://本地主机/为MyService /合同

服务元数据可用的地方我收到HTTP 400 Bad Request错误.

通过检查WCF日志,我发现抛出了System.Xml.XmlException异常,并显示消息:" 无法读取消息正文,因为它是空的. "
以下是日志文件的摘录:

<Exception>
<ExceptionType>
System.ServiceModel.ProtocolException, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
</ExceptionType>
<Message>There is a problem with the XML that was received from the network. See …
Run Code Online (Sandbox Code Playgroud)

wcf wsdl exception http

12
推荐指数
2
解决办法
8万
查看次数

App.config替换单元测试

我的持续集成服务器(TeamCity)配置为在构建中运行我们的应用程序中的所有单元测试.在运行这些测试之前,我需要更改一些appSettings以使它们对我们的CI服务器有效.通过使用随Visual Studio提供的部署项目,我正在为我的Web项目实现类似的功能.我可以为测试项目做同样的事吗?

谢谢,贡萨洛

c# msbuild visual-studio webdeploy slowcheetah

12
推荐指数
3
解决办法
6340
查看次数

Autofixture和Moq v4

我使用Nuget安装了Autofixture和Moq.So我有moq版本4.

运行以下代码时

var fixture = new Fixture().Customize(new AutoMoqCustomization());
fixture.CreateAnonymous<ISomething>();
Run Code Online (Sandbox Code Playgroud)

出现以下错误

System.IO.FileLoadException:无法加载文件或程序集'Moq,Version = 3.1.416.3,Culture = neutral,PublicKeyToken = 69f491c39445e920'

我也尝试将它重定向到v4,但没有运气.

<configuration>
  <runtime>
    <assemblyBinding>
    <dependentAssembly>
      <assemblyIdentity name="Moq" publicKeyToken="69f491c39445e920" culture="neutral"/>
      <bindingRedirect oldVersion="3.1.416.3" newVersion="4.0.10827.0"/>
    </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>
Run Code Online (Sandbox Code Playgroud)

这可能是什么问题?

.net unit-testing moq autofixture

12
推荐指数
1
解决办法
2367
查看次数

将DRY应用于自动混合"构建"语句

假设我有这个具体的类:

public partial class User
{
    public int ID { get; set; }
    public string Email { get; set; }
    public string FullName { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我想创建一个具有有效电子邮件地址的匿名实例,并且fullname字段不超过20个字符.我可以做这个:

var fixture = new Fixture();
var anonUser = fixture.Build<User>()
    .With(x => x.Email, string.Format("{0}@fobar.com", fixture.Create<string>()))
    .With(x => x.FullName,  fixture.Create<string>()Substring(0,20))
    .Create();
Run Code Online (Sandbox Code Playgroud)

有没有办法可以在一个地方定义它,所以AF知道我可以通过使用以下方式获得我的自定义anon类:

var newAnon = fixture.Build<User>();
Run Code Online (Sandbox Code Playgroud)

c# autofixture

12
推荐指数
1
解决办法
1427
查看次数

从所有值的子集创建匿名枚举值

假设我们将枚举类型定义为:

enum Statuses
{
    Completed,
    Pending,
    NotStarted,
    Started
}
Run Code Online (Sandbox Code Playgroud)

我想让Autofixture为我创造一个价值,而不是像Pending.

所以(假设循环生成)我想获得:

已完成,未启动,已启动,已完成,未启动,...

c# autofixture

11
推荐指数
1
解决办法
3155
查看次数