小编Sti*_*ahl的帖子

在NUnit中将参数传递给TestDelegate

我正在尝试创建一个方法,该方法接受testdelegate或delegate并将参数传递给委托对象.这是因为我正在为控制器中的方法创建测试,这些方法都采用相同的参数(id),并且我不想为所有控制器方法创建测试.

我有以下代码:

protected void AssertThrows_NullReference_Og_InvalidOperation(TestDelegate delegateMethod)
{

    Assert.Throws<NullReferenceException>(delegateMethod);
    Assert.Throws<InvalidOperationException>(delegateMethod);
    Assert.Throws<InvalidOperationException>(delegateMethod);
} 
Run Code Online (Sandbox Code Playgroud)

我想做什么:

protected void AssertThrows_NullReference_Og_InvalidOperation(TestDelegate delegateMethod)
{

    Assert.Throws<NullReferenceException>(delegateMethod(null));
    Assert.Throws<InvalidOperationException>(delegateMethod(string.Empty));
    Assert.Throws<InvalidOperationException>(delegateMethod(" "));
} 
Run Code Online (Sandbox Code Playgroud)

编辑:我忘了提到控制器有一个返回值.因此不能使用Action.

c# delegates nunit unit-testing

8
推荐指数
1
解决办法
8346
查看次数

如何使ng-transclude表现得像ng-include(在范围方面)?

我想要转发内容,好像我将内容复制粘贴到我写的文件中<div data-ng-transclude="">.我该怎么做呢?

我知道我可以使用ng-include包含模板,我可以使用脚本标签来定义模板.但这会使模板缓存变得混乱并污染模板命名空间.

我想这样做,以便我可以有一个(或更多!这就是整点)文件,我在其中定义我想要显示我的项目的方式,

<!-- list directive to show the items -->
<div data-item-list="" data-values="vm.items">

    <!-- content to include to display list items -->
    <div class="form-relation-picker-value" ng-bind="item.value.title"></div>
    <div class="form-relation-picker-subtitle" ng-bind="item.value.subTitle"></div>
</div>
Run Code Online (Sandbox Code Playgroud)

和一个文件,我在其中定义列表结构的工作方式.

<div class="list-container">
    <div class="list-item"
         data-ng-click="vm.select(item)"
         data-ng-repeat="item in vm.items | orderBy : vm.orderBy"
         data-selected="{{vm.isSelected(item)}}">

        <div class="flex">
            <div ng-transclude=""></div><!-- item display via transclude -->
            <div class="grid-col flex-icon form-relation-picker-chrome-height-fix">
                <div data-ng-show="vm.isSelected(item)" class="icon check"></div>
            </div>
        </div>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

如果我做这样的事情,这是有效的:

<div data-item-list="" data-values="vm.items" data-template-to-use="randomhash">
    <script type="text/ng-template" id="randomhash">
        <div class="form-relation-picker-value" …
Run Code Online (Sandbox Code Playgroud)

javascript angularjs angularjs-ng-transclude

6
推荐指数
1
解决办法
521
查看次数

$ http帖子没有与asp.net MVC模型绑定

为什么来自angularjs $ http帖子的有效负载没有绑定到输入模型?

调用该操作时,模型为null,request.params和request.forms不显示发送表单的任何迹象.但是小提琴请求表明有效载荷是用JSON发送的.

AngularJS:

$http({
            method: "POST",
            url: "price/add",
            data: {
                Id: $scope.id,
                StoreId: $scope.storeid,
                Name: $scope.name,
                Manufacturer: $scope.manufacturer,
                Price: $scope.price
            }
        })
Run Code Online (Sandbox Code Playgroud)

模型:

public class PriceModel
    {
        public int? Id { get; set; }
        public int? StoreId { get; set; }
        public string Barcode { get; set; }
        public string Name { get; set; }
        public string Manufacturer { get; set; }
        public DateTime Created { get; set; }
        public double? Price { get; set; }
    }
Run Code Online (Sandbox Code Playgroud)

控制器和动作方法描述 …

asp.net-mvc asp.net-mvc-4 angularjs

5
推荐指数
1
解决办法
8283
查看次数

包含c#中列表的动态类型

我有一点问题.

我想这样做:

Type[] classes = new Type[]{ Class1, Class2 };

foreach(Type t in classes){   
  List<t> list = new List<t>(); 
}
Run Code Online (Sandbox Code Playgroud)

有办法做到这一点吗?

c# types dynamic

4
推荐指数
2
解决办法
4536
查看次数

为什么我得到一个 OpenXmlUnknownElement?

这不是一个真正的问题,因为我已经找到了这个问题的原因从 OpenXml 正文中检索后代

使用此代码检索后代。

using System.IO;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
namespace Testolini
{
    class Program
    {
        static void Main(string[] args)
        {
            var filename = Path.GetTempFileName();
            var word = WordprocessingDocument.Create(filename, DocumentFormat.OpenXml.WordprocessingDocumentType.Document);
            word.AddMainDocumentPart();
            word.MainDocumentPart.Document = new Document(
                                                new Body(
                                                    new Paragraph(
                                                        new Run(
                                                            new Paragraph(
                                                                new Run(
                                                                    new Text("test1"))),
                                                            new Paragraph(
                                                                new Run(
                                                                    new Text("test2"))),
                                                            new Paragraph(
                                                                new Run(
                                                                    new Text("test3")))))));
            word.Close();

            using (var memorystream = new MemoryStream(File.ReadAllBytes(filename)))
            {
                var word2 = WordprocessingDocument.Open(memorystream, true);

                var descendants = word2.MainDocumentPart.Document.Body.Descendants();

                word.Close();

            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

如果你遇到同样的问题。这可能是因为 …

c# bytearray openxml

4
推荐指数
1
解决办法
1386
查看次数

以编程方式从XML Schema生成测试XML

我现在搜索了一下,但是我无法找到一种以编程方式从XML Schema自动生成数据的方法.假设我有这个XML架构:

<xs:element xmlns:xs="http://www.w3.org/2001/XMLSchema" name ="Persons">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="Person">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="FirstName" type="xs:string" />
            <xs:element name="LastName" type="xs:string" />
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:sequence>
  </xs:complexType>
</xs:element> 
Run Code Online (Sandbox Code Playgroud)

我可以使用VS函数"生成示例XML"从此创建XML 在此输入图像描述
有没有办法以编程方式执行此操作?

编辑:指定.我不想自己创建所有对象并以编程方式插入数据.我想让它自动创建对象和属性,就像VS中的"生成示例XML"一样.这样做的原因是我想更改XSD而不必对xml样本生成做任何事情.

c# xml xsd sample visual-studio

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

使用XSLT根据XSD转换XML

我想创建一个可以转换XML的XSLT,以便在输出XML(来自XSLT)中排除XSD中未定义的所有元素和属性.

让我们说你有这个XSD.

<xs:element name="parent">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="keptElement1" />
            <xs:element name="keptElement2" />
        </xs:sequence>

        <xs:attribute name="keptAttribute1" />
        <xs:attribute name="keptAttribute2" />
    </complexType>
</xsd:element>
Run Code Online (Sandbox Code Playgroud)

你有这个输入XML

<parent keptAttribute1="kept" 
    keptAttribute2="kept" 
    notKeptAttribute3="not kept" 
    notKeptAttribute4="not kept">

    <notKeptElement0>not kept</notKeptElement0>
    <keptElement1>kept</keptElement1>
    <keptElement2>kept</keptElement2>
    <notKeptElement3>not kept</notKeptElement3>
</parent>
Run Code Online (Sandbox Code Playgroud)

然后我想让输出Xml看起来像这样.

<parent keptAttribute1="kept" 
    keptAttribute2="kept">

    <keptElement1>kept</keptElement1>
    <keptElement2>kept</keptElement2>
</parent>
Run Code Online (Sandbox Code Playgroud)

我可以通过指定元素来做到这一点,但这就是我的xslt技能所达到的目标.对于所有元素和所有属性,我一般都有问题.

xml xslt xsd

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

内存地址是否总是指一个字节,而不是一位?

  1. 你能确认PC中的内存地址总是指向一个字节(8位)吗?
  2. 如果浮点数在内存中需要 32 位,计算机是否会分配 4 个连续字节(总共 32 位)来表示该数字?

memory cpu-architecture

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

如何在 Azure Blob 流中启用搜索

我有一个通过 OpenWriter 方法创建的 BlobStream。

var blob = CloudContainer.GetBlobReference(name));
if (blob == null)
{
   return null;
}

return blob.OpenWrite();
Run Code Online (Sandbox Code Playgroud)

使用此流,我想寻找或设置位置,但每次执行此操作时,我都会收到 NotSupportedException。经过一些研究后,我发现 canSeek 设置为 false,这导致了这个问题。但是,仅当长度未知时,CanSeek 才为 false。但是当我运行调试器时长度是已知的。

为什么 CanSeek 是假的?我怎样才能将其设置为true?

c# streamwriter azure seek azure-blob-storage

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