public virtual void TestGetting() { var startDate = DateTime.UtcNow; Thread.Sleep(2000); CodeSession cs = new CodeSession() { Owner = User }; var id = cs.Id; this.codeSessionsRepository.CreateNewSession(cs); var result = this.codeSessionsRepository.GetSessionById(User, id); Assert.IsNotNull(result); Assert.AreEqual(result.CodeSession.Id, id); CodeSession cs2 = new CodeSession() { Owner = User }; this.codeSessionsRepository.CreateNewSession(cs2); var result2 = this.codeSessionsRepository.GetAllSessionsByDateRange(startDate, DateTime.UtcNow); Assert.AreEqual(result2.Count(), 2); }
public override void TestGetting() { var startDate = DateTime.UtcNow; Thread.Sleep(2000); CodeSession cs = new CodeSession() { Owner = User }; var id = cs.Id; this.codeSessionsRepository.CreateNewSession(cs); this.mockProvider.Setup(m => m.GetCodeSession(id)).Throws(new InvalidOperationException()); var result = this.codeSessionsRepository.GetSessionById(User, id); Assert.IsNotNull(result); Assert.AreEqual(result.CodeSession.Id, id); CodeSession cs2 = new CodeSession() { Owner = User }; this.codeSessionsRepository.CreateNewSession(cs2); var result2 = this.codeSessionsRepository.GetAllSessionsByDateRange(startDate, DateTime.UtcNow); Assert.AreEqual(result2.Count(), 2); }
public void CreateNewSession(CodeSession codeSession) { codeSessions.Add(codeSession.Id, codeSession); try { this.persistentStorageProvider.AddCodeSession(codeSession); } catch (Exception ex) { this.logger.LogError(ex, "creating new session {id} failed", codeSession.Id); } }
public virtual void TestAdding() { var startCount = this.codeSessionsRepository.GetUserOwnedSessions(User).Count(); CodeSession cs = new CodeSession() { Owner = User }; var id = cs.Id; this.codeSessionsRepository.CreateNewSession(cs); var result = this.codeSessionsRepository.GetUserOwnedSessions(User); Assert.AreEqual(startCount + 1, result.Count()); Assert.AreEqual(id, result.First().Id); }
public IEnumerable <CodeSession> GetCodeSessions() { string readerAll = "SELECT * FROM CodeSessions"; List <CodeSession> result = new List <CodeSession>(); using (var connection = new SqlConnection(this.connectionString)) { try { SqlCommand command = new SqlCommand(readerAll, connection); connection.Open(); var reader = command.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { var cs = new CodeSession() { Id = reader.GetString(0), DateCreated = reader.GetDateTime(1), Code = reader.GetString(2), CodeSyntax = reader.GetString(3), CodeHighlights = JsonConvert.DeserializeObject <IList <CodeCursor> >(reader.GetString(4)), Owner = reader.GetString(5), UserInControl = reader.GetString(6), Participants = JsonConvert.DeserializeObject <IList <string> >(reader.GetString(7)) }; result.Add(cs); } reader.Close(); } return(result); } catch (Exception e) { this.logger.LogError(e, "Sql error on getting code sessions"); return(Enumerable.Empty <CodeSession>()); } } }
public virtual void TestRemoving() { var startStateCount = this.codeSessionsRepository.GetUserOwnedSessions(User).Count(); CodeSession cs = new CodeSession() { Owner = User }; var id = cs.Id; this.codeSessionsRepository.CreateNewSession(cs); var removeOp = this.codeSessionsRepository.RemoveSession(User, id); var currentState = this.codeSessionsRepository.GetUserOwnedSessions(User); Assert.AreEqual(true, removeOp); Assert.AreEqual(startStateCount, currentState.Count()); }
public override void TestAdding() { var startCount = this.codeSessionsRepository.GetUserOwnedSessions(User).Count(); CodeSession cs = new CodeSession() { Owner = User }; var id = cs.Id; this.mockProvider.Setup(m => m.AddCodeSession(cs)).Throws(new InvalidOperationException()); this.codeSessionsRepository.CreateNewSession(cs); var result = this.codeSessionsRepository.GetUserOwnedSessions(User); Assert.AreEqual(startCount + 1, result.Count()); Assert.AreEqual(id, result.First().Id); }
public bool AddCodeSession(CodeSession codeSession) { string insertNewCodeSession = "INSERT INTO CodeSessions (Id, DateCreated, Code, CodeSyntax, CodeHighlights, Owner, UserInControl, Participants)" + " VALUES (@Id, @DateCreated, @Code, @CodeSyntax, @CodeHighlights, @Owner, @UserInControl, @Participants)"; using (var connection = new SqlConnection(this.connectionString)) { try { SqlCommand command = new SqlCommand(insertNewCodeSession, connection); command.Parameters.Add("@Id", System.Data.SqlDbType.NVarChar, 20); command.Parameters.Add("@DateCreated", System.Data.SqlDbType.DateTime2, 7); command.Parameters.Add("@Code", System.Data.SqlDbType.NVarChar, -1); command.Parameters.Add("@CodeSyntax", System.Data.SqlDbType.NVarChar, 100); command.Parameters.Add("@CodeHighlights", System.Data.SqlDbType.NVarChar, -1); command.Parameters.Add("@Owner", System.Data.SqlDbType.NVarChar, 100); command.Parameters.Add("@UserInControl", System.Data.SqlDbType.NVarChar, 100); command.Parameters.Add("@Participants", System.Data.SqlDbType.NVarChar, -1); // Add the parameter values. Validation should have already happened. command.Parameters["@Id"].Value = codeSession.Id; command.Parameters["@DateCreated"].Value = codeSession.DateCreated; command.Parameters["@Code"].Value = codeSession.Code; command.Parameters["@CodeSyntax"].Value = codeSession.CodeSyntax; command.Parameters["@CodeHighlights"].Value = JsonConvert.SerializeObject(codeSession.CodeHighlights); command.Parameters["@Owner"].Value = codeSession.Owner; command.Parameters["@UserInControl"].Value = codeSession.UserInControl; command.Parameters["@Participants"].Value = JsonConvert.SerializeObject(codeSession.Participants); connection.Open(); command.ExecuteNonQuery(); return(true); } catch (Exception e) { this.logger.LogError(e, "Sql error on adding code session {Id} for user {Owner}", codeSession.Id, codeSession.Owner); return(false); } } }
public override void TestRemoving() { var startStateCount = this.codeSessionsRepository.GetUserOwnedSessions(User).Count(); CodeSession cs = new CodeSession() { Owner = User }; var id = cs.Id; this.codeSessionsRepository.CreateNewSession(cs); this.mockProvider.Setup(m => m.RemoveCodeSession(id)).Throws(new InvalidOperationException()); var removeOp = this.codeSessionsRepository.RemoveSession(User, id); var currentState = this.codeSessionsRepository.GetUserOwnedSessions(User); Assert.AreEqual(false, removeOp); Assert.AreEqual(startStateCount, currentState.Count()); }
public ActionResult <CodeSession> Post(CodeSession codeSession) { string user = this.userRepository.GetCurrentUserId(); if (string.IsNullOrEmpty(user)) { return(new StatusCodeResult(500)); } CodeSession newCodeSession = new CodeSession() { Code = codeSession == null ? string.Empty : codeSession.Code, DateCreated = codeSession == null ? DateTime.UtcNow : codeSession.DateCreated, Owner = user, UserInControl = user, Participants = new List <string>(new string[] { user }) }; this.codeSessionsRepository.CreateNewSession(newCodeSession); return(new ActionResult <CodeSession>(newCodeSession)); }
public static void Main(string[] args) { //This class provides the handling of the output log messages var monitor = new ConsoleMonitor(); //Our HAP session manages our runner, this step only adds our prefered monitor var session = new CodeSession(monitor); var message = new ExtensionActivated(); session.MessageDelegates.Add(message); var command = new SayHelloCommand("extension.sayHello"); session.MessageDelegates.Add(command); var xamlCompletionItemProvider = new XamlCompletionItemProvider("completion"); session.MessageDelegates.Add(xamlCompletionItemProvider); session.Start(); Console.ReadKey(); }
static void Initialize(CodeSession session) { _session = session; }
public virtual void TestUpdate() { const string Old = "Hello World!"; const string New = "Nope"; CodeSession cs = new CodeSession() { Owner = User, Code = Old }; var id = cs.Id; this.codeSessionsRepository.CreateNewSession(cs); // update code text this.codeSessionsRepository.UpdateSession(User, id, New); var result = this.codeSessionsRepository.GetUserOwnedSessions(User); var onlySession = result.First(s => s.Id == id); Assert.AreEqual(New, onlySession.Code); // update highlight var highlightOne = new CodeCursor() { HighlightFrom = new CodeCursor.CursorPoint() { Ch = 0, Line = 0 }, HighlightTo = new CodeCursor.CursorPoint() { Ch = 2, Line = 0 } }; this.codeSessionsRepository.UpdateSession(User, id, highlightOne); result = this.codeSessionsRepository.GetUserOwnedSessions(User); onlySession = result.First(s => s.Id == id); Assert.AreEqual(1, onlySession.CodeHighlights.Count); Assert.AreEqual(2, onlySession.CodeHighlights.First().HighlightTo.Ch); // update highlight erase this.codeSessionsRepository.UpdateSessionEraseHighlights(User, id); result = this.codeSessionsRepository.GetUserOwnedSessions(User); onlySession = result.First(s => s.Id == id); Assert.AreEqual(0, onlySession.CodeHighlights.Count); // update syntax const string NewSyntax = "nothing"; this.codeSessionsRepository.UpdateSessionSyntax(User, id, NewSyntax); result = this.codeSessionsRepository.GetUserOwnedSessions(User); onlySession = result.First(s => s.Id == id); Assert.AreEqual(NewSyntax, onlySession.CodeSyntax); // update user in control const string NewUser = "******"; this.codeSessionsRepository.UpdateSessionUserInControl(User, id, NewUser); result = this.codeSessionsRepository.GetUserOwnedSessions(User); onlySession = result.First(s => s.Id == id); Assert.AreEqual(NewUser, onlySession.UserInControl); Assert.AreEqual(User, onlySession.Owner); }
public void CreateNewSession(CodeSession codeSession) { this.codeSessions.Add(codeSession); }