Exemplo n.º 1
0
        public void AddRow_When_Called_Multiple_Times_Adds_Multiple_Rows()
        {
            //Arrange
            var frame = new BasicFrame(Guid.NewGuid());

            TableGenerator.AddColum(frame, typeof(int), 1);
            TableGenerator.AddColum(frame, typeof(double), 1.1);
            TableGenerator.AddColum(frame, typeof(string), "");

            object[] values0 = new object[3];
            values0[0] = 111;
            values0[1] = 11.0;
            values0[2] = "lalala";

            object[] values1 = new object[3];
            values1[0] = 222;
            values1[1] = 12.0;
            values1[2] = "rfrfrf";

            object[] values2 = new object[3];
            values2[0] = 333;
            values2[1] = 13.0;
            values2[2] = "hhhhhhh";

            //Act
            int index0 = frame.AddRow(values0);
            int index1 = frame.AddRow(values1);
            int index2 = frame.AddRow(values2);

            //Assert
            Assert.Equal(3, frame.RowCount);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create a ACK from the specified message
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>Generated ACK frame</returns>
        /// <exception cref="System.ArgumentNullException">request</exception>
        public static IFrame CreateAck(this IFrame request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }
            var frame = new BasicFrame("ACK");

            var trans = request.Headers["transaction"];

            if (trans != null)
            {
                frame.Headers["transaction"] = trans;
            }

            var id = request.Headers["ack"];

            if (id != null)
            {
                frame.Headers["id"] = id;
            }


            var receipt = request.Headers["receipt"];

            if (receipt != null)
            {
                frame.Headers["receipt"] = receipt;
            }

            return(frame);
        }
        public void decode_two_halves_where_the_body_is_partial()
        {
            BasicFrame actual = null;
            var        buffer = new SocketBufferFake();

            buffer.Buffer =
                Encoding.ASCII.GetBytes(
                    "SEND\ndestination:/queue/a\nreceipt:message-12345\ncontent-length:13\n\nhello queue a\0");
            var decoder = new StompDecoder();

            decoder.MessageReceived = o => actual = (BasicFrame)o;

            buffer.BytesTransferred = buffer.Buffer.Length - 10;
            decoder.ProcessReadBytes(buffer);
            buffer.Offset           = buffer.BytesTransferred;
            buffer.BytesTransferred = 10;
            decoder.ProcessReadBytes(buffer);

            actual.Name.Should().Be("SEND");
            actual.Headers.Count.Should().Be(3);
            actual.Body.Should().NotBeNull();
            actual.Body.Length.Should().Be(13);
            actual.Headers["destination"].Should().Be("/queue/a");
            actual.Headers["receipt"].Should().Be("message-12345");
            actual.Headers["content-length"].Should().Be("13");
            var sw = new StreamReader(actual.Body);

            sw.ReadToEnd().Should().Be("hello queue a");
        }
Exemplo n.º 4
0
        public void ack_messages_can_ack_all_since_we_dont_allow_multiple_pending_messages_with_client_individual_ack_type()
        {
            var channel            = Substitute.For <ITcpChannel>();
            var transactionManager = Substitute.For <ITransactionManager>();
            var client             = Substitute.For <IStompClient>();
            var subscription       = new Subscription(client, "abc");

            subscription.AckType = "client";
            var frame1 = new BasicFrame("MESSAGE");

            frame1.AddHeader("message-id", "kdkd1");
            var frame2 = new BasicFrame("MESSAGE");

            frame2.AddHeader("message-id", "kdkd2");
            var frame3 = new BasicFrame("MESSAGE");

            frame3.AddHeader("message-id", "kdkd3");
            subscription.Send(frame1);
            subscription.Send(frame2);
            subscription.Send(frame3);

            var sut = new StompClient(channel, transactionManager);

            sut.AddSubscription(subscription);
            sut.AckMessages("kdkd2");
            var actual1 = sut.IsFramePending("kdkd1");
            var actual2 = sut.IsFramePending("kdkd2");
            var actual3 = sut.IsFramePending("kdkd3");

            actual1.Should().BeFalse();
            actual2.Should().BeFalse();
            actual3.Should().BeTrue();
        }
Exemplo n.º 5
0
        public static IFrame CreateNack(this IFrame request, string errorDescription)
        {
            var frame = new BasicFrame("NACK");

            var trans = request.Headers["transaction"];

            if (trans != null)
            {
                frame.Headers["transaction"] = trans;
            }

            var id = request.Headers["ack"];

            if (id != null)
            {
                frame.Headers["id"] = id;
            }


            var receipt = request.Headers["receipt"];

            if (receipt != null)
            {
                frame.Headers["receipt"] = receipt;
            }

            return(frame);
        }
        public void using_authentication()
        {
            var authService = Substitute.For <IAuthenticationService>();

            authService.IsActivated.Returns(true);
            authService.Login("hello", "world").Returns(new LoginResponse()
            {
                IsSuccessful = true, Token = "mamma"
            });
            var frame  = new BasicFrame("STOMP");
            var client = Substitute.For <IStompClient>();

            frame.Headers["accept-version"] = "2.0";
            frame.Headers["login"]          = "******";
            frame.Headers["passcode"]       = "world";
            client.SessionKey.Returns(Guid.NewGuid().ToString());

            var sut    = new ConnectHandler(authService, "Kickass");
            var actual = sut.Process(client, frame);

            actual.Should().NotBeNull();
            actual.Headers["version"].Should().Be("2.0");
            actual.Headers["server"].Should().Be("Kickass");
            actual.Headers["session"].Should().NotBeNull();
            client.ReceivedWithAnyArgs().SetAsAuthenticated("mamma");
        }
Exemplo n.º 7
0
        public void do_not_create_receipt_if_the_header_is_missing()
        {
            var frame = new BasicFrame("SEND");

            var response = frame.CreateReceiptIfRequired();

            response.Should().BeNull();
        }
Exemplo n.º 8
0
        public static ValueTask <FlushResult> WriteFrame(PipeWriter writer, BasicFrame frame)
        {
            var memory = writer.GetMemory(8);

            BinaryPrimitives.WriteInt32LittleEndian(memory.Span, frame.MessageId);
            BinaryPrimitives.WriteInt32LittleEndian(memory.Span.Slice(4), frame.Payload.Memory.Length);
            writer.Advance(8);
            return(writer.WriteAsync(frame.Payload.Memory));
        }
Exemplo n.º 9
0
        public void transaction_must_be_specified()
        {
            var frame  = new BasicFrame("COMMIT");
            var client = Substitute.For <IStompClient>();

            var    sut    = new CommitHandler();
            Action actual = () => sut.Process(client, frame);

            actual.ShouldThrow <BadRequestException>();
        }
Exemplo n.º 10
0
        public void cant_abort_without_transaction_identifier()
        {
            var frame  = new BasicFrame("ABORT");
            var client = Substitute.For <IStompClient>();

            var    sut    = new AbortHandler();
            Action actual = () => sut.Process(client, frame);

            actual.ShouldThrow <BadRequestException>();
        }
Exemplo n.º 11
0
        public void cant_ack_without_message_id()
        {
            var frame  = new BasicFrame("ACK");
            var client = Substitute.For <IStompClient>();

            var    sut    = new AckHandler();
            Action actual = () => sut.Process(client, frame);

            actual.ShouldThrow <BadRequestException>();
        }
Exemplo n.º 12
0
        public void create_receipt_with_correct_id()
        {
            var frame = new BasicFrame("SEND");

            frame.Headers["receipt"] = "1";

            var response = frame.CreateReceiptIfRequired();

            response.Should().NotBeNull();
            response.Headers["receipt-id"] = "1";
        }
Exemplo n.º 13
0
        public void subscription_id_must_be_specified_according_to_the_specification()
        {
            var repos  = Substitute.For <IQueueRepository>();
            var client = Substitute.For <IStompClient>();
            var msg    = new BasicFrame("SUBSCRIBE");

            var    sut    = new SubscribeHandler(repos);
            Action actual = () => sut.Process(client, msg);

            actual.ShouldThrow <BadRequestException>();
        }
Exemplo n.º 14
0
        public void id_is_required()
        {
            var repos  = Substitute.For <IQueueRepository>();
            var client = Substitute.For <IStompClient>();
            var msg    = new BasicFrame("UNSUBSCRIBE");

            var    sut    = new UnsubscribeHandler(repos);
            Action actual = () => sut.Process(client, msg);

            actual.ShouldThrow <BadRequestException>();
        }
Exemplo n.º 15
0
        public void destination_is_required_according_to_the_specification()
        {
            var repos  = Substitute.For <IQueueRepository>();
            var client = Substitute.For <IStompClient>();
            var msg    = new BasicFrame("SEND");

            var    handler = new SendHandler(repos);
            Action actual  = () => handler.Process(client, msg);

            actual.ShouldThrow <BadRequestException>();
        }
Exemplo n.º 16
0
        public void send_message_directly()
        {
            var channel            = Substitute.For <ITcpChannel>();
            var transactionManager = Substitute.For <ITransactionManager>();
            var frame = new BasicFrame("SEND");

            var sut = new StompClient(channel, transactionManager);

            sut.Send(frame);

            channel.Received().Send(frame);
        }
Exemplo n.º 17
0
        public void successful_subcribe()
        {
            var repos  = Substitute.For <IQueueRepository>();
            var client = Substitute.For <IStompClient>();
            var msg    = new BasicFrame("SUBSCRIBE");

            msg.Headers["id"]          = "123";
            msg.Headers["destination"] = "/queue/mamma";
            repos.Get("/queue/mamma").Returns(new StompQueue());

            var sut    = new SubscribeHandler(repos);
            var actual = sut.Process(client, msg);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Check if the
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public static IFrame CreateReceiptIfRequired(this IFrame request)
        {
            var receipt = request.Headers["receipt"];

            if (receipt != null)
            {
                var response = new BasicFrame("RECEIPT");
                response.Headers["receipt-id"] = receipt;
                return(response);
            }

            return(null);
        }
Exemplo n.º 19
0
        public void abort_if_transaction_was_specified()
        {
            var frame = new BasicFrame("ABORT");

            frame.Headers["transaction"] = "aa";
            var client = Substitute.For <IStompClient>();

            var sut = new AbortHandler();

            sut.Process(client, frame);

            client.Received().RollbackTransaction("aa");
        }
        public void version_is_required_according_to_the_specification()
        {
            var authService = Substitute.For <IAuthenticationService>();
            var frame       = new BasicFrame("STOMP");
            var client      = Substitute.For <IStompClient>();

            var sut    = new ConnectHandler(authService, "Kickass");
            var actual = sut.Process(client, frame);

            actual.Should().NotBeNull();
            actual.Headers["version"].Should().Be("2.0");
            actual.Headers["message"].Should().Be("Missing the 'accept-version' header.");
        }
Exemplo n.º 21
0
        public void succeed_if_transaction_was_specified()
        {
            var frame = new BasicFrame("COMMIT");

            frame.Headers["transaction"] = "aa";
            var client = Substitute.For <IStompClient>();

            var sut = new CommitHandler();

            sut.Process(client, frame);

            client.Received().CommitTransaction("aa");
        }
Exemplo n.º 22
0
        public void subscription_must_exist()
        {
            var repos  = Substitute.For <IQueueRepository>();
            var client = Substitute.For <IStompClient>();
            var msg    = new BasicFrame("UNSUBSCRIBE");

            msg.Headers["id"] = "1";

            var    sut    = new UnsubscribeHandler(repos);
            Action actual = () => sut.Process(client, msg);

            actual.ShouldThrow <BadRequestException>();
        }
Exemplo n.º 23
0
        public void cant_nack_if_message_Was_not_found()
        {
            var frame  = new BasicFrame("NACK");
            var repos  = Substitute.For <IQueueRepository>();
            var client = Substitute.For <IStompClient>();

            frame.Headers["id"] = "aa";
            client.IsFramePending("aa").Returns(false);

            var    sut    = new NackHandler(repos);
            Action actual = () => sut.Process(client, frame);

            actual.ShouldThrow <BadRequestException>();
        }
Exemplo n.º 24
0
        public void get_existent_subscription()
        {
            var client       = Substitute.For <IStompClient>();
            var subscription = new Subscription(client, "abc");
            var frame        = new BasicFrame("MESSAGE");

            frame.AddHeader("message-id", "kdkd");
            subscription.AckType = "client-individual";
            subscription.Send(frame);

            var actual = subscription.IsMessagePending("kdkd");

            actual.Should().BeTrue();
        }
Exemplo n.º 25
0
        public void Test()
        {
            var repos  = Substitute.For <IQueueRepository>();
            var client = Substitute.For <IStompClient>();
            var msg    = new BasicFrame("UNSUBSCRIBE");

            msg.Headers["id"] = "1";
            client.RemoveSubscription("1").Returns(new Subscription(client, "1"));

            var sut    = new UnsubscribeHandler(repos);
            var actual = sut.Process(client, msg);

            actual.Should().BeNull();
        }
Exemplo n.º 26
0
        public void may_not_subscribe_on_previously_created_subscription()
        {
            var repos  = Substitute.For <IQueueRepository>();
            var client = Substitute.For <IStompClient>();
            var msg    = new BasicFrame("SUBSCRIBE");

            msg.Headers["id"] = "123";
            client.SubscriptionExists("123").Returns(true);

            var    sut    = new SubscribeHandler(repos);
            Action actual = () => sut.Process(client, msg);

            actual.ShouldThrow <BadRequestException>();
        }
Exemplo n.º 27
0
        public void message_in_its_simplest_form()
        {
            var frame    = new BasicFrame("STOMP");
            var expected = "STOMP\n\n\0";
            var buffer   = new SocketBufferFake();

            var encoder = new StompEncoder();

            encoder.Prepare(frame);
            encoder.Send(buffer);
            var actual = Encoding.ASCII.GetString(buffer.Buffer, 0, buffer.Count);

            actual.Should().Be(expected);
        }
Exemplo n.º 28
0
        public void NoOp_message()
        {
            var frame    = new BasicFrame("NoOp");
            var expected = "\n";
            var buffer   = new SocketBufferFake();

            var encoder = new StompEncoder();

            encoder.Prepare(frame);
            encoder.Send(buffer);
            var actual = Encoding.ASCII.GetString(buffer.Buffer, 0, buffer.Count);

            actual.Should().Be(expected);
        }
Exemplo n.º 29
0
        public void content_length_is_required_if_a_body_is_present()
        {
            var repos  = Substitute.For <IQueueRepository>();
            var client = Substitute.For <IStompClient>();
            var msg    = new BasicFrame("SEND");

            msg.Headers["destination"]  = "/queue/momas";
            msg.Headers["content-type"] = "text/plain";
            msg.Body = new MemoryStream();

            var    handler = new SendHandler(repos);
            Action actual  = () => handler.Process(client, msg);

            actual.ShouldThrow <BadRequestException>();
        }
Exemplo n.º 30
0
        public void enlist_transaction_messages()
        {
            var repos  = Substitute.For <IQueueRepository>();
            var client = Substitute.For <IStompClient>();
            var msg    = new BasicFrame("SEND");

            msg.Headers["destination"] = "/queue/momas";
            msg.Headers["transaction"] = "10";

            var handler = new SendHandler(repos);
            var actual  = handler.Process(client, msg);

            actual.Should().BeNull();
            client.Received().EnqueueInTransaction("10", Arg.Any <Action>(), Arg.Any <Action>());
        }
        public void only_accepting_20_clients()
        {
            var authService = Substitute.For <IAuthenticationService>();
            var frame       = new BasicFrame("STOMP");
            var client      = Substitute.For <IStompClient>();

            frame.Headers["accept-version"] = "1.1";

            var sut    = new ConnectHandler(authService, "Kickass");
            var actual = sut.Process(client, frame);

            actual.Should().NotBeNull();
            actual.Headers["version"].Should().Be("2.0");
            actual.Headers["message"].Should().Be("Only accepting stomp 2.0 clients.");
        }
Exemplo n.º 32
0
        public void AddRow_WithIncorrectDataTypes_Adds_A_New_Row_With_Implicit_Casting()
        {
            //Arrange
            var frame = new BasicFrame(Guid.NewGuid());

            TableGenerator.AddColum(frame, typeof(int), 1);
            TableGenerator.AddColum(frame, typeof(double), 1.1);
            TableGenerator.AddColum(frame, typeof(string), "");

            object[] values = new object[3];
            values[0] = 33.0;
            values[1] = 13;
            values[2] = "lalala";

            //Act
            frame.AddRow(values);

            //Assert
            Assert.Equal(1, frame.RowCount);
        }
Exemplo n.º 33
0
        public void ColumnCount_Returns_Number_Of_Columns()
        {
            //Arrange
            var frame = new BasicFrame(Guid.NewGuid());

            //Act
            TableGenerator.AddColum(frame, TestConstants.COL_0_NAME, typeof(int));

            //Assert
            Assert.Equal(1, frame.ColumnCount);
        }
Exemplo n.º 34
0
        public void ColumnNames_Returns_Array_With_Column_Names()
        {
            //Arrange
            var frame = new BasicFrame(Guid.NewGuid());
            Type t0 = typeof(int);
            Type t1 = typeof(double);
            Type t2 = typeof(string);

            DataColumn c0 = TableGenerator.AddColum(frame, typeof(int), 1);
            DataColumn c1 = TableGenerator.AddColum(frame, typeof(double), 1.1);
            DataColumn c2 = TableGenerator.AddColum(frame, typeof(string), "");

            //Act
            string[] names = frame.ColumnNames;

            //Assert
            Assert.NotNull(names);

            Assert.Equal(c0.ColumnName, names[0]);
            Assert.Equal(c1.ColumnName, names[1]);
            Assert.Equal(c2.ColumnName, names[2]);
        }
Exemplo n.º 35
0
        public void AddRow_With_Incorrect_Input_Array_Length_Adds_Default_Values_For_Empty_Columns()
        {
            //Arrange
            var frame = new BasicFrame(Guid.NewGuid());

            TableGenerator.AddColum(frame, typeof(int), 1);
            TableGenerator.AddColum(frame, typeof(double), 1.1);
            TableGenerator.AddColum(frame, typeof(string), "");

            object[] values = new object[3];
            values[0] = 33.0;
            values[1] = 13;

            //Act
            frame.AddRow(values);

            //Assert
            Assert.Equal(1, frame.RowCount);
        }
Exemplo n.º 36
0
        public void ColumnTypes_Returns_Array_Of_Types_Of_Column_Data()
        {
            //Arrange
            var frame = new BasicFrame(Guid.NewGuid());
            Type t0 = typeof(int);
            Type t1 = typeof(double);
            Type t2 = typeof(string);

            TableGenerator.AddColum(frame, typeof(int), 1);
            TableGenerator.AddColum(frame, typeof(double), 1.1);
            TableGenerator.AddColum(frame, typeof(string), "");

            //Act
            Type[] types = frame.ColumnTypes;

            //Assert
            Assert.NotNull(types);
            Assert.Equal(t0, types[0]);
            Assert.Equal(t1, types[1]);
            Assert.Equal(t2, types[2]);
        }
Exemplo n.º 37
0
        public void Ctor_Assigns_Default_Values()
        {
            //Arrange
            BasicFrame frame = null;

            //Act
            frame = new BasicFrame(Guid.NewGuid());

            //Assert
            Assert.Equal(0, frame.ColumnCount);
            Assert.Equal(0, frame.RowCount);
        }
Exemplo n.º 38
0
        public void RemoveRow_Removes_The_Row_At_The_Specified_Row_Index()
        {
            //Arrange
            var frame = new BasicFrame(Guid.NewGuid());

            TableGenerator.AddColum(frame, typeof(int), 1);
            TableGenerator.AddColum(frame, typeof(double), 1.1);
            TableGenerator.AddColum(frame, typeof(string), "");

            object[] values0 = new object[3];
            values0[0] = 111;
            values0[1] = 11.0;
            values0[2] = "lalala";

            object[] values1 = new object[3];
            values1[0] = 222;
            values1[1] = 12.0;
            values1[2] = "rfrfrf";

            object[] values2 = new object[3];
            values2[0] = 333;
            values2[1] = 13.0;
            values2[2] = "hhhhhhh";

            int index0 = frame.AddRow(values0);
            int index1 = frame.AddRow(values1);
            int index2 = frame.AddRow(values2);

            //Act
            frame.Rows.RemoveAt(index1);

            //Assert
            Assert.Equal(2, frame.RowCount);
        }
Exemplo n.º 39
0
        public void Name_Property_Sets_Name()
        {
            //Arrange
            var frame = new BasicFrame(Guid.NewGuid());
            string name = "blah";

            //Act
            frame.Name = name;

            //Assert
            Assert.Equal(name, frame.Name);
        }
Exemplo n.º 40
0
        public void Id_Property_Sets_Id()
        {
            //Arrange
            var frame = new BasicFrame(Guid.NewGuid());
            Guid id = Guid.NewGuid();

            //Act
            frame.Id = id;

            //Assert
            Assert.Equal(id, frame.Id);
        }
Exemplo n.º 41
0
        public void IndexOf_Returns_Zero_Based_Index_Of_Column()
        {
            //Arrange
            var frame = new BasicFrame(Guid.NewGuid());
            DataColumn c0 = TableGenerator.AddColum(frame, typeof(int), 1);
            DataColumn c1 = TableGenerator.AddColum(frame, typeof(double), 1.1);
            DataColumn c2 = TableGenerator.AddColum(frame, typeof(string), "");
            int i0, i1, i2;

            //Act
            i0 = frame.Columns.IndexOf(c0);
            i1 = frame.Columns.IndexOf(c1);
            i2 = frame.Columns.IndexOf(c2);

            //Assert
            Assert.Equal(0, i0);
            Assert.Equal(1, i1);
            Assert.Equal(2, i2);
        }