Ejemplo n.º 1
0
        public void UriUnescapeInvalid_ValidUtf8IncompleteUtf8AsciiIriOn_InvalidUtf8LeftAlone()
        {
            using (ThreadCultureChange irihelper = new ThreadCultureChange())
            {
                string input = "http://host/%E6%9C%88%E6%9C%59";

                Uri uri = new Uri(input);
                Assert.Equal("http://host/%E6%9C%88%E6%9CY", uri.AbsoluteUri);
                Assert.Equal("http://host/\u6708%E6%9CY", uri.ToString());

                string output = Uri.UnescapeDataString(input);
                Assert.Equal("http://host/\u6708%E6%9CY", output);

                irihelper.ChangeCultureInfo("zh-cn");
                Uri uriZhCn = new Uri(input);
                Assert.Equal(uri.ToString(), uriZhCn.ToString());
                Assert.Equal(uri.AbsoluteUri, uriZhCn.AbsoluteUri);

                string outputZhCn = Uri.UnescapeDataString(input);
                Assert.Equal(output, outputZhCn);
            }
        }
Ejemplo n.º 2
0
        public async Task CloseAsync_CreateAndReceive_ThrowsInvalidOperationExceptionWithMessage()
        {
            using (var cws = new ClientWebSocket())
            {
                var buffer  = new byte[100];
                var segment = new ArraySegment <byte>(buffer);
                var ct      = new CancellationToken();

                InvalidOperationException exception;

                using (var tcc = new ThreadCultureChange())
                {
                    tcc.ChangeCultureInfo(CultureInfo.InvariantCulture);
                    exception = await Assert.ThrowsAsync <InvalidOperationException>(
                        () => cws.ReceiveAsync(segment, ct));
                }

                string expectedMessage = ResourceHelper.GetExceptionMessage("net_WebSockets_NotConnected");
                Assert.Equal(expectedMessage, exception.Message);
                Assert.Equal(WebSocketState.None, cws.State);
            }
        }