Beispiel #1
0
        public void Dispose()
        {
            _host.Dispose();

            MockServiceRepository.Unregister(this);

            if (!_ignoreUnusedHandlers && _unusedHandlers.Any())
            {
                throw new InvalidOperationException(
                          String.Format("Mock Server {0} expected requests \r\n\r\n {1} \r\n\r\n but they were not made.",
                                        BaseAddress,
                                        _unusedHandlers.Select(h => new ConstantMemberEvaluationVisitor().Visit(h).ToString())
                                        .Aggregate((c, n) => c + "\r\n" + n)));
            }
        }
Beispiel #2
0
        public MockService(bool ignoreUnusedHandlers = false)
        {
            _handlers             = new List <Tuple <Expression <Func <HttpRequest, bool> >, Func <HttpResponse, Task> > >();
            _unusedHandlers       = new List <Expression <Func <HttpRequest, bool> > >();
            _ignoreUnusedHandlers = ignoreUnusedHandlers;

            MockServiceRepository.Register(this);


            var builder = new WebHostBuilder()
                          .UseStartup <Startup>()
                          .UseKestrel()
                          .UseSetting("applicationName", ServiceId)
                          .UseUrls("http://127.0.0.1:0");

            _host = builder.Build();

            _host.Start();

            BaseAddress = _host
                          .ServerFeatures.Get <IServerAddressesFeature>()
                          .Addresses.First();
        }
Beispiel #3
0
 public Startup(IHostingEnvironment env)
 {
     _service = MockServiceRepository.GetServiceMockById(env.ApplicationName);
 }