예제 #1
0
        public void ConstructorThrowsOnNull()
        {
            Mock <HttpMessageHandler> mockHandler = new Mock <HttpMessageHandler>();

            Assert.ThrowsArgumentNull(() => new HttpServer((HttpConfiguration)null, mockHandler.Object), "configuration");
            Assert.ThrowsArgumentNull(() => new HttpServer(new HttpConfiguration(), null), "dispatcher");
        }
예제 #2
0
        public void Constructor_GuardClauses()
        {
            HttpRequestMessage request = new HttpRequestMessage();

            Assert.ThrowsArgumentNull(() => new HttpRequestMessageWrapper(virtualPathRoot: null, httpRequest: request), "virtualPathRoot");
            Assert.ThrowsArgumentNull(() => new HttpRequestMessageWrapper(String.Empty, httpRequest: null), "httpRequest");
        }
예제 #3
0
        public void TryReadQueryAsThrowsWithNull()
        {
            object value;

            Assert.ThrowsArgumentNull(() => ((Uri)null).TryReadQueryAs(TestType, out value), "address");
            Assert.ThrowsArgumentNull(() => TestAddress.TryReadQueryAs(null, out value), "type");
        }
예제 #4
0
 public void OnAuthorization_IfContextParameterIsNull_ThrowsException()
 {
     Assert.ThrowsArgumentNull(() =>
     {
         _attribute.OnAuthorization(actionContext: null);
     }, "actionContext");
 }
예제 #5
0
 public void HandleUnauthorizedRequest_IfContextParameterIsNull_ThrowsArgumentNullException()
 {
     Assert.ThrowsArgumentNull(() =>
     {
         _attribute.HandleUnauthorizedRequestPublic(context: null);
     }, "actionContext");
 }
        public void ReadFromStreamAsync_ThrowsOnNull()
        {
            TFormatter formatter = new TFormatter();

            Assert.ThrowsArgumentNull(() => { formatter.ReadFromStreamAsync(null, Stream.Null, null, null); }, "type");
            Assert.ThrowsArgumentNull(() => { formatter.WriteToStreamAsync(typeof(object), null, null, null, null); }, "stream");
        }
예제 #7
0
        public void CanWriteAsThrowsWithNullContent()
        {
            MockMediaTypeFormatter formatter = new MockMediaTypeFormatter();
            MediaTypeHeaderValue   mediaType = null;

            Assert.ThrowsArgumentNull(() => formatter.CanWriteAs(typeof(int), null, out mediaType), "mediaType");
        }
예제 #8
0
        public void ReadFromStreamThrowsOnNull()
        {
            TestFormUrlEncodedMediaTypeFormatter formatter = new TestFormUrlEncodedMediaTypeFormatter();

            Assert.ThrowsArgumentNull(() => { formatter.ReadFromStreamAsync(null, Stream.Null, null, null); }, "type");
            Assert.ThrowsArgumentNull(() => { formatter.ReadFromStreamAsync(typeof(object), null, null, null); }, "stream");
        }
        public void ReadAsHttpRequestMessageVerifyArguments()
        {
            Assert.ThrowsArgumentNull(() => HttpContentMessageExtensions.ReadAsHttpRequestMessageAsync(null), "content");
            Assert.ThrowsArgument(() => new ByteArrayContent(new byte[] { }).ReadAsHttpRequestMessageAsync(), "content");
            Assert.ThrowsArgument(() => new StringContent(String.Empty).ReadAsHttpRequestMessageAsync(), "content");
            Assert.ThrowsArgument(() => new StringContent(String.Empty, Encoding.UTF8, "application/http").ReadAsHttpRequestMessageAsync(), "content");

            Assert.ThrowsArgument(() =>
            {
                HttpContent content         = new StringContent(String.Empty);
                content.Headers.ContentType = ParserData.HttpResponseMediaType;
                content.ReadAsHttpRequestMessageAsync();
            }, "content");

            Assert.ThrowsArgumentNull(() =>
            {
                HttpContent content         = new StringContent(String.Empty);
                content.Headers.ContentType = ParserData.HttpRequestMediaType;
                content.ReadAsHttpRequestMessageAsync(null);
            }, "uriScheme");

            Assert.ThrowsArgument(() =>
            {
                HttpContent content         = new StringContent(String.Empty);
                content.Headers.ContentType = ParserData.HttpRequestMediaType;
                content.ReadAsHttpRequestMessageAsync("i n v a l i d");
            }, "uriScheme");

            Assert.ThrowsArgumentGreaterThanOrEqualTo(() =>
            {
                HttpContent content         = new StringContent(String.Empty);
                content.Headers.ContentType = ParserData.HttpRequestMediaType;
                content.ReadAsHttpRequestMessageAsync(Uri.UriSchemeHttp, ParserData.MinBufferSize - 1);
            }, "bufferSize", ParserData.MinBufferSize.ToString(), ParserData.MinBufferSize - 1);
        }
        public void FindWriter_ThrowsOnNullType()
        {
            MediaTypeFormatterCollection collection = new MediaTypeFormatterCollection();
            MediaTypeHeaderValue         mediaType  = new MediaTypeHeaderValue("text/test");

            Assert.ThrowsArgumentNull(() => collection.FindWriter(type: null, mediaType: mediaType), "type");
        }
        public void TryGetValueThrowsOnNullKey()
        {
            IDictionary <string, object> dict = new Dictionary <string, object>();
            string value;

            Assert.ThrowsArgumentNull(() => dict.TryGetValue <string>(null, out value), "key");
        }
예제 #12
0
 public void ReadAsMultipartAsync_DetectsNonMultipartContent()
 {
     Assert.ThrowsArgumentNull(() => HttpContentMultipartExtensions.IsMimeMultipartContent(null), "content");
     Assert.ThrowsArgument(() => new ByteArrayContent(new byte[0]).ReadAsMultipartAsync().Result, "content");
     Assert.ThrowsArgument(() => new StringContent(String.Empty).ReadAsMultipartAsync().Result, "content");
     Assert.ThrowsArgument(() => new StringContent(String.Empty, Encoding.UTF8, "multipart/form-data").ReadAsMultipartAsync().Result, "content");
 }
예제 #13
0
        public void SetDefaultContentHeaders_ThrowsOnNullHeaders()
        {
            MockMediaTypeFormatter formatter = new MockMediaTypeFormatter();
            Type type = typeof(object);

            Assert.ThrowsArgumentNull(() => formatter.SetDefaultContentHeaders(type, null, TestMediaTypeHeader), "headers");
        }
예제 #14
0
        public void SupportedMediaTypes_AddThrowsWithNullMediaType()
        {
            MockMediaTypeFormatter            formatter           = new MockMediaTypeFormatter();
            Collection <MediaTypeHeaderValue> supportedMediaTypes = formatter.SupportedMediaTypes;

            Assert.ThrowsArgumentNull(() => supportedMediaTypes.Add(null), "item");
        }
        public void SetSerializer2_ThrowsWithNullType()
        {
            XmlMediaTypeFormatter formatter           = new XmlMediaTypeFormatter();
            XmlObjectSerializer   xmlObjectSerializer = new DataContractSerializer(typeof(string));

            Assert.ThrowsArgumentNull(() => { formatter.SetSerializer(null, xmlObjectSerializer); }, "type");
        }
예제 #16
0
        public void SetDefaultContentHeaders_ThrowsOnNullType()
        {
            MockMediaTypeFormatter formatter      = new MockMediaTypeFormatter();
            HttpContentHeaders     contentHeaders = FormattingUtilities.CreateEmptyContentHeaders();

            Assert.ThrowsArgumentNull(() => formatter.SetDefaultContentHeaders(null, contentHeaders, TestMediaTypeHeader), "type");
        }
예제 #17
0
        public void SetResolverCommonServiceLocatorThrowsOnNull()
        {
            HttpConfiguration  config   = new HttpConfiguration();
            DependencyResolver resolver = new DependencyResolver(config);

            Assert.ThrowsArgumentNull(() => resolver.SetResolver((object)null), "commonServiceLocator");
        }
예제 #18
0
        public void SetResolverIDependencyResolverThrowsOnNull()
        {
            HttpConfiguration  config   = new HttpConfiguration();
            DependencyResolver resolver = new DependencyResolver(config);

            Assert.ThrowsArgumentNull(() => resolver.SetResolver((IDependencyResolver)null), "resolver");
        }
        public void ConstructorThrowsOnNull()
        {
            Mock <HttpControllerDispatcher> controllerDispatcherMock = new Mock <HttpControllerDispatcher>();

            Assert.ThrowsArgumentNull(() => new HttpServer((HttpConfiguration)null, controllerDispatcherMock.Object), "configuration");
            Assert.ThrowsArgumentNull(() => new HttpServer(new HttpConfiguration(), null), "dispatcher");
        }
예제 #20
0
        public void SetResolverFuncThrowsOnNull()
        {
            HttpConfiguration  config   = new HttpConfiguration();
            DependencyResolver resolver = new DependencyResolver(config);

            Assert.ThrowsArgumentNull(() => resolver.SetResolver(null, _ => null), "getService");
            Assert.ThrowsArgumentNull(() => resolver.SetResolver(_ => null, null), "getServices");
        }
예제 #21
0
 public void IsMimeMultipartContentVerifyArguments()
 {
     Assert.ThrowsArgumentNull(() =>
     {
         HttpContent content = null;
         HttpContentMultipartExtensions.IsMimeMultipartContent(content);
     }, "content");
 }
 public void IsHttpResponseMessageContentVerifyArguments()
 {
     Assert.ThrowsArgumentNull(() =>
     {
         HttpContent content = null;
         HttpContentMessageExtensions.IsHttpResponseMessageContent(content);
     }, "content");
 }
예제 #23
0
        public void Initializer_Throws_With_Null()
        {
            // Arrange
            var config = new HttpConfiguration();

            // Act & Assert
            Assert.ThrowsArgumentNull(() => config.Initializer = null, "value");
        }
        public void ParseBufferThrowsOnNullBuffer()
        {
            ICollection <KeyValuePair <string, string> > collection;
            FormUrlEncodedParser parser = CreateParser(128, out collection);
            int bytesConsumed           = 0;

            Assert.ThrowsArgumentNull(() => { parser.ParseBuffer(null, 0, ref bytesConsumed, false); }, "buffer");
        }
        public void FindAllContentTypeMediaTypeThrows()
        {
            Assert.ThrowsArgumentNull(() => { HttpContentCollectionExtensions.FindAllContentType(null, new MediaTypeHeaderValue("text/plain")); }, "contents");

            IEnumerable <HttpContent> content = HttpContentCollectionExtensionsTests.CreateContent();

            Assert.ThrowsArgumentNull(() => { HttpContentCollectionExtensions.FindAllContentType(content, (MediaTypeHeaderValue)null); }, "contentType");
        }
예제 #26
0
        public void DependencyResolver_GuardClauses()
        {
            // Arrange
            var config = new HttpConfiguration();

            // Act & assert
            Assert.ThrowsArgumentNull(() => config.DependencyResolver = null, "value");
        }
        public void SelectResponseMediaTypeFormatter_ThrowsOnNull()
        {
            MockContentNegotiator  negotiator = new MockContentNegotiator();
            HttpRequestMessage     request    = new HttpRequestMessage();
            MockMediaTypeFormatter formatter  = new MockMediaTypeFormatter();

            Assert.ThrowsArgumentNull(() => negotiator.SelectResponseMediaTypeFormatter(matches: null), "matches");
        }
예제 #28
0
        public void ConvertToThrowsIfTypeIsNull()
        {
            // Arrange
            ValueProviderResult vpr = new ValueProviderResult("x", null, CultureInfo.InvariantCulture);

            // Act & Assert
            Assert.ThrowsArgumentNull(
                delegate { vpr.ConvertTo(null); }, "type");
        }
예제 #29
0
        public void GetServicesThrowsOnNull()
        {
            // Arrange
            HttpConfiguration  config   = new HttpConfiguration();
            DependencyResolver resolver = new DependencyResolver(config, null);

            // Act
            Assert.ThrowsArgumentNull(() => resolver.GetServices(null), "serviceType");
        }
예제 #30
0
        public void ReadAsMultipartAsync_NullStreamProviderThrows()
        {
            HttpContent content = CreateContent("---");

            Assert.ThrowsArgumentNull(() =>
            {
                content.ReadAsMultipartAsync(null);
            }, "streamProvider");
        }