public void TryGetValueReturnsFalse()
        {
            // Arrange
            IDictionary <string, object> dict = new Dictionary <string, object>();

            // Act
            string resultValue = null;
            bool   result      = dict.TryGetValue("notfound", out resultValue);

            // Assert
            Assert.False(result);
            Assert.Null(resultValue);
        }
Example #2
0
        public void TryParseReturnsFalseMaxDepthExceeded()
        {
            JObject value;

            // Depth of 'a[b]=1' is 3
            IEnumerable <KeyValuePair <string, string> > query = CreateQuery(new KeyValuePair <string, string>("a[b]", "1"));

            Assert.False(FormUrlEncodedJson.TryParse(query, 2, out value), "Parse should have failed due to too high depth.");

            // This should succeed
            Assert.True(FormUrlEncodedJson.TryParse(query, 3, out value), "Expected non-null JsonObject instance");
            Assert.NotNull(value);
        }
Example #3
0
        void UseBufferedInputStream_Can_Be_Overridden()
        {
            // Arrange
            Mock <WebHostBufferPolicySelector> mockSelector = new Mock <WebHostBufferPolicySelector>();

            mockSelector.Setup((w) => w.UseBufferedInputStream(It.IsAny <HttpContextBase>())).Returns(false);
            Mock <HttpContextBase> mockContext = new Mock <HttpContextBase>()
            {
                CallBase = true
            };

            // Act & Assert
            Assert.False(mockSelector.Object.UseBufferedInputStream(mockContext.Object));
        }
        public void CanReadType_ReturnsExpectedValues(Type variationType, object testData)
        {
            TestJsonMediaTypeFormatter formatter = new TestJsonMediaTypeFormatter();

            bool isSerializable = IsTypeSerializableWithJsonSerializer(variationType, testData);
            bool canSupport     = formatter.CanReadTypeProxy(variationType);

            // If we don't agree, we assert only if the DCJ serializer says it cannot support something we think it should
            Assert.False(isSerializable != canSupport && isSerializable, String.Format("CanReadType returned wrong value for '{0}'.", variationType));

            // Ask a 2nd time to probe whether the cached result is treated the same
            canSupport = formatter.CanReadTypeProxy(variationType);
            Assert.False(isSerializable != canSupport && isSerializable, String.Format("2nd CanReadType returned wrong value for '{0}'.", variationType));
        }
Example #5
0
        public void UseDataContractJsonSerializer_False()
        {
            JsonMediaTypeFormatter xmlFormatter = new JsonMediaTypeFormatter {
                UseDataContractJsonSerializer = false
            };
            MemoryStream       memoryStream   = new MemoryStream();
            HttpContentHeaders contentHeaders = FormattingUtilities.CreateEmptyContentHeaders();

            Assert.Task.Succeeds(xmlFormatter.WriteToStreamAsync(typeof(XmlMediaTypeFormatterTests.SampleType), new XmlMediaTypeFormatterTests.SampleType(), memoryStream, contentHeaders, transportContext: null));
            memoryStream.Position = 0;
            string serializedString = new StreamReader(memoryStream).ReadToEnd();

            //Assert.True(serializedString.Contains("DataContractSampleType"),
            //    "SampleType should be serialized with data contract name DataContractSampleType because UseDataContractJsonSerializer is set to true.");
            Assert.False(serializedString.Contains("\r\n"), "Using JsonSerializer should emit data without indentation by default.");
        }
        public void UseXmlSerializer_False()
        {
            XmlMediaTypeFormatter xmlFormatter = new XmlMediaTypeFormatter {
                UseXmlSerializer = false
            };
            MemoryStream       memoryStream   = new MemoryStream();
            HttpContentHeaders contentHeaders = FormattingUtilities.CreateEmptyContentHeaders();

            Assert.Task.Succeeds(xmlFormatter.WriteToStreamAsync(typeof(SampleType), new SampleType(), memoryStream, contentHeaders, transportContext: null));
            memoryStream.Position = 0;
            string serializedString = new StreamReader(memoryStream).ReadToEnd();

            Assert.True(serializedString.Contains("DataContractSampleType"),
                        "SampleType should be serialized with data contract name DataContractSampleType because we're using DCS.");
            Assert.False(serializedString.Contains("version=\"1.0\" encoding=\"utf-8\""),
                         "Using DCS should not emit the xml declaration by default.");
            Assert.False(serializedString.Contains("\r\n"), "Using DCS should emit data without indentation by default.");
        }
Example #7
0
        public void Initialize_Default_Initializer_Can_Be_Removed()
        {
            // Arrange
            var config = new HttpConfiguration();

            config.Initializer = (c) => { };
            bool initializeCalled     = false;
            Mock <ITraceManager> mock = new Mock <ITraceManager>()
            {
                CallBase = true
            };

            mock.Setup(m => m.Initialize(config)).Callback(() => initializeCalled = true);
            config.Services.Replace(typeof(ITraceManager), mock.Object);

            // Act
            config.Initializer(config);

            // Assert
            Assert.False(initializeCalled);
        }
Example #8
0
        public void TryParseInt32_RejectsInvalidNumbers(string intValue)
        {
            int actualInt;

            Assert.False(FormattingUtilities.TryParseInt32(intValue, out actualInt));
        }
Example #9
0
        public void TryStringToDate_RejectsInvalidDates(string dateValue)
        {
            DateTimeOffset actualDate;

            Assert.False(FormattingUtilities.TryParseDate(dateValue, out actualDate));
        }
Example #10
0
        public void ValidateHeaderToken_RejectsInvalidTokens(string invalidToken)
        {
            bool result = FormattingUtilities.ValidateHeaderToken(invalidToken);

            Assert.False(result);
        }
 public void IsHttpResponseMessageContent(HttpContent notHttpMessageContent)
 {
     Assert.False(notHttpMessageContent.IsHttpResponseMessageContent());
 }
Example #12
0
 public void IsControllerType_RejectsInvalidControllerTypes(Type invalidControllerType)
 {
     Assert.False(DefaultHttpControllerTypeResolver.IsControllerType(invalidControllerType));
 }
        public void RegisterForDispose_WhenResourceParamterIsNull_DoesNothing()
        {
            _request.RegisterForDispose(resource: null);

            Assert.False(_request.Properties.ContainsKey(HttpPropertyKeys.DisposableRequestResourcesKey));
        }
Example #14
0
        public void CanReadType_ReturnsFalse_ForInvalidDataContracts()
        {
            XmlMediaTypeFormatter formatter = new XmlMediaTypeFormatter();

            Assert.False(formatter.CanReadType(typeof(InvalidDataContract)));
        }
        public void CanWriteType_ReturnsFalse_ForInvalidDataContracts()
        {
            JsonMediaTypeFormatter formatter = new DataContractJsonMediaTypeFormatter();

            Assert.False(formatter.CanWriteType(typeof(InvalidDataContract)));
        }
 public void IsHttpRequestMessageContentRespondsFalse(HttpContent notHttpMessageContent)
 {
     Assert.False(notHttpMessageContent.IsHttpRequestMessageContent());
 }
        public void FileExists(string path)
        {
            IBuildManager buildManager = new DefaultBuildManager();

            Assert.False(buildManager.FileExists(path));
        }