小编Jel*_*tra的帖子

Azure Blob 存储:模拟 CloudBlobContainer

我正在尝试对一个将文件上传到 Azure Blob 存储的类进行单元测试。上传方法作为CloudBlobContainer输入。调用时_storageContainer.Object.GetBlockBlobReference(),会引发 System.NullReferenceException。谁能帮我嘲笑这个?

单元测试代码:

[TestClass()]
public class BlobStorageServiceUploadUnitTest
{
    private static BlobStorageService _service;
    private static Mock<CloudBlobContainer> _storageContainer;
    private static List<FileType> _extensions;
    private static int _maxSize;

    [ClassInitialize]
    public static void Setup_Service(TestContext context)
    {
        _extensions = new List<FileType> { FileType.Image };
        _maxSize = 2048;

        _storageContainer = new Mock<CloudBlobContainer>();

        _service = new BlobStorageService(new Mock<BEntitiesContainer>().Object, _storageContainer.Object);
    }

    [TestMethod()]
    public void When_FileIsDeleted()
    {
        var file = CreateMockFile("test.jpg", 500000);
        var blob = _storageContainer.Object.GetBlockBlobReference("deleteTest.jpg");
        blob.UploadFromStream(file.Object.InputStream);

        _service.DeleteFromStorage("deleteTest.jpg");

        var blobs = _storageContainer.Object.ListBlobs();
        Assert.AreEqual(0, …
Run Code Online (Sandbox Code Playgroud)

c# unit-testing moq azure-blob-storage

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

删除XML元素节点

我想使用C#删除本地xml文件中的an Element Node和all Child Elements.

这是我的xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<data>
  <cocktail name="43 Hedonism" id="14">
    <name>43 Hedonism</name>
    <id>14</id>
  </cocktail>
  <cocktail name="B-52" id="4">
    <name>B-52</name>
    <id>4</id>
  </cocktail>
</data>
Run Code Online (Sandbox Code Playgroud)

我想删除一个鸡尾酒元素,其中id-attribute为4,存储在变量中.如何告诉我的应用程序只需删除id为4的鸡尾酒元素? XmlNode.RemoveChild由于Windows Phone 8中不支持/不可用,因此无法正常工作.我编写了以下代码,但我仍然坚持在哪里写出要删除的元素的id.

using System;
using System.IO;
using System.IO.IsolatedStorage;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Resources;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using XmlLocalDelete1.Resources;
using System.Xml;
using System.Xml.Linq;
using System.Text;

namespace XmlLocalDelete1
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent(); …
Run Code Online (Sandbox Code Playgroud)

c# xml windows-phone-8

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

参数字典包含参数Orderid的空条目

当调用CheckoutController的Data操作时,我不断收到以下错误:

在此输入链接描述 我正在使用这种技术在其他几个控制器中传递参数,我没有遇到任何麻烦.我的CheckoutController代码和默认路由如下所示.提前致谢!

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebApplication2.Functions;
using WebApplication2.Models;

namespace WebApplication2.Controllers
{
    public class CheckoutController : Controller
    {
        private thelearningbayEntities _db = new thelearningbayEntities();
        private Auth Permission = new Auth();

        [HttpGet]
        public ActionResult Data(int Orderid) 
        {
            if (Permission.Check(0))
            {
                var email = Session["email"].ToString();
                _db.Configuration.ProxyCreationEnabled = false; 

                var result = (from order_line in _db.order_line
                              join orders in _db.orders on order_line.id_order equals orders.id_order
                              join product in _db.product on order_line.p_id equals product.p_id
                              where (orders.email == email) …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc

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

在Docker容器中运行dotnet测试

我想dotnet test在docker容器中运行命令,但是我无法弄清楚将命令放在哪里。该项目是.NET Core 2.1测试项目。原因是我要运行端到端集成测试,这要求我所有的容器都在运行。

DockerFile:

FROM microsoft/dotnet:2.1-runtime AS base
WORKDIR /app

FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /src
COPY *.sln ./
COPY Sombra.IntegrationTests/Sombra.IntegrationTests.csproj Sombra.IntegrationTests/
COPY . .
WORKDIR /src/Sombra.IntegrationTests
RUN dotnet build -c Release -o /app

FROM build AS publish
RUN dotnet publish -c Release -o /app

FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "test", "Sombra.IntegrationTests.csproj"]
Run Code Online (Sandbox Code Playgroud)

docker-compose.yml

version: '3'

services:
  sombra.integrationtests:
    image: sombra.integrationtests
    build:
      context: .
      dockerfile: Sombra.IntegrationTests/Dockerfile
    depends_on:
      - rabbitmq
Run Code Online (Sandbox Code Playgroud)

docker .net-core docker-compose

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