public WeatherForecastController(ILogger <WeatherForecastController> logger, IServiceOne serviceOne, IServiceTwo serviceTwo, IServiceProvider serviceProvider)
 {
     _logger          = logger;
     _serviceOne      = serviceOne;
     _serviceTwo      = serviceTwo;
     _serviceProvider = serviceProvider;
 }
示例#2
0
 public ScopesController(IServiceOne testingServiceOne, IServiceTwo testingServiceTwo, ISingleton singleton, IScoped scoped, ITransient transient)
 {
     this.testingServiceOne = testingServiceOne;
     this.testingServiceTwo = testingServiceTwo;
     this.singleton         = singleton;
     this.scoped            = scoped;
     this.transient         = transient;
 }
示例#3
0
        private void CanMockGenericMethodOnClass(Mock <IParentInterface> mock)
        {
            Mock <IServiceOne> serviceOneMock = Factory.CreateMock <IServiceOne>();
            Mock <IServiceTwo> serviceTwoMock = Factory.CreateMock <IServiceTwo>();

            // That works only with Expect and if the order of calls to Get match the order of the expectations:
            mock.Expects.One.Method(_ => _.Method <IServiceOne>()).WillReturn(serviceOneMock.MockObject);
            mock.Expects.One.Method(_ => _.Method <IServiceTwo>()).Will(Return.Value(serviceTwoMock.MockObject));

            serviceOneMock.Expects.One.Method(_ => _.ServiceOneGetsName()).Will(Return.Value("ServiceOne"));
            serviceTwoMock.Expects.One.Method(_ => _.ServiceTwoSaves()).Will(Return.Value(true));

            // real call now; only works in same order as the expectations
            IServiceOne serviceOne = mock.MockObject.Method <IServiceOne>();
            string      name       = serviceOne.ServiceOneGetsName();

            Assert.AreEqual("ServiceOne", name, "Service one returned wrong name.");

            IServiceTwo serviceTwo = mock.MockObject.Method <IServiceTwo>();
            bool        res        = serviceTwo.ServiceTwoSaves();

            Assert.AreEqual(true, res, "Service two returned wrong boolean value.");
        }
示例#4
0
 public ServiceOne(IServiceTwo serviceTwo)
 {
     //虽然没有使用IServiceTwo依赖,但是没有它,ServiceOne是不能实例化的
 }
示例#5
0
 public Controller(IServiceOne service_one, IServiceTwo service_two, ServiceThree service_three)
 {
     ServiceOne   = service_one;
     ServiceTwo   = service_two;
     ServiceThree = service_three;
 }
示例#6
0
 public ServiceTwoController(IServiceTwo serviceTwo)
 {
     _serviceTwo = serviceTwo;
 }
 public Foo(IServiceOne one, IServiceTwo two, string parameter)
 {
示例#8
0
 public Controller(IServiceOne service_one, IServiceTwo service_two, ServiceThree service_three)
 {
     ServiceOne = service_one;
     ServiceTwo = service_two;
     ServiceThree = service_three;
 }