public async Task ExecuteEventGridTrigger_WhenPassedEvent_StoresEventSuccessfully()
        {
            //Arrange
            var eventStoreModel = new EventStoreModel()
            {
                Data        = "Some data...",
                DataVersion = "1.0.0",
                EventTime   = DateTime.UtcNow,
                Id          = Guid.NewGuid(),
                EventType   = EventTypes.StorageBlobCreatedEvent,
                Subject     = "My Test Subject",
                Topic       = "My/Topic/Test"
            };

            //Act
            await RunFunction(eventStoreModel);

            //Assert
            A.CallTo(() => _eventStoreRepository.UpsertAsync(A <EventStoreModel> .Ignored)).MustHaveHappenedOnceExactly();
        }
        private async Task RunFunction(EventStoreModel eventStoreModel)
        {
            var ms = new MemoryStream();
            var sw = new StreamWriter(ms);

            var json = JsonConvert.SerializeObject(eventStoreModel != null ?  new List <EventStoreModel> {
                eventStoreModel
            } : null);

            sw.Write(json);
            sw.Flush();

            ms.Position = 0;

            var request = new DefaultHttpRequest(new DefaultHttpContext())
            {
                Body = ms
            };

            await _executeFunction.Run(request, _log).ConfigureAwait(false);
        }
        public async Task ExecuteEventGridTrigger_ThrowsException_ExceptionCaught()
        {
            //Arrange
            var eventStoreModel = new EventStoreModel()
            {
                Data        = "Some data...",
                DataVersion = "1.0.0",
                EventTime   = DateTime.UtcNow,
                Id          = Guid.NewGuid(),
                EventType   = EventTypes.StorageBlobCreatedEvent,
                Subject     = "My Test Subject",
                Topic       = "My/Topic/Test"
            };

            A.CallTo(() => _eventStoreRepository.UpsertAsync(A <EventStoreModel> .Ignored)).Throws(new InvalidOperationException("Something went wrong"));

            //Act

            //Assert
            await Assert.ThrowsAsync <InvalidOperationException>(async() => await RunFunction(eventStoreModel));
        }