forked from aspnet/AspNetWebStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModelStateFormatterLoggerTest.cs
More file actions
42 lines (34 loc) · 1.5 KB
/
Copy pathModelStateFormatterLoggerTest.cs
File metadata and controls
42 lines (34 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Net.Http.Formatting;
using System.Web.Http.ModelBinding;
using Microsoft.TestCommon;
namespace System.Web.Http.Validation
{
public class ModelStateFormatterLoggerTest
{
[Fact]
public void LogErrorAddsErrorToModelState()
{
ModelStateDictionary modelState = new ModelStateDictionary();
string prefix = "prefix";
IFormatterLogger formatterLogger = new ModelStateFormatterLogger(modelState, prefix);
formatterLogger.LogError("property", "error");
Assert.True(modelState.ContainsKey("prefix.property"));
ModelError error = Assert.Single(modelState["prefix.property"].Errors);
Assert.Equal("error", error.ErrorMessage);
}
[Fact]
public void LogErrorAddsExceptionToModelState()
{
ModelStateDictionary modelState = new ModelStateDictionary();
string prefix = "prefix";
IFormatterLogger formatterLogger = new ModelStateFormatterLogger(modelState, prefix);
Exception e = new Exception("error");
formatterLogger.LogError("property", e);
Assert.True(modelState.ContainsKey("prefix.property"));
ModelError error = Assert.Single(modelState["prefix.property"].Errors);
Assert.Equal(e, error.Exception);
}
}
}