This file contains hidden or 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 class SQLiteEntity : IEntity | |
{ | |
[PrimaryKey, AutoIncrement] | |
public int Id { get; set; } | |
} |
This file contains hidden or 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 class ToDoItem : SQLiteEntity | |
{ | |
public string Title { get; set; } | |
public string Description { get; set; } | |
public ToDoItemState State { get; set; } | |
} |
This file contains hidden or 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 class MockRepository : IRepository<ToDoItem> | |
{ | |
private List<ToDoItem> _toDoItems { get; set; } | |
public MockRepository() | |
{ | |
_toDoItems = new List<ToDoItem>(); | |
_toDoItems.Add(new ToDoItem { Id = 1, Title = "Buy cat food", Description = "It's either that or be ambushed and gnawed" }); | |
_toDoItems.Add(new ToDoItem { Id = 2, Title = "Starch underwear", Description = "It ain't safe if it don't chafe" }); | |
_toDoItems.Add(new ToDoItem { Id = 3, Title = "Start retro girl band", Description = "Frauke and the courgettes" }); |
This file contains hidden or 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 class OverviewVM | |
{ | |
private MockRepository _toDoRepo; | |
public IEnumerable<ToDoItem> ToDoItems { get; set; } | |
public OverviewVM() | |
{ | |
_toDoRepo = new MockRepository(); | |
ToDoItems = _toDoRepo.GetAsync().Result; | |
} |
This file contains hidden or 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
using System; | |
using System.Reflection; | |
using System.Windows.Input; | |
using Xamarin.Forms; | |
namespace EventToCommandBehavior | |
{ | |
public class EventToCommandBehavior : BehaviorBase<View> | |
{ | |
Delegate eventHandler; |
This file contains hidden or 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
using System; | |
using Xamarin.Forms; | |
namespace EventToCommandBehavior | |
{ | |
public class BehaviorBase<T> : Behavior<T> where T : BindableObject | |
{ | |
public T AssociatedObject { get; private set; } | |
protected override void OnAttachedTo(T bindable) |
This file contains hidden or 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() | |
{ | |
ToDoItems = await _toDoRepo.GetAsync(); | |
} |
This file contains hidden or 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 partial class OverviewPage : ContentPage | |
{ | |
private OverviewVM _viewModel; | |
public OverviewPage() | |
{ | |
InitializeComponent(); | |
_viewModel = new OverviewVM(); | |
BindingContext = _viewModel; | |
} |
This file contains hidden or 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 class OverviewVM : ViewModelBase | |
{ | |
private MockRepository _toDoRepo; | |
private IEnumerable<ToDoItem> _toDoItems; | |
public IEnumerable<ToDoItem> ToDoItems | |
{ | |
get { return _toDoItems; } | |
set { Set(ref _toDoItems, value); } | |
} |
This file contains hidden or 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_loads_data_from_repository() | |
{ | |
// Arrange | |
OverviewVM vm = new OverviewVM(); | |
// Act | |
await vm.LoadData(); | |
// Assert |