C#测试不会编译

时间:2017-03-17 16:14:38

标签: c# compiler-errors

Project JohnsonTest中的测试类

using Microsoft.VisualStudio.TestTools.UnitTesting;
using Usecases;
using Requests;

namespace Controllers
{
    [TestClass]
    public class InitialContollerTest : IUsecase
    {
        private bool executeMethodCalled = false;

        public void Execute(IRequest request)
        {
            executeMethodCalled = true;
        }

        [TestMethod]
        public void ShouldCallInitialUsecase()
        {
            IRequest request = new InitialRequest();
            InitialController controller = new InitialController(request, this);
            controller.Execute();
            Assert.IsTrue(executeMethodCalled);
        }
    }
}

Project Johnson的测试类

using Requests;
using Usecases;

namespace Controllers
{
    interface IController
    {
        void Execute();
    }

    public class InitialController : IController
    {
        private IUsecase usecase;
        private IRequest request;

        public InitialController(IRequest request, IUsecase usecase)
        {
            this.request = request;
            this.usecase = usecase;
        }

        public void Execute()
        {
            usecase.Execute(request);
        }
    }
}

约翰逊项目涉及的其他课程

using Requests;

namespace Usecases
{
    public interface IUsecase
    {
        void Execute(IRequest request);
    }

    public class InitialUsecase : IUsecase
    {
        public void Execute(IRequest request)
        {
            ;
        }
    }
}

namespace Requests
{
    public interface IRequest
    {
    }

    public class InitialRequest : IRequest
    {
    }
}

构建错误是:

  

1> C:\ Users \ bggib_000 \ documents \ visual studio   2017 \ Projects \ Johnson \ Johnson \ JohnsonRibbon.cs(25,21,25,38):错误   CS7036:没有给出符合要求的论据   形式参数'usecase'   'InitialController.InitialController(IRequest,IUsecase)'

这似乎是抱怨'这个',但我以前的测试只是'这个'

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Usecases;

namespace Controllers
{
    [TestClass]
    public class InitialContollerTest : IUsecase
    {
        private bool executeMethodCalled = false;

        void IUsecase.Execute()
        {
            executeMethodCalled = true;
        }

        [TestMethod]
        public void ShouldCallInitialUsecase()
        {
            InitialController controller = new InitialController(this);
            controller.Execute();
            Assert.IsTrue(executeMethodCalled);
        }


    }
}

使用此课程:

public class InitialController : IController
    {
        IUsecase usecase;

        public InitialController(IUsecase usecase)
        {
            this.usecase = usecase;
        }

        public void Execute()
        {
            usecase.Execute();
        }
    }
  

2> C:\ Users \ bggib_000 \ documents \ visual studio   2017 \ Projects \ Johnson \ JohnsonTest \ ContollerTest.cs(8,41,8,49):错误   CS0535:'InitialContollerTest'没有实现接口成员   'IUsecase.Execute()'

这似乎在抱怨一些不存在的东西。

using Requests;

namespace Usecases
{
    public interface IUsecase
    {
        void Execute(IRequest request);
    }

    public class InitialUsecase : IUsecase
    {
        public void Execute(IRequest request)
        {
            ;
        }
    }
}

Visual Studio Community 2017并未指出任何错误。为什么不编译?

1 个答案:

答案 0 :(得分:0)

此文件出现问题:

using Microsoft.Office.Tools.Ribbon;
using Excel = Microsoft.Office.Interop.Excel;
using Controllers;

namespace Johnson
{
    public partial class JohnsonRibbon
    {
        private void JohnsonRibbon_Load(object sender, RibbonUIEventArgs e)
        {

        }

        private void OnInitalButtonClick(object sender, RibbonControlEventArgs e)
        {
            string Prompt = "Select two data columns (X, Freq) for analysis";
            string Title = "Select Histogram";
            var range = Globals.ThisAddIn.Application.InputBox(Prompt: Prompt, Title: Title, Type: 8);
            if (range is Excel.Range)
            {
                new InitialController(new Usecases.InitialUsecase()).Execute();
            }
        }
    }
}

我改变了这一行

new InitialController(new Usecases.InitialUsecase()).Execute();

对此有用

new InitialController(new Requests.InitialRequest(), new Usecases.InitialUsecase()).Execute();