Beispiel #1
0
        public void GetLinksAsync_Throws()
        {
            var url              = "http://a.b";
            var expectedRequest  = new HttpRequestMessage();
            var expectedResponse = new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.InternalServerError
            };

            QTB3.Client.Common.Services.LinkService.LinkService service = new ServiceTestBuilder <Uom>()
                                                                          .ApiEndPoint_GetUrl(url)
                                                                          .HttpRequestBuilder_BuildAsync(HttpMethod.Head, url, expectedRequest)
                                                                          .HttpClient_SendAsync(expectedRequest, expectedResponse);

            Assert.ThrowsAsync <LinksException>
            (
                async() => await service.GetLinksAsync()
            );
        }
        private static void Execute(ServiceTestBuilder builder)
        {
            var uri  = new Uri(builder.ServiceAddress + builder.ContractType.Name); // Disambiguate
            var host = Activator.CreateInstance(builder.ServiceHostType, builder.ServiceType, uri) as ServiceHost;

            if (builder.IncludeExceptionDetails)
            {
                var sdb = host.Description.Behaviors.Find <ServiceDebugBehavior>();
                sdb.IncludeExceptionDetailInFaults = true;
            }
            host.AddServiceEndpoint(builder.ContractType, builder.Binding, string.Empty);
            host.Open();

            object client = typeof(ChannelFactory <>).MakeGenericType(builder.ContractType).InvokeMember(
                "CreateChannel",
                BindingFlags.Public | /* public static method */
                BindingFlags.Static |
                BindingFlags.InvokeMethod,
                null, /* default binder */
                null, /* no instance - static method */
                new object[]
            {
                builder.Binding,         /* WCF Binding */
                new EndpointAddress(uri) /* Service Endpoint */
            });

            OperationContextScope ctx = null;

            if (builder.EstablishOperationContextScope)
            {
                ctx = new OperationContextScope((IContextChannel)client);
            }

            builder.ClientAction.DynamicInvoke(client);

            if (ctx != null)
            {
                ctx.Dispose();
            }

            host.Abort(); // Fail-fast (instead of .Close() )
        }
Beispiel #3
0
        public async Task GetLinksAsync()
        {
            var url              = "http://a.b";
            var links            = "someLinksString";
            var expectedRequest  = new HttpRequestMessage();
            var expectedResponse = new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.OK
            };

            expectedResponse.Headers.Add("Link-Template", links);
            QTB3.Client.Common.Services.LinkService.LinkService service = new ServiceTestBuilder <Uom>()
                                                                          .ApiEndPoint_GetUrl(url)
                                                                          .HttpRequestBuilder_BuildAsync(HttpMethod.Head, url, expectedRequest)
                                                                          .HttpClient_SendAsync(expectedRequest, expectedResponse);

            var response = await service.GetLinksAsync();

            Assert.AreEqual(links, response);
        }