本文整理汇总了C#中ModelStateDictionary.Merge方法的典型用法代码示例。如果您正苦于以下问题:C# ModelStateDictionary.Merge方法的具体用法?C# ModelStateDictionary.Merge怎么用?C# ModelStateDictionary.Merge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ModelStateDictionary
的用法示例。
在下文中一共展示了ModelStateDictionary.Merge方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddModelstateErrors
public void AddModelstateErrors(ModelStateDictionary modelState)
{
if (_modelState != null && !_modelState.IsValid)
{
//TODO: This errors now and then.
modelState.Merge(_modelState);
}
}
示例2: Validate
public async Task<ModelStateDictionary> Validate(DefaultContext db, Controller controller, CancellationToken cancellationToken, bool isAdmin)
{
var modelStateDictionary = new ModelStateDictionary();
modelStateDictionary.Merge(await ValidateGoogleCredentialsJson(controller, cancellationToken));
UserProfile userProfile = UserProfileCache.GetDetail(db, UserId);
Currency[] currencies = CurrencyCache.GetIndex(db);
ValidateChangeClaAccessCurrency(userProfile, currencies, ref modelStateDictionary);
ValidateLyonessId(db, ref modelStateDictionary);
AddAdditionalInformation(userProfile, isAdmin);
FixAddress();
return modelStateDictionary;
}
示例3: MergeDoesNothingIfParameterIsNull
public void MergeDoesNothingIfParameterIsNull()
{
// Arrange
ModelStateDictionary fooDict = new ModelStateDictionary() { { "foo", new ModelState() } };
// Act
fooDict.Merge(null);
// Assert
Assert.Single(fooDict);
Assert.True(fooDict.ContainsKey("foo"));
}
示例4: MergeCopiesDictionaryEntries
public void MergeCopiesDictionaryEntries()
{
// Arrange
ModelStateDictionary fooDict = new ModelStateDictionary() { { "foo", new ModelState() } };
ModelStateDictionary barDict = new ModelStateDictionary() { { "bar", new ModelState() } };
// Act
fooDict.Merge(barDict);
// Assert
Assert.Equal(2, fooDict.Count);
Assert.Equal(barDict["bar"], fooDict["bar"]);
}
示例5: MergeDoesNothingIfParameterIsNull
public void MergeDoesNothingIfParameterIsNull()
{
// Arrange
var dictionary = new ModelStateDictionary() { { "foo", new ModelStateEntry() } };
// Act
dictionary.Merge(null);
// Assert
Assert.Single(dictionary);
Assert.True(dictionary.ContainsKey("foo"));
}
示例6: MergeCopiesDictionaryEntries
public void MergeCopiesDictionaryEntries()
{
// Arrange
var dictionary1 = new ModelStateDictionary { { "foo", new ModelStateEntry() } };
var dictionary2 = new ModelStateDictionary { { "bar", new ModelStateEntry() } };
// Act
dictionary1.Merge(dictionary2);
// Assert
Assert.Equal(2, dictionary1.Count);
Assert.Equal(dictionary2["bar"], dictionary1["bar"]);
}
示例7: MergeCopiesDictionaryOverwritesExistingValues
public void MergeCopiesDictionaryOverwritesExistingValues(string key)
{
// Arrange
var dictionary1 = new ModelStateDictionary();
dictionary1.SetModelValue(key, "RawValue1", "AttemptedValue1");
dictionary1.AddModelError(key, "value1-Error1");
dictionary1.AddModelError(key, "value1-Error2");
dictionary1.SetModelValue("other-key", null, null);
var dictionary2 = new ModelStateDictionary();
dictionary2.SetModelValue(key, "RawValue2", "AttemptedValue2");
dictionary2.AddModelError(key, "value2-Error1");
// Act
dictionary1.Merge(dictionary2);
// Assert
Assert.Equal(2, dictionary1.Count);
var item = dictionary1["other-key"];
Assert.Null(item.AttemptedValue);
Assert.Null(item.RawValue);
Assert.Empty(item.Errors);
item = dictionary1[key];
Assert.Equal("AttemptedValue2", item.AttemptedValue);
Assert.Equal("RawValue2", item.RawValue);
Assert.Collection(item.Errors,
error => Assert.Equal("value2-Error1", error.ErrorMessage));
}
示例8: MergeCopiesDictionaryEntries
public void MergeCopiesDictionaryEntries()
{
// Arrange
var dictionary1 = new ModelStateDictionary();
dictionary1.SetModelValue("foo", "RawValue1", "AttemptedValue1");
dictionary1.AddModelError("foo", "value1-Error1");
dictionary1.AddModelError("foo", "value1-Error2");
var dictionary2 = new ModelStateDictionary();
dictionary2.SetModelValue("bar", "RawValue2", "AttemptedValue2");
dictionary2.AddModelError("bar", "value2-Error1");
// Act
dictionary1.Merge(dictionary2);
// Assert
Assert.Equal(2, dictionary1.Count);
var item = dictionary1["foo"];
Assert.Equal("AttemptedValue1", item.AttemptedValue);
Assert.Equal("RawValue1", item.RawValue);
item = dictionary1["bar"];
Assert.Equal("AttemptedValue2", item.AttemptedValue);
Assert.Equal("RawValue2", item.RawValue);
Assert.Collection(item.Errors,
error => Assert.Equal("value2-Error1", error.ErrorMessage));
}