private void OnFileChangedHandler(object sender, FileSystemEventArgs e) { if (e.Name != _filename) { return; } string newLine = FileHelper.ReadLastLine(_path, _encoding); var message = MessageDataEntity.Parse(newLine); switch (message.Text) { case "Logon": OnUserStatusChanged?.Invoke(new OnUserStatusChangedArgs(message.UserName, true, message.DateTime)); break; case "Logout": OnUserStatusChanged?.Invoke(new OnUserStatusChangedArgs(message.UserName, false, message.DateTime)); break; default: OnMessageReceived?.Invoke(new OnMessageReceivedArgs(new MessageData( message.Id, message.DateTime, message.UserName, message.Text, message.UserName == CurrentUserContext.CurrentUserName, message.ReplyToMessageId))); break; } }
public void Parse_UserNameContainsSymbols_UserNameUnchanged() { string line = "24.08.2011 17:00:47|TIM_!@#$%^> Hello! My name is 'TIM_!@#$%^'"; MessageDataEntity mes = MessageDataEntity.Parse(line); Assert.AreEqual("TIM_!@#$%^", mes.UserName); }
public void Parse_WithoutSpaceAfterDelSym_TextCorrect() { string line = "24.08.2011 17:00:47|TIM>Hello! My name > is '5cc > 62'"; MessageDataEntity mes = MessageDataEntity.Parse(line); Assert.AreEqual("Hello! My name > is '5cc > 62'", mes.Text); Assert.AreEqual("TIM", mes.UserName); }
public void Parse_MessageContainsGtSymb_TextUnchanged() { string line = "24.08.2011 17:00:47|TIM> Hello! My name > is '5cc > 62'"; MessageDataEntity mes = MessageDataEntity.Parse(line); Assert.AreEqual("Hello! My name > is '5cc > 62'", mes.Text); Assert.AreEqual("TIM", mes.UserName); }
public void Parse_ReplyYearNotSpecified(string text, string expReplyId, string expText = null) { string line = "24.08.2011 17:00:47|NAMEORIG> " + text; MessageDataEntity mes = MessageDataEntity.Parse(line); Assert.AreEqual(expReplyId, mes.ReplyToMessageId); Assert.AreEqual(expReplyId == null ? text : expText, mes.Text); }
public void Parse_CleanLine() { string line = "24.08.2011 17:00:47|5cc62> Hello! My name is '5cc62'"; MessageDataEntity mes = MessageDataEntity.Parse(line); Assert.AreEqual(new DateTime(2011, 08, 24, 17, 0, 47), mes.DateTime); Assert.AreEqual("5CC62", mes.UserName); Assert.AreEqual("Hello! My name is '5cc62'", mes.Text); }
public void Parse_UserNameContainsSpaces_UserNameUnchanged() { string line = "24.08.2011 17:00:47|FGHFF GH DFDF> Hello! My name is '???'"; MessageDataEntity mes = MessageDataEntity.Parse(line); Assert.AreEqual(new DateTime(2011, 08, 24, 17, 0, 47), mes.DateTime); Assert.AreEqual("FGHFF GH DFDF", mes.UserName); Assert.AreEqual("Hello! My name is '???'", mes.Text); }
public void Parse_UserNameShort_ExtraSpacesRemoved() { string line = "24.08.2011 17:00:47|VI > Hello! My name is 'Vi'"; MessageDataEntity mes = MessageDataEntity.Parse(line); Assert.AreEqual(new DateTime(2011, 08, 24, 17, 0, 47), mes.DateTime); Assert.AreEqual("VI", mes.UserName); Assert.AreEqual("Hello! My name is 'Vi'", mes.Text); }
public void Parse_HasCleanReply_ReplyNotNull() { string line = "24.08.2011 17:00:47|NAME1 > 23.08.2011 15:01:02|NAME2 > Hello! My name is '5cc62'"; MessageDataEntity mes = MessageDataEntity.Parse(line); Assert.AreEqual(new DateTime(2011, 08, 24, 17, 0, 47), mes.DateTime); Assert.AreEqual("NAME1", mes.UserName); Assert.AreEqual("Hello! My name is '5cc62'", mes.Text); Assert.NotNull(mes.ReplyToMessageId); Assert.AreEqual("23.08.2011 15:01:02|NAME2", mes.ReplyToMessageId); }
public async Task SetUserStatusOffline() { await _repo.SetUserStatus(new UserStatus() { UserId = "User1", IsOnline = false, UpdateDateTime = DateTime.Now }); var lines = File.ReadAllLines(_filename); var m = MessageDataEntity.Parse(lines[0]); Assert.AreEqual(1, lines.Length); Assert.AreEqual("Logout", m.Text); Assert.AreEqual("USER1", m.UserName); }
public async Task <IList <UserStatus> > GetUsersStatuses(CancellationToken token = default) { var res = await Task.Run(() => { var lines = File.ReadAllLines(_filename, _encoding); return(lines .Select(l => MessageDataEntity.Parse(l)) .GroupBy(m => m.UserName) .Select(g => { var mes = g.Last(); return new UserStatus() { UserId = mes.UserName, IsOnline = mes.Text != "Logout", UpdateDateTime = mes.DateTime }; }) .OrderBy(u => u.UserId) .ToArray()); }, token); return(res); }
public void Parse_BadFormatLine_ThrowArgumentNullException(string line) { Assert.Throws <ArgumentNullException>(() => MessageDataEntity.Parse(line)); }
public void Parse_EmptyLine_ThrowArgumentNullException() { Assert.Throws <ArgumentNullException>(() => MessageDataEntity.Parse("")); }