A class that represents a multitenant host of Stumps servers.
상속: IStumpsHost
예제 #1
0
 public void Constructor_NullHostName_ThrowsException()
 {
     StumpsHost proxy = new StumpsHost(Substitute.For<IServerFactory>(), Substitute.For<IDataAccess>());
     Assert.That(
         () => proxy.CreateServerInstance(null, _defaultPort, true, false),
         Throws.Exception.TypeOf<ArgumentNullException>().With.Property("ParamName").EqualTo("remoteServerHostName"));
 }
예제 #2
0
        public void Constructor_NullHostName_ThrowsException()
        {
            StumpsHost proxy = new StumpsHost(Substitute.For <IServerFactory>(), Substitute.For <IDataAccess>());

            Assert.That(
                () => proxy.CreateServerInstance(null, _defaultPort, true, false),
                Throws.Exception.TypeOf <ArgumentNullException>().With.Property("ParamName").EqualTo("remoteServerHostName"));
        }
예제 #3
0
        public void Constructor_PortNumberRange_ThrowsException()
        {
            StumpsHost proxy = new StumpsHost(Substitute.For<IServerFactory>(), Substitute.For<IDataAccess>());
            Assert.That(
                () => proxy.CreateServerInstance("www.foo.com", IPEndPoint.MaxPort + 1, true, false),
                Throws.Exception.TypeOf<ArgumentOutOfRangeException>().With.Property("ParamName").EqualTo("port"));

            Assert.That(
                () => proxy.CreateServerInstance("www.foo.com", IPEndPoint.MinPort - 1, true, false),
                Throws.Exception.TypeOf<ArgumentOutOfRangeException>().With.Property("ParamName").EqualTo("port"));
        }
예제 #4
0
        public void Constructor_PortNumberRange_ThrowsException()
        {
            StumpsHost proxy = new StumpsHost(Substitute.For <IServerFactory>(), Substitute.For <IDataAccess>());

            Assert.That(
                () => proxy.CreateServerInstance("www.foo.com", IPEndPoint.MaxPort + 1, true, false),
                Throws.Exception.TypeOf <ArgumentOutOfRangeException>().With.Property("ParamName").EqualTo("port"));

            Assert.That(
                () => proxy.CreateServerInstance("www.foo.com", IPEndPoint.MinPort - 1, true, false),
                Throws.Exception.TypeOf <ArgumentOutOfRangeException>().With.Property("ParamName").EqualTo("port"));
        }
예제 #5
0
        public void Constructor_PortInUse_ThrowsException()
        {
            int    port             = NetworkInformation.FindRandomOpenPort();
            string externalHostName = "www.foo.com";
            bool   autoStart        = false;
            bool   useSsl           = true;

            var proxyEntity = new ServerEntity
            {
                AutoStart            = autoStart,
                RemoteServerHostName = externalHostName,
                Port     = port,
                UseSsl   = useSsl,
                ServerId = RandomGenerator.GenerateIdentifier()
            };

            var dataAccess = Substitute.For <IDataAccess>();

            dataAccess.ServerFind(Arg.Any <string>()).Returns(proxyEntity);

            // create a TcpListener already listening on the port
            var tcpListener = new TcpListener(IPAddress.Loopback, port);

            try
            {
                tcpListener.Start();

                StumpsHost proxy = new StumpsHost(Substitute.For <IServerFactory>(), dataAccess);
                Assert.That(
                    () => proxy.CreateServerInstance(externalHostName, port, useSsl, autoStart),
                    Throws.Exception.TypeOf <StumpsNetworkException>().With.Property("Message").EqualTo("The port is already in use."));
            }
            finally
            {
                tcpListener.Stop();
            }
        }
예제 #6
0
        public void Constructor_PortInUse_ThrowsException()
        {
            int port = NetworkInformation.FindRandomOpenPort();
            string externalHostName = "www.foo.com";
            bool autoStart = false;
            bool useSsl = true;

            var proxyEntity = new ServerEntity
            {
                AutoStart = autoStart,
                RemoteServerHostName = externalHostName,
                Port = port,
                UseSsl = useSsl,
                ServerId = RandomGenerator.GenerateIdentifier()
            };

            var dataAccess = Substitute.For<IDataAccess>();
            dataAccess.ServerFind(Arg.Any<string>()).Returns(proxyEntity);

            // create a TcpListener already listening on the port
            var tcpListener = new TcpListener(IPAddress.Loopback, port);

            try
            {
                tcpListener.Start();

                StumpsHost proxy = new StumpsHost(Substitute.For<IServerFactory>(), dataAccess);
                Assert.That(
                    () => proxy.CreateServerInstance(externalHostName, port, useSsl, autoStart),
                    Throws.Exception.TypeOf<StumpsNetworkException>().With.Property("Message").EqualTo("The port is already in use."));
            }
            finally
            {
                tcpListener.Stop();
            }
        }
예제 #7
0
        public void Start()
        {
            // Prevent multiple simultaneous requests to start or stop the instance.
            lock (_syncRoot)
            {

                if (_started)
                {
                    return;
                }

                _started = true;

                // Initialize a new instance of the data access layer.
                var dataAccess = new DataAccess(this.Configuration.StoragePath);

                var factory = new ServerFactory();

                // Initialize and load a new instance of the proxy host.
                _host = new StumpsHost(factory, dataAccess);
                _host.Load();

                // Initialize the Nancy web server module.
                _webServer = new StumpsWebServer(_host, this.Configuration.WebApiPort);

                // Start the host and the web server
                _host.Start();
                _webServer.Start();

            }
        }