Add integration and unit tests for Notes API with PostgreSQL-based test hosting configuration
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Freman.Sample.Web.Contracts;
|
||||
using Shouldly;
|
||||
|
||||
namespace Freman.Sample.Web.UnitTests.Contracts;
|
||||
|
||||
public class CreateNoteRequestTests
|
||||
{
|
||||
[Fact]
|
||||
public void CreateNoteRequest_EmptyText_IsInvalid()
|
||||
{
|
||||
var model = new CreateNoteRequest { Text = "" };
|
||||
|
||||
var results = Validate(model);
|
||||
|
||||
results.Count.ShouldBeGreaterThan(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CreateNoteRequest_TooLong_IsInvalid()
|
||||
{
|
||||
var model = new CreateNoteRequest { Text = new string('a', 501) };
|
||||
|
||||
var results = Validate(model);
|
||||
|
||||
results.Count.ShouldBeGreaterThan(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CreateNoteRequest_NormalText_IsValid()
|
||||
{
|
||||
var model = new CreateNoteRequest { Text = "hello" };
|
||||
|
||||
var results = Validate(model);
|
||||
|
||||
results.Count.ShouldBe(0);
|
||||
}
|
||||
|
||||
private static List<ValidationResult> Validate(object model)
|
||||
{
|
||||
var results = new List<ValidationResult>();
|
||||
var ctx = new ValidationContext(model);
|
||||
Validator.TryValidateObject(model, ctx, results, validateAllProperties: true);
|
||||
return results;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user