Beispiel #1
0
        public async Task Can_forward_headers()
        {
            var spy = new OutboxEntryRepositorySpy();

            var sut = A.OutboxQueue
                      .With(
                A.OutgoingMessageRegistry
                .Register <Message>("foo", "bar", @event => "baz")
                .Build()
                )
                      .With(spy)
                      .Build();

            var metadata = new Metadata()
            {
                MessageId     = "183388b5-a8e9-4cb4-b553-6699632461c7",
                CausationId   = "183388b5-a8e9-4cb4-b553-6699632461c7",
                CorrelationId = "183388b5-a8e9-4cb4-b553-6699632461c7"
            };

            await sut.Enqueue(new[] { new Message() }, metadata);

            var expected = @"{
                            ""messageId"":""183388b5-a8e9-4cb4-b553-6699632461c7"",
                            ""type"":""bar"",
                            ""causationId"":""183388b5-a8e9-4cb4-b553-6699632461c7"",
                            ""correlationId"":""183388b5-a8e9-4cb4-b553-6699632461c7"",
                            ""data"":{
                                }
                            }";


            AssertJson.Equal(expected, spy.OutboxEntries[0].Payload);
        }
Beispiel #2
0
        public async Task produces_expected_message_without_headers_using_default_serializer()
        {
            var spy = new KafkaProducerSpy();

            var sut = A.Producer
                      .With(spy)
                      .With(new MessageIdGeneratorStub(() => "1"))
                      .With(A.OutgoingMessageRegistry
                            .Register <Message>("foo", "bar", @event => @event.Id)
                            .Build()
                            )
                      .Build();

            await sut.Produce(
                message : new Message {
                Id = "dummyId"
            },
                headers : new Dictionary <string, object>
            {
            }
                );

            var expected = @"{
                                ""messageId"":""1"",
                                ""type"":""bar"",
                                ""causationId"":""1"",
                                ""correlationId"":""1"",
                                ""data"":{
                                    ""id"":""dummyId""
                                    }
                                }";

            AssertJson.Equal(expected, spy.Value);
        }
        public async Task Can_create_outgoing_message_from_registry_with_expected_raw_message()
        {
            const string dummyMessageId   = "foo_id";
            const string dummyAggregateId = "dummyId";

            var spy = new KafkaProducerSpy();
            var sut = A.Producer
                      .With(spy)
                      .With(A.OutgoingMessageRegistry
                            .Register <DummyMessage>(DummyTopic, DummyType, x => x.AggregateId)
                            .Build()
                            )
                      .With(new MessageIdGeneratorStub(() => dummyMessageId))
                      .Build();

            await sut.Produce(new DummyMessage(dummyAggregateId));

            var expected = $@"{{
                                ""messageId"":""{dummyMessageId}"",
                                ""type"":""{DummyType}"",
                                ""causationId"":""foo_id"",
                                ""correlationId"":""foo_id"",
                                ""data"":{{
                                    ""aggregateId"":""{dummyAggregateId}""
                                    }}
                                }}";

            AssertJson.Equal(expected, spy.Value);
        }
        public void AreEquals_NestedArrays_Fail()
        {
            const string expectedObject     = "{prop1:'value1', arr:[1, '2', {key: 'value'}]}";
            const string actualObject       = "{prop1:'value1', arr:[1, '3', {key: 'value'}]}";
            var          assertionException =
                Assert.Throws <AssertionException>(() => AssertJson.AreEquals(expectedObject, actualObject));

            Assert.IsTrue(
                assertionException.Message.StartsWith(string.Format("  Property \"{0}\" does not match.", "arr[1]")));
        }
        public void AreEquals_NestedObjects_Fail()
        {
            const string expectedObject     = "{prop1:'value1', nested0:{}, nested: {key:'value'}}";
            const string actualObject       = "{prop1:'value1', nested0:{}, nested: {key:'value2'}}";
            var          assertionException =
                Assert.Throws <AssertionException>(() => AssertJson.AreEquals(expectedObject, actualObject));

            Assert.IsTrue(
                assertionException.Message.StartsWith(string.Format("  Property \"{0}\" does not match.", "nested.key")));
        }
        public void AreEquals_ExcessProperty_Fail()
        {
            const string expectedObject     = "{name:'value'}";
            const string actualObject       = "{name:'value', excess:'yes'}";
            var          assertionException =
                Assert.Throws <AssertionException>(() => AssertJson.AreEquals(expectedObject, actualObject));

            Assert.AreEqual(assertionException.Message,
                            string.Format("Object  has excess properties: excess"));
        }
        public void AreEquals_NestedArraysDifferentLength_Fail()
        {
            const string expectedObject     = "{prop1:'value1', arr:[1, '2', {key: 'value'}, 5]}";
            const string actualObject       = "{prop1:'value1', arr:[1, '3', {key: 'value'}]}";
            var          assertionException =
                Assert.Throws <AssertionException>(() => AssertJson.AreEquals(expectedObject, actualObject));

            Assert.AreEqual(
                string.Format("Different arrays length at {0}. Expected: {1}, but was: {2}", "arr", "4", "3"),
                assertionException.Message);
        }
        public void AreEquals_UnequalIntPropertyValues_Fail()
        {
            const string expectedObject = "{prop1:'value1', int:15}";
            const string actualObject   = "{prop1:'value1', int:16}";

            var assertionException =
                Assert.Throws <AssertionException>(() => AssertJson.AreEquals(expectedObject, actualObject));

            Assert.IsTrue(
                assertionException.Message.StartsWith(string.Format("  Property \"{0}\" does not match.", "int")));
        }
        public void AreEquals_ComplexJson_Fail()
        {
            const string expectedObject =
                "{\"array\":[1,2,3],\"boolean\":true,\"null\":null,\"number\":123,\"object\":{\"a\":\"b\",\"c\":\"d\",\"e\":\"f\",\"test\":{\"arr\":[{\"key\":{\"diff\":\"val\"}},{}]},\"name\":\"value\"},\"string\":\"Hello World\"}";
            const string actualObject =
                "{\"array\":[1,2,3],\"boolean\":true,\"null\":null,\"number\":123,\"object\":{\"a\":\"b\",\"c\":\"d\",\"e\":\"f\",\"test\":{\"arr\":[{\"key\":{\"diff\":\"val2\"}},{}]},\"name\":\"value\"},\"string\":\"Hello World\"}";
            var assertionException =
                Assert.Throws <AssertionException>(() => AssertJson.AreEquals(expectedObject, actualObject));

            Assert.IsTrue(
                assertionException.Message.StartsWith(string.Format("  Property \"{0}\" does not match.",
                                                                    "object.test.arr[0].key.diff")));
        }
Beispiel #10
0
        public async Task GetReturnedValuesToBeCreated()
        {
            OutputScenarioText();

            var jsonBody = await When.GetResponse.Content.ReadAsStringAsync();

            var responseModels = AssertJson.Valid <ValueJsonModel[]>(jsonBody);

            Assert.Equal(Given.ValuesToBeCreated.Count, responseModels.Length);
            foreach (var valueToBeCreated in Given.ValuesToBeCreated)
            {
                Assert.Single(responseModels, r => r.Value == valueToBeCreated);
            }
        }
Beispiel #11
0
        public async Task returns_expected_serialized_value_of_simple_payload_without_headers()
        {
            var sut = new DefaultPayloadSerializer();

            var messageDataStub = "foo-message-data";

            var payloadStub = new PayloadDescriptorBuilder()
                              .WithMessageData(messageDataStub)
                              .Build();

            AssertJson.Equal(
                expected: $@"
                            {{
                                ""messageId"":""{payloadStub.MessageId}"",
                                ""type"":""{payloadStub.MessageType}"",
                                ""data"":""{messageDataStub}""
                            }}",
                actual: await sut.Serialize(payloadStub)
                );
        }
Beispiel #12
0
        public async Task produces_message_using_message_handler_context()
        {
            var spy = new KafkaProducerSpy();

            var sut = A.Producer
                      .With(spy)
                      .With(new MessageIdGeneratorStub(() => "1"))
                      .With(A.OutgoingMessageRegistry
                            .Register <Message>("foo", "bar", @event => @event.Id)
                            .Build()
                            )
                      .Build();

            await sut.Produce(
                message : new Message {
                Id = "0"
            },
                context : new MessageHandlerContext(new Metadata
            {
                CausationId   = "my-causation",
                CorrelationId = "my-correlation"
            })
                );


            var expected = @"
                            {
                            ""messageId"":""1"",
                            ""type"":""bar"",
                            ""correlationId"":""my-correlation"",
                            ""causationId"":""1"",
                            ""data"":{
                                ""id"":""0""
                                }
                            }";

            AssertJson.Equal(expected, spy.Value);
        }
Beispiel #13
0
        //[TestMethodWithReport]
        public void TestGetAndAssertLongJson()
        {
            Dictionary <string, string> headers = new Dictionary <string, string>()
            {
                { "Accept", "application/json" }
            };

            RestClientHelper restClientHelper = new RestClientHelper();
            string           getUrl           = "http://localhost:1082/laptop-bag/webapi/api/all";
            IRestResponse    restResponse     = restClientHelper.PerformGetRequest(getUrl, headers);

            Assert.AreEqual(200, (int)restResponse.StatusCode);
            Assert.IsNotNull(restResponse.Content, "Content is Null/Empty");

            IRestResponse <List <Laptop> > restResponse1 = restClientHelper.PerformGetRequest <List <Laptop> >(getUrl, headers);

            Assert.AreEqual(200, (int)restResponse.StatusCode);
            Assert.IsNotNull(restResponse1.Data, "Content is Null/Empty");

            var actual = File.ReadAllText(Directory.GetCurrentDirectory() + "/Resource/Get/getall.json");

            AssertJson.AreEquals(restResponse.Content, actual);
        }
        public async Task returns_expected_serialized_value_of_simple_payload_with_simple_headers()
        {
            var sut = new DefaultPayloadSerializer();

            var messageDataStub = "foo-message-data";
            var headerEntryStub = KeyValuePair.Create <string, object>("foo", "bar");

            var payloadStub = new PayloadDescriptorBuilder()
                              .WithMessageData(messageDataStub)
                              .WithMessageHeaders(headerEntryStub)
                              .Build();

            AssertJson.Equal(
                expected: $@"
                            {{
                                ""messageId"":""{payloadStub.MessageId}"",
                                ""type"":""{payloadStub.MessageType}"",
                                ""{headerEntryStub.Key}"":""{headerEntryStub.Value}"",
                                ""data"":""{messageDataStub}""
                            }}",
                actual: await sut.Serialize(payloadStub)
                );
        }
Beispiel #15
0
 public void AreEquals_EqualJsonStrings_Success()
 {
     AssertJson.AreEquals("{name:'value'}", "{name:'value'}");
 }