|
2 | 2 | {
|
3 | 3 | using System.Collections.Generic;
|
4 | 4 | using Microsoft.AspNetCore.Mvc.ModelBinding;
|
| 5 | + using Microsoft.AspNetCore.Routing; |
5 | 6 | using MyTested.AspNetCore.Mvc.Builders.Contracts.Models;
|
6 | 7 | using MyTested.AspNetCore.Mvc.Internal.TestContexts;
|
7 | 8 | using MyTested.AspNetCore.Mvc.Utilities.Extensions;
|
8 | 9 |
|
| 10 | + /// <summary> |
| 11 | + /// Used for building <see cref="ModelStateDictionary"/> |
| 12 | + /// </summary> |
9 | 13 | public class ModelStateBuilder : IAndModelStateBuilder
|
10 | 14 | {
|
| 15 | + /// <summary> |
| 16 | + /// Initializes a new instance of the <see cref="ModelStateBuilder"/> class. |
| 17 | + /// </summary> |
| 18 | + /// <param name="actionContext"><see cref="ModelStateDictionary"/> to build.</param> |
11 | 19 | public ModelStateBuilder(ActionTestContext actionContext)
|
12 | 20 | => this.ModelState = actionContext.ModelState;
|
13 | 21 |
|
| 22 | + /// <summary> |
| 23 | + /// Gets the <see cref="ModelStateDictionary"/> |
| 24 | + /// </summary> |
| 25 | + /// <value>The built <see cref="ModelStateDictionary"/></value> |
14 | 26 | protected ModelStateDictionary ModelState { get; set; }
|
15 | 27 |
|
| 28 | + /// <inheritdoc /> |
16 | 29 | public IAndModelStateBuilder WithError(string key, string errorMessage)
|
17 | 30 | {
|
18 | 31 | this.AddError(key, errorMessage);
|
19 | 32 | return this;
|
20 | 33 | }
|
21 | 34 |
|
| 35 | + /// <inheritdoc /> |
22 | 36 | public IAndModelStateBuilder WithErrors(IDictionary<string, string> errors)
|
23 | 37 | {
|
24 | 38 | errors.ForEach(err => this.AddError(err.Key, err.Value));
|
25 | 39 | return this;
|
26 | 40 | }
|
27 | 41 |
|
28 |
| - public IAndModelStateBuilder WithErrors(object erros) |
29 |
| - { |
30 |
| - return this; |
31 |
| - } |
| 42 | + /// <inheritdoc /> |
| 43 | + public IAndModelStateBuilder WithErrors(object errors) |
| 44 | + => this.WithErrors(new RouteValueDictionary(errors)); |
32 | 45 |
|
| 46 | + /// <inheritdoc /> |
33 | 47 | public IModelStateBuilder AndAlso() => this;
|
34 | 48 |
|
35 | 49 | private void AddError(string key, string errorMessage) => this.ModelState.AddModelError(key, errorMessage);
|
|
0 commit comments