Skip to content

Instantly share code, notes, and snippets.

@FraukeN
Created June 15, 2018 21:19
Show Gist options
  • Save FraukeN/709cbae5e487e2fcbfd65de332bdda45 to your computer and use it in GitHub Desktop.
Save FraukeN/709cbae5e487e2fcbfd65de332bdda45 to your computer and use it in GitHub Desktop.
OverviewVM LoadData test with Moq
public async Task LoadData_loads_data_from_repository()
{
// Arrange
List<ToDoItem> toDoList = new List<ToDoItem>();
for (int i = 0; i < 5; i++)
{
toDoList.Add(new ToDoItem { Title = $"Item {i}" });
}
Mock<IRepository<ToDoItem>> repoMock = new Mock<IRepository<ToDoItem>>();
repoMock.Setup(repo => repo.GetAsync()).ReturnsAsync(toDoList);
OverviewVM vm = new OverviewVM(repoMock.Object);
// Act
await vm.LoadData();
// Assert
Assert.That(vm.ToDoItems.Count(), Is.EqualTo(5));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment