Skip to content

Commit 94f9a35

Browse files
author
hristo.h
committed
Added comments (#178)
1 parent 33a9ba3 commit 94f9a35

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

src/MyTested.AspNetCore.Mvc.ModelState/Builders/Contracts/Models/IModelStateBuilder.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,26 @@
77
/// </summary>
88
public interface IModelStateBuilder
99
{
10+
/// <summary>
11+
/// Adds an error to the built <see cref="Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary"/>
12+
/// </summary>
13+
/// <param name="key">Key to set as string.</param>
14+
/// <param name="errorMessage">Error message to set as string.</param>
15+
/// <returns></returns>
1016
IAndModelStateBuilder WithError(string key, string errorMessage);
1117

18+
/// <summary>
19+
/// Adds model state entries to the built <see cref="Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary"/>
20+
/// </summary>
21+
/// <param name="errors">Model state entries as dictionary.</param>
22+
/// <returns></returns>
1223
IAndModelStateBuilder WithErrors(IDictionary<string, string> errors);
1324

14-
IAndModelStateBuilder WithErrors(object erros);
25+
/// <summary>
26+
/// Adds model state entries to the built <see cref="Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary"/>
27+
/// </summary>
28+
/// <param name="errors">Model state entries as anonymous object.</param>
29+
/// <returns></returns>
30+
IAndModelStateBuilder WithErrors(object errors);
1531
}
1632
}

src/MyTested.AspNetCore.Mvc.ModelState/Builders/Models/ModelStateBuilder.cs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,48 @@
22
{
33
using System.Collections.Generic;
44
using Microsoft.AspNetCore.Mvc.ModelBinding;
5+
using Microsoft.AspNetCore.Routing;
56
using MyTested.AspNetCore.Mvc.Builders.Contracts.Models;
67
using MyTested.AspNetCore.Mvc.Internal.TestContexts;
78
using MyTested.AspNetCore.Mvc.Utilities.Extensions;
89

10+
/// <summary>
11+
/// Used for building <see cref="ModelStateDictionary"/>
12+
/// </summary>
913
public class ModelStateBuilder : IAndModelStateBuilder
1014
{
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>
1119
public ModelStateBuilder(ActionTestContext actionContext)
1220
=> this.ModelState = actionContext.ModelState;
1321

22+
/// <summary>
23+
/// Gets the <see cref="ModelStateDictionary"/>
24+
/// </summary>
25+
/// <value>The built <see cref="ModelStateDictionary"/></value>
1426
protected ModelStateDictionary ModelState { get; set; }
1527

28+
/// <inheritdoc />
1629
public IAndModelStateBuilder WithError(string key, string errorMessage)
1730
{
1831
this.AddError(key, errorMessage);
1932
return this;
2033
}
2134

35+
/// <inheritdoc />
2236
public IAndModelStateBuilder WithErrors(IDictionary<string, string> errors)
2337
{
2438
errors.ForEach(err => this.AddError(err.Key, err.Value));
2539
return this;
2640
}
2741

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));
3245

46+
/// <inheritdoc />
3347
public IModelStateBuilder AndAlso() => this;
3448

3549
private void AddError(string key, string errorMessage) => this.ModelState.AddModelError(key, errorMessage);

0 commit comments

Comments
 (0)