public static OperationalMessage?MessageFrom(string content) { if (content.StartsWith(APP)) { return(ApplicationSays.From(content)); } if (content.StartsWith(DIR)) { return(Directory.From(content)); } if (content.StartsWith(ELECT)) { return(Elect.From(content)); } if (content.StartsWith(JOIN)) { return(Join.From(content)); } if (content.StartsWith(LEADER)) { return(Leader.From(content)); } if (content.StartsWith(LEAVE)) { return(Leave.From(content)); } if (content.StartsWith(PING)) { return(Ping.From(content)); } if (content.StartsWith(PULSE)) { return(Pulse.From(content)); } if (content.StartsWith(SPLIT)) { return(Split.From(content)); } if (content.StartsWith(VOTE)) { return(Vote.From(content)); } return(null); }
public void TestGenerateElectMessage() { var elect = new Elect(Id.Of(1)); MessageConverters.MessageToBytes(elect, _messageBuffer); var raw = OperationalMessage.ELECT + "\nid=1"; _expectedBuffer.Write(Converters.TextToBytes(raw)); Assert.Equal(_expectedBuffer.ToArray(), _messageBuffer.ToArray()); Assert.Equal(elect, Elect.From(raw)); }