Exemplo n.º 1
0
        public void GetValueProvider_ContentTypeDoesNotStartsWithApplicationSlashJson_ReturnsNull()
        {
            _requestFake.Setup(x => x.ContentType).Returns("text/html");
            _httpContextBaseFake.Setup(x => x.Request).Returns(_requestFake.Object);

            var jsonDotNetValueProvider = new JsonDotNetValueProviderFactory().GetValueProvider(_controllerContext);

            Assert.IsNull(jsonDotNetValueProvider);
        }
Exemplo n.º 2
0
        public void GetValueProvider_InputStreamIsEmpty_ReturnsNull()
        {
            _requestFake.Setup(x => x.ContentType).Returns("application/json");
            _requestFake.Setup(x => x.InputStream).Returns(Stream.Null);
            _httpContextBaseFake.Setup(x => x.Request).Returns(_requestFake.Object);

            var jsonDotNetValueProvider = new JsonDotNetValueProviderFactory().GetValueProvider(_controllerContext);

            Assert.IsNull(jsonDotNetValueProvider);
        }
Exemplo n.º 3
0
        public void GetValueProvider_InputStreamContainsVaildJson_ReturnsCorrectlyMappedDictionaryValueProviderFromDeserializedJson()
        {
            using (var inputStream = new MemoryStream(Encoding.ASCII.GetBytes("{value1:'MyString',value2:100}")))
            {
                _requestFake.Setup(x => x.ContentType).Returns("application/json");
                _requestFake.Setup(x => x.InputStream).Returns(inputStream);
                _httpContextBaseFake.Setup(x => x.Request).Returns(_requestFake.Object);

                var jsonDotNetValueProvider = new JsonDotNetValueProviderFactory().GetValueProvider(_controllerContext);
                Assert.IsInstanceOf <DictionaryValueProvider <object> >(jsonDotNetValueProvider);
                Assert.AreEqual(jsonDotNetValueProvider.GetValue("value1").RawValue, "MyString");
                Assert.AreEqual(jsonDotNetValueProvider.GetValue("value2").RawValue, 100);
            }
        }
Exemplo n.º 4
0
 public void Activated()
 {
     JsonDotNetValueProviderFactory.RegisterFactory();
     ModelBinders.Binders.DefaultBinder = new EnumConverterModelBinder();
     FileUtil.CleanupUploadedImageStorage();
 }