Exemple #1
0
        public async Task InvokeAsync(HttpContext httpContext, IOptionsSnapshot <HttpMockOptions> mockOptions, IMockService mockService)
        {
            ContextManager = new HttpContextManager(httpContext, mockOptions);
            MockOptions    = mockOptions.Value;
            MockService    = mockService;

            var mockAction = ContextManager.GetHeaderValue(MockOptions.ActionHeader());

            if (mockAction == RequestHeaderActions.CreateKey)
            {
                await CreateKeyAsync();
            }
            else if (mockAction == RequestHeaderActions.CreateMock)
            {
                await CreateMockAsync();
            }
            else if (mockAction == RequestHeaderActions.DeleteMock)
            {
                await DeleteMockAsync();
            }
            else
            {
                await ReturnMockAsync();
            }

            return;
        }
 public void Init()
 {
     this._settings        = new ConfigurationSettings();
     this._service         = new MockService(this._settings);
     this._config          = new HttpConfiguration();
     this._regexSourcePath = new Regex(@"^[A-Z]+:\\.+$", RegexOptions.Compiled | RegexOptions.IgnoreCase);
 }
Exemple #3
0
 internal MockServiceConnection(IMockService mockService, IServiceConnection serviceConnection)
 {
     _mockService       = mockService;
     _serviceConnection = serviceConnection;
     ConnectionNumber   = Interlocked.Increment(ref s_num);
     _mockService.RegisterSDKConnection(this);
 }
Exemple #4
0
 public void Setup()
 {
     _actualService = new MockService();
     _marshalledOnServer = Marshal.Get(_actualService);
     _marshalledOnClient = Marshal.Get<IMockService>((Func<string, object[], object>)
         ((name, args) => _marshalledOnServer.Invoke(name, args)));
 }
 public PositionRepositoryAsync(ApplicationDbContext dbContext,
                                IDataShapeHelper <Position> dataShaper, IMockService mockData) : base(dbContext)
 {
     _dbContext  = dbContext;
     _positions  = dbContext.Set <Position>();
     _dataShaper = dataShaper;
     _mockData   = mockData;
 }
Exemple #6
0
 public MockServiceSideConnection(IMockService mocksvc, MockServiceConnectionContext sdkSideConnCtx, HubServiceEndpoint endpoint, string target, IDuplexPipe pipe)
 {
     Index   = Interlocked.Increment(ref s_index);
     MockSvc = mocksvc;
     SDKSideServiceConnection = sdkSideConnCtx;
     Endpoint        = endpoint;
     Target          = target;
     MockServicePipe = pipe;
 }
 public EmployeeRepositoryAsync(ApplicationDbContext dbContext,
                                IDataShapeHelper <Employee> dataShaper,
                                IMockService mockData) : base(dbContext)
 {
     _dbContext  = dbContext;
     _employee   = dbContext.Set <Employee>();
     _dataShaper = dataShaper;
     _mockData   = mockData;
 }
Exemple #8
0
 public CircuitBreaker(int threshold = 5, TimeSpan recoverTime = default, IMockService mockService = null)
 {
     if (recoverTime == default)
     {
         recoverTime = new TimeSpan(0, 0, 30);
     }
     Threshold   = threshold;
     RecoverTime = recoverTime;
     MockService = mockService;
 }
Exemple #9
0
        public MockServiceConnectionContext(IMockService mockService, HubServiceEndpoint endpoint, string target, string id)
        {
            ConnectionId = id;
            Features     = new FeatureCollection();
            Items        = new ConcurrentDictionary <object, object>();

            var duplexPipePair = DuplexPipe.CreateConnectionPair(PipeOptions.Default, PipeOptions.Default);

            // SDK's side uses Transport property to read/write to our mock service
            Transport = duplexPipePair.Transport;

            _mockService            = mockService;
            MyServiceSideConnection = _mockService.RegisterSDKConnectionContext(this, endpoint, target, duplexPipePair.Application);
        }
        public MockServiceConnectionContext(IMockService mockService, string id)
        {
            ConnectionId = id;
            Features     = new FeatureCollection();
            Items        = new ConcurrentDictionary <object, object>();

            var duplexPipePair = DuplexPipe.CreateConnectionPair(PipeOptions.Default, PipeOptions.Default);

            // SDK's side uses Transport property to read/write to our mock service
            Transport = duplexPipePair.Transport;

            (_mockService = mockService).MockServicePipe = duplexPipePair.Application;
            _ = _mockService.StartAsync();
        }
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IMockService service)
        {
            //var rewrite = new RewriteOptions()
            //    .AddRedirect("films", "movies")
            //    .AddRewrite("actors", "stars", true);

            //app.UseRewriter(rewrite);

            //app.Run(async context =>
            //{
            //    var path = context.Request.Path;
            //    var query = context.Request.QueryString;
            //    await context.Response.WriteAsync($"New URL: {path}{query}");
            //});
        }
Exemple #12
0
        public void Init()
        {
            this._settings = new ConfigurationSettings();
            this._service  = new MockService(this._settings);

            this._config = new HttpConfiguration();
            var route = this._config.Routes.MapHttpRoute("DefaultApi",
                                                         "api/{controller}/{id}",
                                                         new { id = RouteParameter.Optional });

            this._routeData = new HttpRouteData(route,
                                                new HttpRouteValueDictionary()
            {
                { "controller", "Service" }
            });

            this._controller = new ServiceController(this._settings, this._service);
        }
        public void BuildProgramaticallyServiceInstanceTest()
        {
            UnityApplicationContainer.SetInstanceForTest(UnityContainerMother.GetContainerWithMockLogger());
            var serviceHost = new UnityEnabledServiceHost(typeof(MockService));
            var binding     = new NetTcpBinding();

            serviceHost.Open();

            IMockService proxy = ChannelFactory <IMockService> .CreateChannel(binding, ServiceEndpointAddress);

            const string input = "DoOperation()";

            proxy.DoOperation(input);
            proxy.DoOperation(input);
            Assert.Equal(proxy.GetLastLogEntry(), input);

            ((ICommunicationObject)proxy).Close();
            serviceHost.Close();
            UnityApplicationContainer.SetInstanceForTest(null);
        }
Exemple #14
0
 public MockServiceConnectionFactory(
     IMockService mockService,
     IServiceProtocol serviceProtocol,
     IClientConnectionManager clientConnectionManager,
     IConnectionFactory connectionFactory,
     ILoggerFactory loggerFactory,
     ConnectionDelegate connectionDelegate,
     IClientConnectionFactory clientConnectionFactory,
     IServerNameProvider nameProvider)
     : base(
         serviceProtocol,
         clientConnectionManager,
         new MockServiceConnectionContextFactory(mockService),   // use instead of connectionFactory
         loggerFactory,
         connectionDelegate,
         clientConnectionFactory,
         nameProvider)
 {
     _mockService = mockService;
 }
        // Helper method to pull raw messages received by the mock service and count them per service connection
        private static async Task <ConcurrentDictionary <MockServiceSideConnection, int> > DrainBroadcastMessages(
            int endpointCount, int msgNum, IMockService mockSvc,
            ConcurrentDictionary <MockServiceSideConnection, int> counts = null)
        {
            counts ??= new ConcurrentDictionary <MockServiceSideConnection, int>();

            // Each endpoint will get the broadcast message so we should receive endpointCount * MsgNum messages
            for (int ep = 0; ep < endpointCount * msgNum; ep++)
            {
                // we go "peek then take" route because we don't know which secondary connection will receive the messages
                var connWithMessage = await Task.WhenAny(mockSvc.ServiceSideConnections.Select(async c =>
                {
                    bool moreData = await c.WaitToDequeueMessageAsync <BroadcastDataMessage>();
                    Assert.True(moreData);
                    return(c, moreData);
                }));

                var conn   = connWithMessage.Result.c;
                var newMsg = await conn.DequeueMessageAsync <BroadcastDataMessage>();

                int msgCount = counts.GetOrAdd(conn, 0);
                counts[conn] = ++msgCount;

                // parse each BroadcastDataMessage and verify this is the correct message
                var hubMessage = ParseBroadcastDataMessageJson(newMsg, mockSvc.CurrentInvocationBinder);
                Assert.True(hubMessage is InvocationMessage);
                var invMsg = hubMessage as InvocationMessage;
                Assert.Equal("Callback", invMsg.Target);

                // finally, get ready to verify the order of messages
                int actualCallbackNum = (int)invMsg.Arguments[0];

                // this check works for both primary and secondary connections
                Assert.Equal(msgCount, actualCallbackNum);
            }
            // todo: verify we received no extra BroadcastDataMessage - need TryPeek method (async with timeout?)
            return(counts);
        }
Exemple #16
0
 public NormalHystrixCommand(IHystrixCommandOptions options, IMockService mockService, ILoggerFactory loggerFactory) : base(options, logger: loggerFactory.CreateLogger <NormalHystrixCommand>())
 {
     _mockService = mockService;
 }
 public UserController(IUserService _userService, IMockService _mockService)
 {
     userService = _userService;
 }
 public CityController(IMockService _mockService)
 {
     mockService = _mockService;
 }
Exemple #19
0
 public GetMockMiddlewareService(IMockService mockService)
 {
     _mockService = mockService;
 }
Exemple #20
0
 private void Act()
 {
     _mockServiceClient = _container.Resolve <IMockService>("mockClient");
 }
Exemple #21
0
 public MockHost(IMockService mockService)
 {
     MockService = mockService ?? throw new ArgumentNullException(nameof(mockService));
 }
Exemple #22
0
 public HomeController(IMockService mockService)
 {
     _mockService = mockService;
 }
 public MockServiceConnectionContextFactory(IMockService mockService)
 {
     _mockService = mockService;
 }
Exemple #24
0
 internal MockServiceConnection(IMockService mockService, IServiceConnection serviceConnection)
 {
     _mockService       = mockService;
     _serviceConnection = serviceConnection;
 }
Exemple #25
0
        public MockQuery(IMockService mockService)
        {
            _mockService = mockService;

            //Field<ListGraphType<MockType>>(
            //    "MockList",
            //    resolve:
            //    context =>
            //    {
            //        try
            //        {
            //            return GetData();
            //        }
            //        catch (NullReferenceException e)
            //        {
            //            throw new ExecutionError(e.Message);
            //        }
            //        catch (ArgumentException e)
            //        {
            //            throw new ExecutionError(e.Message);
            //        }
            //        catch (Exception e)
            //        {
            //            throw new ExecutionError(e.Message);
            //        }
            //    });

            //Code commented above can be changed with this code using extension method Execute of class GraphQLExt
            Field <ListGraphType <MockType> >(
                "MockList",
                resolve:
                context => context.Execute(GetData)
                );

            //Field<MockType>(
            //    "Mock",
            //    arguments: new QueryArguments(
            //        new QueryArgument<IdGraphType> { Name = "id" }
            //    ),
            //    resolve:
            //    context =>
            //    {
            //        try
            //        {
            //            var id = context.GetArgument<int>("id");
            //            return GetDataById(id);
            //        }
            //        catch (NullReferenceException e)
            //        {
            //            throw new ExecutionError(e.Message);
            //        }
            //        catch (ArgumentException e)
            //        {
            //            throw new ExecutionError(e.Message);
            //        }
            //        catch (Exception e)
            //        {
            //            throw new ExecutionError(e.Message);
            //        }
            //    });

            //Code commented above can be changed with this code using extension method Execute of class GraphQLExt
            Field <MockType>(
                "Mock",
                arguments: new QueryArguments(
                    new QueryArgument <IdGraphType> {
                Name = "id"
            }
                    ),
                resolve:
                context => context.Execute(GetDataById));
        }
 /// <summary>
 /// Initialises a new instance of the ServiceController class.
 /// </summary>
 /// <param name="settings">Configuration settings instance.</param>
 /// <param name="service">Mock service instance.</param>
 public ServiceController(IConfigurationSettings settings, IMockService service)
 {
     this._settings = settings;
     this._service  = service;
 }
Exemple #27
0
 public void Configure(IMockService mockService)
 {
     mockService.Value = "5";
 }