Skip to content

Instantly share code, notes, and snippets.

@jkeam
Created July 15, 2022 15:14
Show Gist options
  • Save jkeam/7c8621ba3dffdc980682c080011bce10 to your computer and use it in GitHub Desktop.
Save jkeam/7c8621ba3dffdc980682c080011bce10 to your computer and use it in GitHub Desktop.
Validation tests to add for todo application, found here: https://github.com/jkeam/TodoList
// Snippet to add to TodoListTest/Tests.cs
[Test]
public void NotAllowCreateShortTodo()
{
using (var scope = testContext.Services.CreateScope())
{
var service = scope.ServiceProvider.GetRequiredService<IDbContextFactory<DatabaseContext>>();
using (var context = service.CreateDbContext())
{
Assert.AreEqual(1, context.Todos.ToList().Count);
var component = testContext.RenderComponent<TodoList.Pages.Todos>();
var inputField = component.Find("input");
inputField.Change("1");
component.Find("button[type=submit].new-todo").Click();
var todos = context.Todos.ToList();
Assert.AreEqual(1, todos.Count);
}
}
}
[Test]
public void NotAllowCreateLongTodo()
{
using (var scope = testContext.Services.CreateScope())
{
var service = scope.ServiceProvider.GetRequiredService<IDbContextFactory<DatabaseContext>>();
using (var context = service.CreateDbContext())
{
Assert.AreEqual(1, context.Todos.ToList().Count);
var component = testContext.RenderComponent<TodoList.Pages.Todos>();
var inputField = component.Find("input");
inputField.Change("012345678901234567890123456789012345678901234567890123456789");
component.Find("button[type=submit].new-todo").Click();
var todos = context.Todos.ToList();
Assert.AreEqual(1, todos.Count);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment