public void EnqueueSend(TcpPackage package) { if (_connection == null) { throw new InvalidOperationException("Failed connection."); } _connection.EnqueueSend(_framer.FrameData(package.AsArraySegment())); }
public void authorized_with_empty_data_should_serialize_and_deserialize_correctly() { var corrId = Guid.NewGuid(); var refPkg = new TcpPackage(TcpCommand.BadRequest, TcpFlags.Authenticated, corrId, "login", "pa$$", new byte[0]); var bytes = refPkg.AsArraySegment(); var pkg = TcpPackage.FromArraySegment(bytes); Assert.AreEqual(TcpCommand.BadRequest, pkg.Command); Assert.AreEqual(TcpFlags.Authenticated, pkg.Flags); Assert.AreEqual(corrId, pkg.CorrelationId); Assert.AreEqual("login", pkg.Login); Assert.AreEqual("pa$$", pkg.Password); Assert.AreEqual(0, pkg.Data.Count); }
public void not_authorized_with_empty_data_should_serialize_and_deserialize_correctly() { var corrId = Guid.NewGuid(); var refPkg = new TcpPackage(TcpCommand.BadRequest, TcpFlags.None, corrId, null, null, new byte[0]); var bytes = refPkg.AsArraySegment(); var pkg = TcpPackage.FromArraySegment(bytes); Assert.AreEqual(TcpCommand.BadRequest, pkg.Command); Assert.AreEqual(TcpFlags.None, pkg.Flags); Assert.AreEqual(corrId, pkg.CorrelationId); Assert.False(pkg.Tokens.TryGetValue("uid", out _)); Assert.False(pkg.Tokens.TryGetValue("pwd", out _)); Assert.False(pkg.Tokens.TryGetValue("jwt", out _)); Assert.AreEqual(0, pkg.Data.Count); }
public void not_authorized_with_data_should_serialize_and_deserialize_correctly() { var corrId = Guid.NewGuid(); var refPkg = new TcpPackage(TcpCommand.BadRequest, TcpFlags.None, corrId, null, null, new byte[] { 1, 2, 3 }); var bytes = refPkg.AsArraySegment(); var pkg = TcpPackage.FromArraySegment(bytes); Assert.AreEqual(TcpCommand.BadRequest, pkg.Command); Assert.AreEqual(TcpFlags.None, pkg.Flags); Assert.AreEqual(corrId, pkg.CorrelationId); Assert.AreEqual(null, pkg.Login); Assert.AreEqual(null, pkg.Password); Assert.AreEqual(3, pkg.Data.Count); Assert.AreEqual(1, pkg.Data.Array[pkg.Data.Offset + 0]); Assert.AreEqual(2, pkg.Data.Array[pkg.Data.Offset + 1]); Assert.AreEqual(3, pkg.Data.Array[pkg.Data.Offset + 2]); }
public void authorized_with_data_should_serialize_and_deserialize_correctly() { var corrId = Guid.NewGuid(); var refPkg = new TcpPackage(TcpCommand.BadRequest, TcpFlags.Authenticated, corrId, "login", "pa$$", new byte[] { 1, 2, 3 }); var bytes = refPkg.AsArraySegment(); var pkg = TcpPackage.FromArraySegment(bytes); Assert.AreEqual(TcpCommand.BadRequest, pkg.Command); Assert.AreEqual(TcpFlags.Authenticated, pkg.Flags); Assert.AreEqual(corrId, pkg.CorrelationId); Assert.AreEqual("login", pkg.Tokens["uid"]); Assert.AreEqual("pa$$", pkg.Tokens["pwd"]); Assert.False(pkg.Tokens.TryGetValue("jwt", out _)); Assert.AreEqual(3, pkg.Data.Count); Assert.AreEqual(1, pkg.Data.Array[pkg.Data.Offset + 0]); Assert.AreEqual(2, pkg.Data.Array[pkg.Data.Offset + 1]); Assert.AreEqual(3, pkg.Data.Array[pkg.Data.Offset + 2]); }