< Summary

Class:Microsoft.Azure.EventHubs.ServiceFabricProcessor.EventHubWrappers
Assembly:Microsoft.Azure.EventHubs.ServiceFabricProcessor
File(s):C:\Git\azure-sdk-for-net\sdk\eventhub\Microsoft.Azure.EventHubs.ServiceFabricProcessor\src\EventHubWrappers.cs
Covered lines:0
Uncovered lines:21
Coverable lines:21
Total lines:156
Line coverage:0% (0 of 21)
Covered branches:0
Total branches:0

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-0%100%
get_PrefetchCount()-0%100%
set_PrefetchCount(...)-0%100%
ReceiveAsync(...)-0%100%
SetReceiveHandler(...)-0%100%
CloseAsync()-0%100%
get_MaxBatchSize()-0%100%
.ctor(...)-0%100%
GetRuntimeInformationAsync()-0%100%
CreateEpochReceiver(...)-0%100%
CloseAsync()-0%100%
Create(...)-0%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\eventhub\Microsoft.Azure.EventHubs.ServiceFabricProcessor\src\EventHubWrappers.cs

#LineLine coverage
 1// Copyright (c) Microsoft. All rights reserved.
 2// Licensed under the MIT license. See LICENSE file in the project root for full license information.using System;
 3
 4namespace Microsoft.Azure.EventHubs.ServiceFabricProcessor
 5{
 6    using System;
 7    using System.Collections.Generic;
 8    using System.Threading.Tasks;
 9
 10    /// <summary>
 11    /// Wrappers for the underlying Event Hub client which allow mocking.
 12    /// The interfaces include only the client functionality used by the Service Fabric Processor.
 13    /// </summary>
 14    public class EventHubWrappers
 15    {
 16        /// <summary>
 17        /// Interface for a partition receiver.
 18        /// </summary>
 19        public interface IPartitionReceiver
 20        {
 21            /// <summary>
 22            ///
 23            /// </summary>
 24            int PrefetchCount { get; set; }
 25
 26            /// <summary>
 27            /// </summary>
 28            /// <param name="maxEventCount"></param>
 29            /// <param name="waitTime"></param>
 30            /// <returns></returns>
 31            Task<IEnumerable<EventData>> ReceiveAsync(int maxEventCount, TimeSpan waitTime);
 32
 33            /// <summary>
 34            /// </summary>
 35            /// <param name="receiveHandler"></param>
 36            /// <param name="invokeWhenNoEvents"></param>
 37            void SetReceiveHandler(IPartitionReceiveHandler receiveHandler, bool invokeWhenNoEvents = false);
 38
 39            /// <summary>
 40            /// </summary>
 41            /// <returns></returns>
 42            Task CloseAsync();
 43        }
 44
 45        /// <summary>
 46        /// Interface representing EventHubClient
 47        /// </summary>
 48        public interface IEventHubClient
 49        {
 50            /// <summary>
 51            /// </summary>
 52            /// <returns></returns>
 53            Task<EventHubRuntimeInformation> GetRuntimeInformationAsync();
 54
 55            /// <summary>
 56            /// </summary>
 57            /// <param name="consumerGroupName"></param>
 58            /// <param name="partitionId"></param>
 59            /// <param name="eventPosition"></param>
 60            /// <param name="epoch"></param>
 61            /// <param name="receiverOptions"></param>
 62            /// <returns></returns>
 63            IPartitionReceiver CreateEpochReceiver(string consumerGroupName, string partitionId, EventPosition eventPosi
 64
 65            /// <summary>
 66            /// </summary>
 67            /// <returns></returns>
 68            Task CloseAsync();
 69        }
 70
 71        /// <summary>
 72        /// Interface for an EventHubClient factory so that we can have factories which dispense different implementatio
 73        /// </summary>
 74        public interface IEventHubClientFactory
 75        {
 76            /// <summary>
 77            /// </summary>
 78            /// <param name="connectionString"></param>
 79            /// <param name="receiveTimeout"></param>
 80            /// <returns></returns>
 81            IEventHubClient Create(string connectionString, TimeSpan receiveTimeout);
 82        }
 83
 84        internal class PartitionReceiverWrapper : IPartitionReceiver
 85        {
 86            private readonly PartitionReceiver inner;
 87
 088            internal PartitionReceiverWrapper(PartitionReceiver receiver)
 89            {
 090                this.inner = receiver;
 091                this.MaxBatchSize = 10; // TODO get this from somewhere real
 092            }
 93
 94            public int PrefetchCount
 95            {
 096                get => this.inner.PrefetchCount;
 97                set
 98                {
 099                    this.inner.PrefetchCount = value;
 0100                }
 101            }
 102
 103            public Task<IEnumerable<EventData>> ReceiveAsync(int maxEventCount, TimeSpan waitTime)
 104            {
 0105                return this.inner.ReceiveAsync(maxEventCount, waitTime);
 106            }
 107
 108            public void SetReceiveHandler(IPartitionReceiveHandler receiveHandler, bool invokeWhenNoEvents = false)
 109            {
 0110                this.inner.SetReceiveHandler(receiveHandler, invokeWhenNoEvents);
 0111            }
 112
 113            public Task CloseAsync()
 114            {
 0115                return this.inner.CloseAsync();
 116            }
 117
 0118            public int MaxBatchSize { get; set; }
 119        }
 120
 121        internal class EventHubClientWrapper : IEventHubClient
 122        {
 123            private readonly EventHubClient inner;
 124
 0125            internal EventHubClientWrapper(EventHubClient ehc)
 126            {
 0127                this.inner = ehc;
 0128            }
 129
 130            public Task<EventHubRuntimeInformation> GetRuntimeInformationAsync()
 131            {
 0132                return this.inner.GetRuntimeInformationAsync();
 133            }
 134
 135            public IPartitionReceiver CreateEpochReceiver(string consumerGroupName, string partitionId, EventPosition ev
 136            {
 0137                return new PartitionReceiverWrapper(this.inner.CreateEpochReceiver(consumerGroupName, partitionId, event
 138            }
 139
 140            public Task CloseAsync()
 141            {
 0142                return this.inner.CloseAsync();
 143            }
 144        }
 145
 146        internal class EventHubClientFactory : IEventHubClientFactory
 147        {
 148            public IEventHubClient Create(string connectionString, TimeSpan receiveTimeout)
 149            {
 0150                EventHubsConnectionStringBuilder csb = new EventHubsConnectionStringBuilder(connectionString);
 0151                csb.OperationTimeout = receiveTimeout;
 0152                return new EventHubClientWrapper(EventHubClient.Create(csb));
 153            }
 154        }
 155    }
 156}