Exemplo n.º 1
0
        // ModelStateを取得
        public static ModelStateDictionary GetModelState(this ITempDataDictionary tempData)
        {
            var json = tempData[_modelStateKey] as string;

            if (string.IsNullOrWhiteSpace(json))
            {
                return(null);
            }

            return(ModelStateDictionaryJsonSerializer.Deserialize(json));
        }
        public void Deserialize_RawValueIsNull()
        {
            // Arrange
            // Act
            var modelStates = ModelStateDictionaryJsonSerializer.Deserialize(_jsonRawValueIsNull);

            // Assert
            Assert.Single(modelStates);

            var(key, modelState) = modelStates.First();
            Assert.Equal("k", key);

            Assert.Null(modelState.RawValue);

            Assert.Equal("a", modelState.AttemptedValue);

            Assert.Empty(modelState.Errors);
        }
        public void Deserialize_RawValueIsStringArray()
        {
            // Arrange
            // Act
            var modelStates = ModelStateDictionaryJsonSerializer.Deserialize(_jsonRawValueIsStringArray);

            // Assert
            Assert.Single(modelStates);

            var(key, modelState) = modelStates.First();
            Assert.Equal("k", key);

            Assert.IsType <string[]>(modelState.RawValue);
            var rawValues = modelState.RawValue as string[];

            Assert.Equal(2, rawValues.Length);
            Assert.Equal("r1", rawValues[0]);
            Assert.Equal("r2", rawValues[1]);

            Assert.Equal("a", modelState.AttemptedValue);

            Assert.Empty(modelState.Errors);
        }