This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public OverviewPage() | |
{ | |
InitializeComponent(); | |
IRepository<ToDoItem> repo = SimpleIoc.Default.GetInstance<IRepository<ToDoItem>>(); | |
_viewModel = new OverviewVM(repo); | |
BindingContext = _viewModel; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public App() | |
{ | |
InitializeComponent(); | |
SimpleIoc.Default.Register<IRepository<ToDoItem>, MockRepository>(); | |
MainPage = new OverviewPage(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Test] | |
public async Task LoadData_sets_IsFaulted_to_true_if_LoadData_encounters_an_exception() | |
{ | |
// Arrange | |
Mock<IRepository<ToDoItem>> repoMock = new Mock<IRepository<ToDoItem>>(); | |
repoMock.Setup(repo => repo.GetAsync()).ThrowsAsync(new Exception()); | |
OverviewVM vm = new OverviewVM(repoMock.Object); | |
// Act |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public OverviewVM(IRepository<ToDoItem> toDoRepo) | |
{ | |
_toDoRepo = toDoRepo ?? throw new ArgumentNullException("toDoRepo"); | |
IsFaulted = false; | |
ErrorMessage = string.Empty; | |
} | |
public async Task LoadData() | |
{ | |
try |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private bool _isFaulted; | |
public bool IsFaulted | |
{ | |
get { return _isFaulted; } | |
set { Set(ref _isFaulted, value); } | |
} | |
private string _errorMessage; | |
public string ErrorMessage | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public OverviewPage() | |
{ | |
InitializeComponent(); | |
_viewModel = new OverviewVM(null); | |
BindingContext = _viewModel; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Test] | |
public void creating_a_new_instance_of_OverviewVM_with_null_repository_throws_ArgumentNullException() | |
{ | |
// Assert | |
Assert.That(() => new OverviewVM(null), | |
Throws.Exception | |
.TypeOf<ArgumentNullException>() | |
.With.Property("ParamName") | |
.EqualTo("toDoRepo")); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task LoadData_loads_data_from_repository() | |
{ | |
// Arrange | |
OverviewVM vm = new OverviewVM(new MockRepository()); | |
// Act | |
await vm.LoadData(); | |
// Assert | |
Assert.That(vm.ToDoItems.Count(), Is.EqualTo(3)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public OverviewVM(IRepository<ToDoItem> toDoRepo) | |
{ | |
_toDoRepo = toDoRepo ?? throw new ArgumentNullException("toDoRepo"); | |
} |
NewerOlder