public void TestCreateDontThrowIfNodeExists() { using (var requestHandler = new TestRequestHandler()) using (var client = new RingMasterClient(requestHandler)) { string path = this.GetRandomString(); byte[] data = this.GetRandomData(); var acl = new List <Acl>() { new Acl((int)Acl.Perm.ALL, new Id(AuthSchemes.Digest, this.GetRandomString())) }; var createMode = CreateMode.Persistent; var expectedResult = this.GetRandomString(); requestHandler.Implementation = request => { Assert.IsTrue(request is RequestCreate); var createRequest = (RequestCreate)request; Assert.AreEqual(path, createRequest.Path); Assert.AreEqual(data, createRequest.Data); Assert.AreEqual(acl.Count, createRequest.Acl.Count); Assert.IsTrue(Acl.AreEqual(acl[0], createRequest.Acl[0])); Assert.AreEqual(createMode, createRequest.CreateMode); return(new RequestResponse() { ResultCode = (int)RingMasterException.Code.Nodeexists, Content = expectedResult }); }; client.Create(path, data, acl, createMode, throwIfNodeExists: false).Wait(); } }
public void TestGetDataWithStat() { using (var requestHandler = new TestRequestHandler()) using (var client = new RingMasterClient(requestHandler)) { string path = this.GetRandomString(); var watcher = new TestWatcher(this.GetRandomInt()); byte[] expectedData = this.GetRandomData(); var expectedStat = new Stat() { Version = this.GetRandomInt() }; requestHandler.Implementation = request => { Assert.IsTrue(request is RequestGetData); var getDataRequest = (RequestGetData)request; Assert.AreEqual(path, getDataRequest.Path); Assert.AreEqual(watcher.Id, getDataRequest.Watcher.Id); return(new RequestResponse() { ResultCode = (int)RingMasterException.Code.Ok, Content = expectedData, Stat = expectedStat }); }; var dataAndStat = client.GetDataWithStat(path, watcher).Result; Assert.AreEqual(expectedStat.Version, dataAndStat.Item1.Version); CollectionAssert.AreEqual(expectedData, dataAndStat.Item2); } }
public void TestDelete() { using (var requestHandler = new TestRequestHandler()) using (var client = new RingMasterClient(requestHandler)) { string path = this.GetRandomString(); var version = this.GetRandomInt(); requestHandler.Implementation = request => { Assert.IsTrue(request is RequestDelete); var deleteRequest = (RequestDelete)request; Assert.AreEqual(path, deleteRequest.Path); Assert.AreEqual(version, deleteRequest.Version); return(new RequestResponse() { ResultCode = (deleteRequest.DeleteMode == DeleteMode.None) ? (int)RingMasterException.Code.Ok : (int)RingMasterException.Code.Nonode }); }; bool result = client.Delete(path, version, isRecursive: false).Result; Assert.IsTrue(result); result = client.Delete(path, version, isRecursive: true).Result; Assert.IsFalse(result); } }
public void TestGetChildren() { using (var requestHandler = new TestRequestHandler()) using (var client = new RingMasterClient(requestHandler)) { string path = this.GetRandomString(); string retrievalCondition = this.GetRandomString(); var watcher = new TestWatcher(this.GetRandomInt()); IReadOnlyList <string> expectedChildren = new string[] { this.GetRandomString(), this.GetRandomString() }; requestHandler.Implementation = request => { Assert.IsTrue(request is RequestGetChildren); var getChildrenRequest = (RequestGetChildren)request; Assert.AreEqual(path, getChildrenRequest.Path); Assert.AreEqual(watcher.Id, getChildrenRequest.Watcher.Id); return(new RequestResponse() { ResultCode = (int)RingMasterException.Code.Ok, Content = expectedChildren }); }; client.SetWatcher(watcher); var children = client.GetChildren(path, watch: true, retrievalCondition: retrievalCondition).Result; Assert.AreEqual(expectedChildren.Count, children.Count); for (int i = 0; i < expectedChildren.Count; i++) { Assert.AreEqual(expectedChildren[i], children[i]); } } }
public void TestSetData() { using (var requestHandler = new TestRequestHandler()) using (var client = new RingMasterClient(requestHandler)) { string path = this.GetRandomString(); int version = this.GetRandomInt(); byte[] data = this.GetRandomData(); var expectedStat = new Stat() { Version = this.GetRandomInt() }; requestHandler.Implementation = request => { Assert.IsTrue(request is RequestSetData); var setDataRequest = (RequestSetData)request; Assert.AreEqual(path, setDataRequest.Path); Assert.AreEqual(version, setDataRequest.Version); CollectionAssert.AreEqual(data, setDataRequest.Data); return(new RequestResponse() { ResultCode = (int)RingMasterException.Code.Ok, Stat = expectedStat }); }; var stat = client.SetData(path, data, version).Result; Assert.AreEqual(expectedStat.Version, stat.Version); } }
public void TestSetACL() { using (var requestHandler = new TestRequestHandler()) using (var client = new RingMasterClient(requestHandler)) { string path = this.GetRandomString(); var version = this.GetRandomInt(); var acl = new List <Acl>() { new Acl((int)Acl.Perm.ALL, new Id(AuthSchemes.Digest, this.GetRandomString())) }; var expectedStat = new Stat() { Version = this.GetRandomInt() }; requestHandler.Implementation = request => { Assert.IsTrue(request is RequestSetAcl); var setAclRequest = (RequestSetAcl)request; Assert.AreEqual(path, setAclRequest.Path); Assert.AreEqual(acl.Count, setAclRequest.Acl.Count); Assert.IsTrue(Acl.AreEqual(acl[0], setAclRequest.Acl[0])); return(new RequestResponse() { ResultCode = (int)RingMasterException.Code.Ok, Stat = expectedStat }); }; var stat = client.SetACL(path, acl, version).Result; Assert.AreEqual(expectedStat.Version, stat.Version); } }
public void CanSendStreamingRequest() { var socket = new TestWebSocket(); var requestHandler = new TestRequestHandler(); using (var sut = new TestLegacyStreamingConnection(socket, NullLogger.Instance)) { sut.ListenAsync(requestHandler).Wait(); var request = new StreamingRequest { Verb = "POST", Path = "/api/messages", Streams = new List <ResponseMessageStream> { new ResponseMessageStream { Content = new StringContent("foo") } } }; var response = sut.SendStreamingRequestAsync(request).Result; Assert.Equal(request.Streams.Count, response.Streams.Count); Assert.Equal(request.Streams[0].Id, response.Streams[0].Id); } }
public void TestMove() { using (var requestHandler = new TestRequestHandler()) using (var client = new RingMasterClient(requestHandler)) { string pathSrc = this.GetRandomString(); string pathDst = this.GetRandomString(); var version = this.GetRandomInt(); var moveMode = MoveMode.AllowPathCreationFlag; var expectedResult = this.GetRandomString(); requestHandler.Implementation = request => { Assert.IsTrue(request is RequestMove); var moveRequest = (RequestMove)request; Assert.AreEqual(pathSrc, moveRequest.Path); Assert.AreEqual(pathDst, moveRequest.PathDst); Assert.AreEqual(version, moveRequest.Version); Assert.AreEqual(moveMode, moveRequest.MoveMode); return(new RequestResponse() { ResultCode = (int)RingMasterException.Code.Ok, Content = expectedResult }); }; string result = client.Move(pathSrc, version, pathDst, moveMode).Result; Assert.AreEqual(expectedResult, result); } }
public void TestExists() { using (var requestHandler = new TestRequestHandler()) using (var client = new RingMasterClient(requestHandler)) { string path = this.GetRandomString(); var version = this.GetRandomInt(); var watcher = new TestWatcher(this.GetRandomInt()); var expectedStat = new Stat() { Version = this.GetRandomInt() }; requestHandler.Implementation = request => { Assert.IsTrue(request is RequestExists); var existsRequest = (RequestExists)request; Assert.AreEqual(path, existsRequest.Path); Assert.AreEqual(watcher.Id, existsRequest.Watcher.Id); return(new RequestResponse() { ResultCode = (int)RingMasterException.Code.Ok, Content = expectedStat }); }; client.SetWatcher(watcher); IStat stat = client.Exists(path, watch: true).Result; Assert.IsNotNull(stat); Assert.AreEqual(expectedStat.Version, stat.Version); } }
public void CanCreateNamedPipeServer() { var requestHandler = new TestRequestHandler(); var sut = new LegacyStreamingConnection("test", NullLogger.Instance); var server = sut.CreateStreamingTransportServer(requestHandler); Assert.True(server is NamedPipeServer); }
public void CanCreateWebSocketServer() { var socket = new TestWebSocket(); var requestHandler = new TestRequestHandler(); var sut = new LegacyStreamingConnection(socket, NullLogger.Instance); var server = sut.CreateStreamingTransportServer(requestHandler); Assert.True(server is WebSocketServer); }
public void Invoke(IDictionary <string, string> argsDictionary) { // Setup logging if enabled string logFile; if (argsDictionary.TryGetValue(LogFileArgument, out logFile)) { EqtTrace.InitializeVerboseTrace(logFile); } #if NET46 if (EqtTrace.IsInfoEnabled) { var appConfigText = System.IO.File.ReadAllText(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile); EqtTrace.Info("DefaultEngineInvoker: Using Application Configuration: '{0}'", appConfigText); } #endif // Get port number and initialize communication var portNumber = GetIntArgFromDict(argsDictionary, PortArgument); // Start Processing of requests using (var requestHandler = new TestRequestHandler()) { // Attach to exit of parent process var parentProcessId = GetIntArgFromDict(argsDictionary, ParentProcessIdArgument); EqtTrace.Info("DefaultEngineInvoker: Monitoring parent process with id: '{0}'", parentProcessId); var parentProcessMonitoringTask = WaitForParentProcessExitAsync(parentProcessId); // Initialize Communication EqtTrace.Info("DefaultEngineInvoker: Initialize communication on port number: '{0}'", portNumber); requestHandler.InitializeCommunication(portNumber); // Can only do this after InitializeCommunication because TestHost cannot "Send Log" unless communications are initialized if (!string.IsNullOrEmpty(EqtTrace.LogFile)) { requestHandler.SendLog(TestMessageLevel.Informational, string.Format("Logging TestHost Diagnostics in file: {0}", EqtTrace.LogFile)); } // Start processing async in a different task EqtTrace.Info("DefaultEngineInvoker: Start Request Processing."); var processingTask = StartProcessingAsync(requestHandler, new TestHostManagerFactory()); // Wait for either processing to complete or parent process exit Task.WaitAny(processingTask, parentProcessMonitoringTask); } }
private bool Handle(HttpListenerContext context) { context.Response.StatusCode = 200; context.Response.Headers.Add(Constants.HeaderAccessControlAllowOrigin); context.Response.Headers.Add("Server", $"RemoteFork/1.3a"); string httpUrl = context.Request.RawUrl; Console.WriteLine("URL:" + httpUrl); if (httpUrl.IndexOf("/treeview") == 0) { if (context.Request.QueryString.GetValues(null)?.FirstOrDefault(s => PluginRequestHandler.PluginParamRegex.IsMatch(s ?? string.Empty)) != null) { var Handler = new PluginRequestHandler(); Handler.Handle(context); } else { var Handler = new RootRequestHandler(); Handler.Handle(context); } } else if (httpUrl.IndexOf("/proxym3u8") == 0) { var Handler = new ProxyM3u8(); Handler.Handle(context, true); } else { if (httpUrl.StartsWith("/parserlink")) { var Handler = new ParseLinkRequestHandler(); Handler.Handle(context, true); } else { if (httpUrl.StartsWith("/test")) { var Handler = new TestRequestHandler(); Handler.Handle(context, true); } } } return(true); }
public void TestBatch() { using (var requestHandler = new TestRequestHandler()) using (var client = new RingMasterClient(requestHandler)) { string path = this.GetRandomString(); var version = this.GetRandomInt(); var operations = new List <Op>(); operations.Add(Op.Delete(path, version, recursive: false)); var expectedResults = new List <OpResult>(); expectedResults.Add(new OpResult.DeleteResult()); requestHandler.Implementation = request => { Assert.IsTrue(request is RequestBatch); var batchRequest = (RequestBatch)request; Assert.IsTrue(batchRequest.CompleteSynchronously); Assert.AreEqual(operations.Count, batchRequest.Requests.Count); Assert.IsTrue(batchRequest.Requests[0] is RequestDelete); return(new RequestResponse() { ResultCode = (int)RingMasterException.Code.Ok, Content = expectedResults }); }; var results = client.Batch(operations, mustCompleteSynchronously: true).Result; Assert.AreEqual(results.Count, expectedResults.Count); Assert.IsTrue(results[0] is OpResult.DeleteResult); try { client.Batch(null, mustCompleteSynchronously: false).Wait(); Assert.Fail("Batch call must have thrown ArgumentNullException"); } catch (ArgumentException) { } } }
public void TestSync() { using (var requestHandler = new TestRequestHandler()) using (var client = new RingMasterClient(requestHandler)) { string path = this.GetRandomString(); requestHandler.Implementation = request => { Assert.IsTrue(request is RequestSync); var syncRequest = (RequestSync)request; Assert.AreEqual(path, syncRequest.Path); return(new RequestResponse() { ResultCode = (int)RingMasterException.Code.Ok }); }; client.Sync(path).Wait(); } }
public void TestCreateAndGetStat() { using (var requestHandler = new TestRequestHandler()) using (var client = new RingMasterClient(requestHandler)) { string path = this.GetRandomString(); byte[] data = this.GetRandomData(); var acl = new List <Acl>() { new Acl((int)Acl.Perm.ALL, new Id(AuthSchemes.Digest, this.GetRandomString())) }; var createMode = CreateMode.Persistent; var expectedStat = new Stat() { Version = this.GetRandomInt() }; requestHandler.Implementation = request => { Assert.IsTrue(request is RequestCreate); var createRequest = (RequestCreate)request; Assert.AreEqual(path, createRequest.Path); Assert.AreEqual(data, createRequest.Data); Assert.AreEqual(acl.Count, createRequest.Acl.Count); Assert.IsTrue(Acl.AreEqual(acl[0], createRequest.Acl[0])); Assert.AreEqual(createMode, createRequest.CreateMode); return(new RequestResponse() { ResultCode = (int)RingMasterException.Code.Ok, Stat = expectedStat }); }; IStat stat = client.CreateAndGetStat(path, data, acl, createMode).Result; Assert.AreEqual(expectedStat.Version, stat.Version); } }
public void TestSetAuth() { using (var requestHandler = new TestRequestHandler()) using (var client = new RingMasterClient(requestHandler)) { string path = this.GetRandomString(); var id = new Id(AuthSchemes.Digest, this.GetRandomString()); requestHandler.Implementation = request => { Assert.IsTrue(request is RequestSetAuth); var setAuthRequest = (RequestSetAuth)request; Assert.AreEqual($"digest:{id.Identifier}", setAuthRequest.ClientId); return(new RequestResponse() { ResultCode = (int)RingMasterException.Code.Ok }); }; client.SetAuth(id).Wait(); } }
public void Invoke(IDictionary <string, string> argsDictionary) { // Setup logging if enabled string logFile; if (argsDictionary.TryGetValue(LogFileArgument, out logFile)) { EqtTrace.InitializeVerboseTrace(logFile); } #if NET451 if (EqtTrace.IsInfoEnabled) { var appConfigText = System.IO.File.ReadAllText(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile); EqtTrace.Info("DefaultEngineInvoker: Using Application Configuration: '{0}'", appConfigText); } #endif // vstest.console < 15.5 won't send endpoint and role arguments. // So derive endpoint from port argument and Make connectionRole as Client. string endpoint = CommandLineArgumentsHelper.GetStringArgFromDict(argsDictionary, EndpointArgument); if (string.IsNullOrWhiteSpace(endpoint)) { var port = CommandLineArgumentsHelper.GetIntArgFromDict(argsDictionary, "--port"); endpoint = IPAddress.Loopback + ":" + port; } var connectionRole = ConnectionRole.Client; string role = CommandLineArgumentsHelper.GetStringArgFromDict(argsDictionary, RoleArgument); if (!string.IsNullOrWhiteSpace(role) && string.Equals(role, "host", StringComparison.OrdinalIgnoreCase)) { connectionRole = ConnectionRole.Host; } // Start Processing of requests using (var requestHandler = new TestRequestHandler(new TestHostConnectionInfo { Endpoint = endpoint, Role = connectionRole, Transport = Transport.Sockets })) { // Attach to exit of parent process var parentProcessId = CommandLineArgumentsHelper.GetIntArgFromDict(argsDictionary, ParentProcessIdArgument); EqtTrace.Info("DefaultEngineInvoker: Monitoring parent process with id: '{0}'", parentProcessId); // In remote scenario we cannot monitor parent process, so we expect user to pass parentProcessId as -1 if (parentProcessId != -1) { var processHelper = new ProcessHelper(); processHelper.SetExitCallback( parentProcessId, () => { EqtTrace.Info("DefaultEngineInvoker: ParentProcess '{0}' Exited.", parentProcessId); new PlatformEnvironment().Exit(1); }); } // Initialize Communication EqtTrace.Info("DefaultEngineInvoker: Initialize communication on endpoint address: '{0}'", endpoint); requestHandler.InitializeCommunication(); // Initialize DataCollection Communication if data collection port is provided. var dcPort = CommandLineArgumentsHelper.GetIntArgFromDict(argsDictionary, DataCollectionPortArgument); if (dcPort > 0) { var dataCollectionTestCaseEventSender = DataCollectionTestCaseEventSender.Create(); dataCollectionTestCaseEventSender.InitializeCommunication(dcPort); dataCollectionTestCaseEventSender.WaitForRequestSenderConnection(ClientListenTimeOut); } // Checks for Telemetry Opted in or not from Command line Arguments. // By Default opting out in Test Host to handle scenario when user running old version of vstest.console var telemetryStatus = CommandLineArgumentsHelper.GetStringArgFromDict(argsDictionary, TelemetryOptedIn); var telemetryOptedIn = false; if (!string.IsNullOrWhiteSpace(telemetryStatus)) { if (telemetryStatus.Equals("true", StringComparison.Ordinal)) { telemetryOptedIn = true; } } var requestData = new RequestData { MetricsCollection = telemetryOptedIn ? (IMetricsCollection) new MetricsCollection() : new NoOpMetricsCollection(), IsTelemetryOptedIn = telemetryOptedIn }; // Start processing async in a different task EqtTrace.Info("DefaultEngineInvoker: Start Request Processing."); var processingTask = this.StartProcessingAsync(requestHandler, new TestHostManagerFactory(requestData)); // Wait for processing to complete. Task.WaitAny(processingTask); if (dcPort > 0) { // Close socket communication connection. DataCollectionTestCaseEventSender.Instance.Close(); } } }
public void SetUp() { _testRequestHandler = new TestRequestHandler(); }
public static void InitializeTestRequestHandlerWS(TestContext testContext) { TestRequestHandler = new TestRequestHandler(new UtilWS(), new AssertTestWS()); }
public void SetUp() { TestRequestHandler = new TestRequestHandler(new UtilWP80(), new AssertTestWP80()); TestRequestHandler.SetUp(); }
public override IList<RequestHandler> GetRequestHandlers() { this.handler = new TestRequestHandler(); return new RequestHandler[] {this.handler}; }
public override IList <RequestHandler> GetRequestHandlers() { this.handler = new TestRequestHandler(); return(new RequestHandler[] { this.handler }); }
public ActionResult Test() { HttpContext.Response.Headers["Access-Control-Allow-Origin"] = "*"; ViewData["Message"] = new TestRequestHandler().Handle(HttpContext); return(View()); }
public static void InitializeTestRequestHandlerUAP10(TestContext testContext) { TestRequestHandler = new TestRequestHandler(new UtilUAP10(), new AssertTestUAP10()); }
public void Invoke(IDictionary <string, string> argsDictionary) { // Setup logging if enabled string logFile; if (argsDictionary.TryGetValue(LogFileArgument, out logFile)) { EqtTrace.InitializeVerboseTrace(logFile); } #if NET46 if (EqtTrace.IsInfoEnabled) { var appConfigText = System.IO.File.ReadAllText(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile); EqtTrace.Info("DefaultEngineInvoker: Using Application Configuration: '{0}'", appConfigText); } #endif // Get port number and initialize communication var portNumber = CommandLineArgumentsHelper.GetIntArgFromDict(argsDictionary, PortArgument); // Start Processing of requests using (var requestHandler = new TestRequestHandler()) { // Attach to exit of parent process var parentProcessId = CommandLineArgumentsHelper.GetIntArgFromDict(argsDictionary, ParentProcessIdArgument); EqtTrace.Info("DefaultEngineInvoker: Monitoring parent process with id: '{0}'", parentProcessId); var processHelper = new ProcessHelper(); processHelper.SetExitCallback( parentProcessId, () => { EqtTrace.Info("DefaultEngineInvoker: ParentProcess '{0}' Exited.", parentProcessId); Environment.Exit(1); }); // Initialize Communication EqtTrace.Info("DefaultEngineInvoker: Initialize communication on port number: '{0}'", portNumber); requestHandler.InitializeCommunication(portNumber); // Initialize DataCollection Communication if data collection port is provided. var dcPort = CommandLineArgumentsHelper.GetIntArgFromDict(argsDictionary, DataCollectionPortArgument); if (dcPort > 0) { var dataCollectionTestCaseEventSender = DataCollectionTestCaseEventSender.Create(); dataCollectionTestCaseEventSender.InitializeCommunication(dcPort); dataCollectionTestCaseEventSender.WaitForRequestSenderConnection(ClientListenTimeOut); } // Start processing async in a different task EqtTrace.Info("DefaultEngineInvoker: Start Request Processing."); var processingTask = this.StartProcessingAsync(requestHandler, new TestHostManagerFactory()); // Wait for processing to complete. Task.WaitAny(processingTask); if (dcPort > 0) { // Close socket communication connection. DataCollectionTestCaseEventSender.Instance.Close(); } } }