Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/256.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/359.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#中编写内存流的单元测试?_C#_Xunit - Fatal编程技术网

如何在c#中编写内存流的单元测试?

如何在c#中编写内存流的单元测试?,c#,xunit,C#,Xunit,嗨,我正在用c#编写单元测试。我正在编写使用openXML下载excel文件的单元测试。下面是我的单元测试 [Fact] public void ShouldAddErrorColumnAtTheEnd() { var stream = new MemoryStream(); var expectedHeaders = new[] { "Keycode", "Store",

嗨,我正在用c#编写单元测试。我正在编写使用openXML下载excel文件的单元测试。下面是我的单元测试

 [Fact]
      public void ShouldAddErrorColumnAtTheEnd()
      {
        var stream = new MemoryStream();
        var expectedHeaders = new[]
        {
          "Keycode",
          "Store",
          "Date On Range",
          "Date Off Range",
          "LSPL",
          "Active",
          "Ranged",
          "Errors",
        };
        var expectedRows = new[]
        {
          new string[] { "DEF", "1001",  "01/01/2100", "02/02/2100", "-1", "Y", "Y", "Oh no! Bad Lspl" }
        };

        var parameterUploadRepository = mockProvider.GetDependency<IParameterUploadRepository>();
        parameterUploadRepository.GetById(uploadId)
          .Returns(new ParameterUpload()
          {
            Type = Constants.ParameterUploadType.KeycodeParameterUpload,
            ID = uploadId,
          });

        var keycodeParameterChangesWithErrors = new List<KeycodeParameterChange>()
        {
          new KeycodeParameterChange()
          {
            UploadId = uploadId,
            Keycode = "DEF",
            Store = "1001",
            OnRange = "01/01/2100",
            OffRange = "02/02/2100",
            Lspl = "-1",
            Active = "Y",
            Ranged = "Y",
            Errors = "Oh no! Bad Lspl",
          }
        };
        parameterUploadRepository.GetKeycodeParameterChangesWithErrors(uploadId)
          .Returns(keycodeParameterChangesWithErrors);

        IEnumerable<string> actualHeaders = null;
        IEnumerable<IEnumerable<string>> actualRows = null;
        var excelService = mockProvider.GetDependency<IExcelWriterService>();
        excelService.WriteExcelUsingOpenXML(
            Arg.Do<IEnumerable<string>>(headers => actualHeaders = headers),
            Arg.Do<IEnumerable<IEnumerable<string>>>(rows => actualRows = rows),
            Constants.KeycodeParameterUpload.SheetName)
          .Returns(???);

        subject.GetUploadSyncErrors(uploadId);

        actualHeaders.ShouldBe(expectedHeaders);
        actualRows.ShouldBe(expectedRows);
      }
我不知道我该回去买什么

excelService.CreateExcelPackage(
            Arg.Do<IEnumerable<string>>(headers => actualHeaders = headers),
            Arg.Do<IEnumerable<IEnumerable<string>>>(rows => actualRows = rows),
            Constants.KeycodeParameterUpload.SheetName)
          .Returns(????);
excelService.CreateExcelPackage(
Arg.Do(headers=>actualHeaders=headers),
Arg.Do(行=>实际行=行),
Constants.KeycodeParameterUpload.SheetName)
.返回(??);

有人能帮我完成这个吗?任何帮助都将不胜感激。谢谢

您可以测试内存流的长度。如果失败,它将<1。如果需要,您还可以从内存流重新组装工作表。

您可以测试内存流的长度。如果失败,它将<1。如果需要,您还可以从内存流重新组装工作表

excelService.CreateExcelPackage(
            Arg.Do<IEnumerable<string>>(headers => actualHeaders = headers),
            Arg.Do<IEnumerable<IEnumerable<string>>>(rows => actualRows = rows),
            Constants.KeycodeParameterUpload.SheetName)
          .Returns(????);