Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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