Exemplo n.º 1
0
        /// <summary>
        /// Setup a server and client fixture.
        /// </summary>
        /// <param name="writer">The test output writer.</param>
        public async Task OneTimeSetUpAsync(TextWriter writer = null)
        {
            // pki directory root for test runs.
            m_pkiRoot = Path.GetTempPath() + Path.GetRandomFileName();

            // start Ref server
            m_serverFixture = new ServerFixture <ReferenceServer> {
                UriScheme       = m_uriScheme,
                SecurityNone    = true,
                AutoAccept      = true,
                OperationLimits = true
            };

            if (writer != null)
            {
                m_serverFixture.TraceMasks = Utils.TraceMasks.Error;
            }

            await m_serverFixture.LoadConfiguration(m_pkiRoot).ConfigureAwait(false);

            m_serverFixture.Config.TransportQuotas.MaxMessageSize      =
                m_serverFixture.Config.TransportQuotas.MaxBufferSize   = 4 * 1024 * 1024;
            m_serverFixture.Config.TransportQuotas.MaxByteStringLength =
                m_serverFixture.Config.TransportQuotas.MaxStringLength = 1 * 1024 * 1024;
            m_server = await m_serverFixture.StartAsync(writer ?? TestContext.Out).ConfigureAwait(false);

            m_clientFixture = new ClientFixture();
            await m_clientFixture.LoadClientConfiguration(m_pkiRoot).ConfigureAwait(false);

            m_clientFixture.Config.TransportQuotas.MaxMessageSize      =
                m_clientFixture.Config.TransportQuotas.MaxBufferSize   = 4 * 1024 * 1024;
            m_clientFixture.Config.TransportQuotas.MaxByteStringLength =
                m_clientFixture.Config.TransportQuotas.MaxStringLength = 1 * 1024 * 1024;
            m_url = new Uri(m_uriScheme + "://localhost:" + m_serverFixture.Port.ToString());
            try
            {
                m_session = await m_clientFixture.ConnectAsync(m_url, SecurityPolicies.Basic256Sha256).ConfigureAwait(false);
            }
            catch (Exception e)
            {
                Assert.Ignore("OneTimeSetup failed to create session, tests skipped. Error: {0}", e.Message);
            }
        }
        /// <summary>
        /// Setup a server and client fixture.
        /// </summary>
        /// <param name="writer">The test output writer.</param>
        public async Task OneTimeSetUpAsync(TextWriter writer = null)
        {
            // pki directory root for test runs.
            PkiRoot = Path.GetTempPath() + Path.GetRandomFileName();
            TestContext.Out.WriteLine("Using the Pki Root {0}", PkiRoot);

            // The parameters are read from the .runsettings file
            string customUrl = null;

            if (SupportsExternalServerUrl)
            {
                customUrl = TestContext.Parameters["ServerUrl"];
                if (customUrl?.StartsWith(UriScheme, StringComparison.Ordinal) == true)
                {
                    TestContext.Out.WriteLine("Using the external Server Url {0}", customUrl);

                    // load custom test sets
                    TestSetStatic     = ReadCustomTestSet("TestSetStatic");
                    TestSetSimulation = ReadCustomTestSet("TestSetSimulation");
                }
                else
                {
                    customUrl = null;
                }
            }

            if (customUrl == null)
            {
                // start Ref server
                ServerFixture = new ServerFixture <ReferenceServer> {
                    UriScheme       = UriScheme,
                    SecurityNone    = true,
                    AutoAccept      = true,
                    AllNodeManagers = true,
                    OperationLimits = true
                };

                if (writer != null)
                {
                    ServerFixture.TraceMasks = Utils.TraceMasks.Error | Utils.TraceMasks.Security;
                }

                await ServerFixture.LoadConfiguration(PkiRoot).ConfigureAwait(false);

                ServerFixture.Config.TransportQuotas.MaxMessageSize      =
                    ServerFixture.Config.TransportQuotas.MaxBufferSize   = TransportQuotaMaxMessageSize;
                ServerFixture.Config.TransportQuotas.MaxByteStringLength =
                    ServerFixture.Config.TransportQuotas.MaxStringLength = TransportQuotaMaxStringLength;
                ServerFixture.Config.ServerConfiguration.UserTokenPolicies.Add(
                    new UserTokenPolicy(UserTokenType.IssuedToken)
                {
                    IssuedTokenType = Opc.Ua.Profiles.JwtUserToken
                });

                ReferenceServer = await ServerFixture.StartAsync(writer ?? TestContext.Out).ConfigureAwait(false);

                ReferenceServer.TokenValidator = this.TokenValidator;
            }

            ClientFixture = new ClientFixture();
            await ClientFixture.LoadClientConfiguration(PkiRoot).ConfigureAwait(false);

            ClientFixture.Config.TransportQuotas.MaxMessageSize      =
                ClientFixture.Config.TransportQuotas.MaxBufferSize   = TransportQuotaMaxMessageSize;
            ClientFixture.Config.TransportQuotas.MaxByteStringLength =
                ClientFixture.Config.TransportQuotas.MaxStringLength = TransportQuotaMaxStringLength;

            if (!string.IsNullOrEmpty(customUrl))
            {
                ServerUrl = new Uri(customUrl);
            }
            else
            {
                ServerUrl = new Uri(UriScheme + "://localhost:" + ServerFixture.Port.ToString(CultureInfo.InvariantCulture));
            }

            if (SingleSession)
            {
                try
                {
                    Session = await ClientFixture.ConnectAsync(ServerUrl, SecurityPolicies.Basic256Sha256).ConfigureAwait(false);
                }
                catch (Exception e)
                {
                    Assert.Ignore("OneTimeSetup failed to create session, tests skipped. Error: {0}", e.Message);
                }
            }
        }