public static IServiceContext AsServiceApplication( this ContextBuilder source, Func <ServiceConfigurationBuilder, IServiceConfiguration> serviceConfiguration, Func <CodingStyleBuilder, ICodingStyle> codingStyle ) => source.AsServiceApplication( serviceConfiguration(BuildRoutine.ServiceConfig()), codingStyle(BuildRoutine.CodingStyle()) );
public override void SetUp() { base.SetUp(); httpContextAccessor = new Mock <IHttpContextAccessor>(); var httpContext = new Mock <HttpContext>(); serviceContext = new Mock <IServiceContext>(); objectService = new Mock <IObjectService>(); request = new Mock <HttpRequest>(); response = new Mock <HttpResponse>(); featureCollection = new Mock <IFeatureCollection>(); httpResponseFeature = new Mock <IHttpResponseFeature>(); requestHeaders = new HeaderDictionary(); responseHeaders = new HeaderDictionary(); requestQueryString = new QueryString(); requestQuery = new QueryCollection(); serializer = new JsonSerializerAdapter(); serviceContext.Setup(sc => sc.ObjectService).Returns(objectService.Object); config = BuildRoutine.ServiceConfig().FromBasic(); serviceContext.Setup(sc => sc.ServiceConfiguration).Returns(config); objectService.Setup(os => os.ApplicationModel).Returns(() => GetApplicationModel()); objectService.Setup(os => os.Get(It.IsAny <ReferenceData>())).Returns((ReferenceData referenceData) => { if (referenceData.Id == null) { referenceData = new ReferenceData { Id = "instance", ModelId = referenceData.ModelId, ViewModelId = referenceData.ViewModelId }; } return(objectDictionary[referenceData]); }); request.Setup(r => r.Headers).Returns(requestHeaders); request.Setup(r => r.QueryString).Returns(requestQueryString); request.Setup(r => r.Query).Returns(requestQuery); request.Setup(r => r.Method).Returns("POST"); request.Setup(r => r.Body).Returns(new MemoryStream()).Verifiable(); // https://stackoverflow.com/questions/34677203/testing-the-result-of-httpresponse-statuscode/34677864#34677864 response.SetupAllProperties(); response.Setup(r => r.Body).Returns(new MemoryStream()).Verifiable(); response.Setup(r => r.Headers).Returns(responseHeaders); httpContextAccessor.Setup(hca => hca.HttpContext).Returns(httpContext.Object); httpContextAccessor.Setup(hca => hca.HttpContext.Request).Returns(request.Object); httpContextAccessor.Setup(hca => hca.HttpContext.Response).Returns(response.Object); httpContextAccessor.Setup(hca => hca.HttpContext.Features).Returns(featureCollection.Object); httpContextAccessor.Setup(hca => hca.HttpContext.Response.HttpContext.Features.Get <IHttpResponseFeature>()).Returns(httpResponseFeature.Object); httpContextAccessor.Setup(hca => hca.HttpContext.Items).Returns(new Dictionary <object, object>()); RequestHandlerBase.ClearModelIndex(); testing = new HandleRequestHandler(serviceContext.Object, serializer, httpContextAccessor.Object, actionFactory: resolution => resolution.HasOperation ? new DoRequestHandler(serviceContext.Object, serializer, httpContextAccessor.Object, resolution) : new GetRequestHandler(serviceContext.Object, serializer, httpContextAccessor.Object, resolution) ); }