Beispiel #1
0
        public async Task BindModelAsync_WithNullBindingContext_ShouldThrow()
        {
            var subject = new PropertyAmountModelBinder(this.divisibleConfig);

            await Assert.ThrowsAsync <ArgumentNullException>(
                "bindingContext",
                () => subject.BindModelAsync(null)
                );
        }
Beispiel #2
0
        public async Task BindModelAsync_NoSubmittedValue_ShouldFail()
        {
            // Arrange.
            var subject = new PropertyAmountModelBinder(this.divisibleConfig);

            this.context.ModelName.Returns("Amount");
            this.values.GetValue("Amount").Returns(ValueProviderResult.None);

            // Act.
            await subject.BindModelAsync(context);

            // Assert.
            Assert.False(context.Result.IsModelSet);
        }
Beispiel #3
0
        public async Task BindModelAsync_WithEmptySubmittedValue_ShouldFail(string value)
        {
            // Arrange.
            var subject = new PropertyAmountModelBinder(this.divisibleConfig);

            this.context.ModelName.Returns("Amount");
            this.values.GetValue("Amount").Returns(new ValueProviderResult(new[] { value }));

            // Act.
            await subject.BindModelAsync(context);

            // Assert.
            Assert.False(context.Result.IsModelSet);
            Assert.Equal(value, this.context.ModelState["Amount"].RawValue);
        }
Beispiel #4
0
        public async Task BindModelAsync_WithValidDivisibleValue_ShouldSuccess(string value, string expected)
        {
            // Arrange.
            var subject = new PropertyAmountModelBinder(this.divisibleConfig);

            this.context.ModelName.Returns("Amount");
            this.values.GetValue("Amount").Returns(new ValueProviderResult(new[] { value }));

            // Act.
            await subject.BindModelAsync(context);

            // Assert.
            var model = (PropertyAmount)context.Result.Model;

            Assert.True(context.Result.IsModelSet);
            Assert.Equal(expected, model.ToString(PropertyType.Divisible));
            Assert.Equal(value, this.context.ModelState["Amount"].RawValue);
        }