/// <summary>
        /// Create a service registration clause.
        /// </summary>
        /// <param name="server">The mocked HTTP server.</param>
        /// <param name="serviceUriPrefix">The base address of a standalone service.</param>
        public WithServiceClause(MockHttpServer server, string serviceUriPrefix)
        {
            if (server == null)
            {
                throw new ArgumentNullException(nameof(server));
            }

            if (serviceUriPrefix == null)
            {
                throw new ArgumentNullException(nameof(serviceUriPrefix));
            }

#if !NET_CORE
            var uri = new Uri(serviceUriPrefix, UriKind.Absolute);
#else
            var uri = new Uri(serviceUriPrefix, UriKind.RelativeOrAbsolute);
            if (!uri.IsAbsoluteUri)
            {
                throw new UriFormatException($"The uri {uri} is not absolute uri.");
            }
#endif

            this.server           = server;
            this.serviceUriPrefix = uri.AbsoluteUri;
        }
Example #2
0
        /// <summary>
        /// Create a service registration clause.
        /// </summary>
        /// <param name="server">The mocked HTTP server.</param>
        /// <param name="serviceUriPrefix">The base address of a standalone service.</param>
        public WithServiceClause(MockHttpServer server, string serviceUriPrefix)
        {
            if (server == null)
            {
                throw new ArgumentNullException(nameof(server));
            }

            if (serviceUriPrefix == null)
            {
                throw new ArgumentNullException(nameof(serviceUriPrefix));
            }

            var uri = new Uri(serviceUriPrefix, UriKind.Absolute);

            this.server           = server;
            this.serviceUriPrefix = uri.AbsoluteUri;
        }
Example #3
0
 /// <summary>
 /// Mock a service. A service can contains a set of APIs, of which the base addresses
 /// are all the same.
 /// </summary>
 /// <param name="server">The mocked http server.</param>
 /// <param name="serviceUriPrefix">The base address for current service.</param>
 /// <returns>The service registration clause.</returns>
 /// <exception cref="UriFormatException">
 /// The <paramref name="serviceUriPrefix"/> is not a valid absolute URI.
 /// </exception>
 /// <exception cref="ArgumentNullException">
 /// The <paramref name="server"/> is <c>null</c> or the <paramref name="serviceUriPrefix"/> is <c>null</c>.
 /// </exception>
 public static WithServiceClause WithService(
     this MockHttpServer server,
     string serviceUriPrefix)
 {
     return(new WithServiceClause(server, serviceUriPrefix));
 }