public async Task Can_receive_event()
        {
            // Arrange
            var request = new AddSubscriptionRequest
            {
                Name = "foo"
            };
            var addSubscription = await _client.PostAsJson(request, "hooks");

            var addSubscriptionResponse = await addSubscription.Content.ReadAs <AddSubscriptionResponse>();

            var eventName        = "foo";
            var messageId        = Guid.NewGuid();
            var json             = "{ \"id\": 1 }";
            var signature        = PayloadSignature.CreateSignature(json, addSubscriptionResponse.Secret);
            var content          = new StringContent(json, Encoding.UTF8, "application/json");
            var postEventRequest = new HttpRequestMessage(HttpMethod.Post, addSubscription.Headers.Location)
            {
                Content = content
            };

            SetCustomHeaders(postEventRequest, eventName, messageId, signature);

            // Act
            var response = await _client.SendAsync(postEventRequest);

            var streamMessage = (await _streamStore.ReadAllForwards(Position.Start, 10, true))
                                .Messages.Where(m => m.Type == eventName).SingleOrDefault();

            // Assert
            response.StatusCode.ShouldBe(HttpStatusCode.OK);
            (await streamMessage.GetJsonData()).ShouldBe(json);
            streamMessage.MessageId.ShouldBe(messageId);
        }
        public async Task When_receive_same_event_twice_then_should_record_it_once()
        {
            // Arrange
            var request = new AddSubscriptionRequest
            {
                Name = "foo"
            };
            var addSubscription = await _client.PostAsJson(request, "hooks");

            var addSubscriptionResponse = await addSubscription.Content.ReadAs <AddSubscriptionResponse>();

            var eventName        = "foo";
            var messageId        = Guid.NewGuid();
            var json             = "{ \"id\": 1 }";
            var signature        = PayloadSignature.CreateSignature(json, addSubscriptionResponse.Secret);
            var postEventRequest = new HttpRequestMessage(HttpMethod.Post, addSubscription.Headers.Location)
            {
                Content = new StringContent(json, Encoding.UTF8, "application/json")
            };

            SetCustomHeaders(postEventRequest, eventName, messageId, signature);
            await _client.SendAsync(postEventRequest);

            // Act
            var secondPostEventRequest = new HttpRequestMessage(HttpMethod.Post, addSubscription.Headers.Location)
            {
                Content = new StringContent(json, Encoding.UTF8, "application/json")
            };

            SetCustomHeaders(postEventRequest, eventName, messageId, signature);
            await _client.SendAsync(secondPostEventRequest);

            (await _streamStore.ReadAllForwards(Position.Start, 10, true))
            .Messages
            .Where(m => m.Type == eventName && m.MessageId == messageId)
            .SingleOrDefault()     // Idempotent!
            .ShouldNotBeNull();
        }