// // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. // using System.Collections.Generic; using Microsoft.SqlTools.ServiceLayer.Connection; using Microsoft.SqlTools.ServiceLayer.Profiler; using Microsoft.SqlTools.ServiceLayer.Profiler.Contracts; namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Profiler { public static class ProfilerTestObjects { public static List TestProfilerEvents { get { ProfilerEvent event1 = new ProfilerEvent("event1", "1/1/2017"); event1.Values.Add("event_sequence", "1"); ProfilerEvent event2 = new ProfilerEvent("event2", "1/2/2017"); event2.Values.Add("event_sequence", "2"); ProfilerEvent event3 = new ProfilerEvent("event3", "1/3/2017"); event3.Values.Add("event_sequence", "3"); return new List { event1, event2, event3 }; } } } public class TestSessionListener : IProfilerSessionListener { public string PreviousSessionId { get; set; } public List PreviousEvents { get; set; } public bool Stopped { get; set; } public void EventsAvailable(string sessionId, List events, bool eventsLost) { this.PreviousSessionId = sessionId; this.PreviousEvents = events; } public void SessionStopped(string viewerId, int sessionId) { Stopped = true; } } public class TestXEventSession : IXEventSession { private string testXEventXml = "" + " " + " " + " " + " 51" + " " + " " + " " + " false" + " " + " " + " " + " 1" + " " + " " + " " + " 4096" + " " + " " + " " + " 0" + " " + " " + " " + " 2" + " " + " " + " " + " 191053000" + " " + " " + " " + " 4680" + " " + " " + " " + " 2000002838f4010000000000" + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " 01" + " " + " " + " " + " " + " " + " " + " " + " 01" + " " + " " + " " + " 56" + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " 930958063" + " " + " " + " " + " " + " " + " " + " " + " A2873402-C433-4D1F-94C4-9CA99749453E-0" + " " + " " + " " + " 770C3538-EC3F-4A27-86A9-31A2FC777DBC-1" + " " + " " + ""; public int Id { get { return 51; } } public void Start(){} public void Stop(){} public string GetTargetXml() { return testXEventXml; } } public class TestXEventSession1 : IXEventSession { private const string testXEventXml_1 = "" + " " + " " + " " + " 1" + " " + " " + " " + " 1" + " " + " " + ""; private const string testXEventXml_2 = "" + " " + " " + " " + " 1" + " " + " " + " " + " 1" + " " + " " + " " + " " + " " + " 1" + " " + " " + " " + " 2" + " " + " " + ""; private const string testXEventXml_3 = "" + " " + " " + " " + " 1" + " " + " " + " " + " 1" + " " + " " + " " + " " + " " + " 1" + " " + " " + " " + " 2" + " " + " " + " " + " " + " " + " 1" + " " + " " + " " + " 3" + " " + " " + ""; public int Id { get { return 1; } } public void Start(){} public void Stop(){} private int pollCount = 0; private string[] poll_returns = { testXEventXml_1, testXEventXml_2, testXEventXml_3 }; public string GetTargetXml() { string res = poll_returns[pollCount]; pollCount++; pollCount = pollCount > 2 ? 0 : pollCount; return res; } } public class TestXEventSession2 : IXEventSession { private const string testXEventXml_1 = "" + " " + " " + " " + " 2" + " " + " " + " " + " 1" + " " + " " + ""; private const string testXEventXml_2 = "" + " " + " " + " " + " 2" + " " + " " + " " + " 1" + " " + " " + " " + " " + " " + " 2" + " " + " " + " " + " 2" + " " + " " + ""; private const string testXEventXml_3 = "" + " " + " " + " " + " 2" + " " + " " + " " + " 1" + " " + " " + " " + " " + " " + " 2" + " " + " " + " " + " 2" + " " + " " + " " + " " + " " + " 2" + " " + " " + " " + " 3" + " " + " " + ""; public int Id { get { return 2; } } public void Start(){} public void Stop(){} private int pollCount = 0; private string[] poll_returns = { testXEventXml_1, testXEventXml_2, testXEventXml_3 }; public string GetTargetXml() { string res = poll_returns[pollCount]; pollCount++; pollCount = pollCount > 2 ? 0 : pollCount; return res; } } public class TestXEventSessionFactory : IXEventSessionFactory { private int sessionNum = 1; public IXEventSession GetXEventSession(string sessionName, ConnectionInfo connInfo) { if(sessionNum == 1) { sessionNum = 2; return new TestXEventSession1(); } else { sessionNum = 1; return new TestXEventSession2(); } } public IXEventSession CreateXEventSession(string createStatement, string sessionName, ConnectionInfo connInfo) { if(sessionNum == 1) { sessionNum = 2; return new TestXEventSession1(); } else { sessionNum = 1; return new TestXEventSession2(); } } } }