public void ConstructorCreatesEmptyDictionaryIfControllerContextIsNull() {
            // Act
            ValueProviderDictionary dict = new ValueProviderDictionary(null);

            // Assert
            Assert.AreEqual(0, dict.Count);
        }
        public void CanBindMultipleSubscriptionWithWeightingTest()
        {
            var channelsManagementService =
                MockRepository.GenerateMock <IChannelManagementService>();

            channelsManagementService.Expect(x => x.Get(11)).Return(new Channel()
            {
                CategoryID = 11, ChannelName = "Arsenal", ChannelGUID = "ArsenalGUID"
            });
            channelsManagementService.Expect(x => x.Get(22)).Return(new Channel()
            {
                CategoryID = 22, ChannelName = "Leeds", ChannelGUID = "LeedsGUID"
            });
            var dict = new ValueProviderDictionary(null)
            {
                { "subscription", new ValueProviderResult(null, "11.30-Arsenal|22.40-Leeds", null) }
            };
            var bindingContext = new ModelBindingContext()
            {
                ValueProvider = dict
            };
            var binder    = new InsallerSetupBinder(channelsManagementService);
            var setupFile = (InstallerSetup)binder.BindModel(null, bindingContext);

            setupFile.GetSetupText().ShouldEqual("11,,ArsenalGUID,,Arsenal,,30\r\n22,,LeedsGUID,,Leeds,,40\r\n");
        }
예제 #3
0
        public void ConstructorCreatesEmptyDictionaryIfControllerContextIsNull()
        {
            // Act
            ValueProviderDictionary dict = new ValueProviderDictionary(null);

            // Assert
            Assert.Empty(dict);
        }
        public void ControllerContextProperty() {
            // Arrange
            ControllerContext expected = GetControllerContext();
            ValueProviderDictionary dict = new ValueProviderDictionary(expected);

            // Act
            ControllerContext returned = dict.ControllerContext;

            // Assert
            Assert.AreEqual(expected, returned);
        }
예제 #5
0
        public void ControllerContextProperty()
        {
            // Arrange
            ControllerContext       expected = GetControllerContext();
            ValueProviderDictionary dict     = new ValueProviderDictionary(expected);

            // Act
            ControllerContext returned = dict.ControllerContext;

            // Assert
            Assert.Equal(expected, returned);
        }
        public void AddWithRawValueUsesInvariantCulture() {
            // Arrange
            ValueProviderDictionary dict = new ValueProviderDictionary(null);

            // Act
            dict.Add("foo", 42);

            // Assert
            ValueProviderResult vpResult = dict["foo"];
            Assert.AreEqual("42", vpResult.AttemptedValue);
            Assert.AreEqual(42, vpResult.RawValue);
            Assert.AreEqual(CultureInfo.InvariantCulture, vpResult.Culture);
        }
예제 #7
0
        public void NullAndEmptyKeysAreIgnored()
        {
            // DevDiv Bugs #216667: Exception thrown when querystring contains name without value

            // Arrange
            ValueProviderDictionary dict = GetAndPopulateDictionary();

            // Act
            bool emptyKeyFound = dict.ContainsKey(String.Empty);

            // Assert
            Assert.False(emptyKeyFound);
        }
예제 #8
0
        public void AddWithRawValueUsesInvariantCulture()
        {
            // Arrange
            ValueProviderDictionary dict = new ValueProviderDictionary(null);

            // Act
            dict.Add("foo", 42);

            // Assert
            ValueProviderResult vpResult = dict["foo"];

            Assert.Equal("42", vpResult.AttemptedValue);
            Assert.Equal(42, vpResult.RawValue);
            Assert.Equal(CultureInfo.InvariantCulture, vpResult.Culture);
        }
예제 #9
0
        public void BindModelWithNonExistentValueReturnsNull() {
            // Arrange
            ValueProviderDictionary valueProvider = new ValueProviderDictionary(null) {
                { "foo", new ValueProviderResult(null, null, null) }
            };

            ModelBindingContext bindingContext = new ModelBindingContext() {
                ModelName = "foo",
                ValueProvider = valueProvider
            };

            LinqBinaryModelBinder binder = new LinqBinaryModelBinder();

            // Act
            object binderResult = binder.BindModel(null, bindingContext);

            // Assert
            Assert.IsNull(binderResult);
        }
예제 #10
0
        public void BinderWithEmptyStringValueReturnsNull() {
            // Arrange
            ValueProviderDictionary valueProvider = new ValueProviderDictionary(null) {
                { "foo", new ValueProviderResult(String.Empty, null, null) }
            };

            ModelBindingContext bindingContext = new ModelBindingContext() {
                ModelName = "foo",
                ValueProvider = valueProvider
            };

            ByteArrayModelBinder binder = new ByteArrayModelBinder();

            // Act
            object binderResult = binder.BindModel(null, bindingContext);

            // Assert
            Assert.IsNull(binderResult);
        }
예제 #11
0
        public void BindModelWithBase64QuotedValueReturnsBinary() {
            // Arrange
            string base64Value = ByteArrayModelBinderTest.Base64TestString;
            ValueProviderDictionary valueProvider = new ValueProviderDictionary(null) {
                { "foo", new ValueProviderResult("\"" + base64Value + "\"", "\"" + base64Value + "\"", null) }
            };

            ModelBindingContext bindingContext = new ModelBindingContext() {
                ModelName = "foo",
                ValueProvider = valueProvider
            };

            LinqBinaryModelBinder binder = new LinqBinaryModelBinder();

            // Act
            Binary boundValue = binder.BindModel(null, bindingContext) as Binary;

            // Assert
            Assert.AreEqual(ByteArrayModelBinderTest.Base64TestBytes, boundValue);
        }
예제 #12
0
        public void BindModelWithBase64UnquotedValueReturnsByteArray() {
            // Arrange
            string base64Value = Base64TestString;
            ValueProviderDictionary valueProvider = new ValueProviderDictionary(null) {
                { "foo", new ValueProviderResult(base64Value, base64Value, null) }
            };

            ModelBindingContext bindingContext = new ModelBindingContext() {
                ModelName = "foo",
                ValueProvider = valueProvider
            };

            ByteArrayModelBinder binder = new ByteArrayModelBinder();

            // Act
            byte[] boundValue = binder.BindModel(null, bindingContext) as byte[];

            // Assert
            CollectionAssert.AreEqual(Base64TestBytes, boundValue);
        }
예제 #13
0
        public void BindModelWithNonExistentValueReturnsNull()
        {
            // Arrange
            ValueProviderDictionary valueProvider = new ValueProviderDictionary(null)
            {
                { "foo", new ValueProviderResult(null, null, null) }
            };

            ModelBindingContext bindingContext = new ModelBindingContext()
            {
                ModelName     = "foo",
                ValueProvider = valueProvider
            };

            ByteArrayModelBinder binder = new ByteArrayModelBinder();

            // Act
            object binderResult = binder.BindModel(null, bindingContext);

            // Assert
            Assert.IsNull(binderResult);
        }
        public void BinderWithEmptyStringValueReturnsNull()
        {
            // Arrange
            ValueProviderDictionary valueProvider = new ValueProviderDictionary(null)
            {
                { "foo", new ValueProviderResult(String.Empty, null, null) }
            };

            ModelBindingContext bindingContext = new ModelBindingContext()
            {
                ModelName     = "foo",
                ValueProvider = valueProvider
            };

            LinqBinaryModelBinder binder = new LinqBinaryModelBinder();

            // Act
            object binderResult = binder.BindModel(null, bindingContext);

            // Assert
            Assert.IsNull(binderResult);
        }
        public void CanBindMultipleSubscriptionWithMultiWordNameTest()
        {
            var channelsManagementService =
                MockRepository.GenerateMock <IChannelManagementService>();

            channelsManagementService.Expect(x => x.Get(22)).Return(new Channel()
            {
                CategoryID = 22, ChannelName = "Leeds United", ChannelGUID = "LeedsGUID"
            });
            var dict = new ValueProviderDictionary(null)
            {
                { "subscription", new ValueProviderResult(null, "22-Leeds-United", null) }
            };
            var bindingContext = new ModelBindingContext()
            {
                ValueProvider = dict
            };
            var binder    = new InsallerSetupBinder(channelsManagementService);
            var setupFile = (InstallerSetup)binder.BindModel(null, bindingContext);

            setupFile.GetSetupText().ShouldEqual("22,,LeedsGUID,,Leeds United,,10\r\n");
        }
        public void BindModelWithBase64UnquotedValueReturnsBinary()
        {
            // Arrange
            string base64Value = ByteArrayModelBinderTest.Base64TestString;
            ValueProviderDictionary valueProvider = new ValueProviderDictionary(null)
            {
                { "foo", new ValueProviderResult(base64Value, base64Value, null) }
            };

            ModelBindingContext bindingContext = new ModelBindingContext()
            {
                ModelName     = "foo",
                ValueProvider = valueProvider
            };

            LinqBinaryModelBinder binder = new LinqBinaryModelBinder();

            // Act
            Binary boundValue = binder.BindModel(null, bindingContext) as Binary;

            // Assert
            Assert.AreEqual(ByteArrayModelBinderTest.Base64TestBytes, boundValue);
        }
예제 #17
0
        public void BindModelWithBase64QuotedValueReturnsByteArray()
        {
            // Arrange
            string base64Value = Base64TestString;
            ValueProviderDictionary valueProvider = new ValueProviderDictionary(null)
            {
                { "foo", new ValueProviderResult("\"" + base64Value + "\"", "\"" + base64Value + "\"", null) }
            };

            ModelBindingContext bindingContext = new ModelBindingContext()
            {
                ModelName     = "foo",
                ValueProvider = valueProvider
            };

            ByteArrayModelBinder binder = new ByteArrayModelBinder();

            // Act
            byte[] boundValue = binder.BindModel(null, bindingContext) as byte[];

            // Assert
            CollectionAssert.AreEqual(Base64TestBytes, boundValue);
        }