public void TestFilter() { var lst = new List <ToDo>(); lst.Add(new ToDo() { Id = 1, Text = "ccc", DueDate = new DateTime(2017, 5, 1), CreatedAt = new DateTime(2017, 4, 3), Completed = false }); lst.Add(new ToDo() { Id = 2, Text = "bbb", DueDate = new DateTime(2017, 5, 2), CreatedAt = new DateTime(2017, 4, 2), Completed = true }); lst.Add(new ToDo() { Id = 3, Text = "aaa", DueDate = new DateTime(2017, 5, 3), CreatedAt = new DateTime(2017, 4, 1), Completed = false }); var items = new ToDoFiltableCollection(lst); Assert.AreEqual(3, items.Count); // 完了を表示しない items.SetFilter(false, 0); Assert.AreEqual(2, items.Count); // 完了を表示する items.SetFilter(true, 0); Assert.AreEqual(3, items.Count); }
public void TestDueDateIsNull() { var lst = new List <ToDo>(); lst.Add(new ToDo() { Id = 1, Text = "aaa", DueDate = null, CreatedAt = new DateTime(2017, 4, 1), Completed = false }); var items = new ToDoFiltableCollection(lst); // シリアライズする var data = Newtonsoft.Json.JsonConvert.SerializeObject(items); System.Diagnostics.Debug.WriteLine(data); // 空白ではない Assert.AreNotEqual("", data); // デシリアライズする var newItems = Newtonsoft.Json.JsonConvert.DeserializeObject <ToDoFiltableCollection>(data); Assert.AreEqual(1, newItems.Count); Assert.AreEqual(1, newItems[0].Id); Assert.AreEqual("aaa", newItems[0].Text); Assert.AreEqual(null, newItems[0].DueDate); Assert.AreEqual(new DateTime(2017, 4, 1), newItems[0].CreatedAt); Assert.AreEqual(false, newItems[0].Completed); }
public void TestSaveXmlDueDateIsNull() { var lst = new List <ToDo>(); lst.Add(new ToDo() { Id = 1, Text = "aaa", DueDate = null, CreatedAt = new DateTime(2017, 4, 1), Completed = false }); var items = new ToDoFiltableCollection(lst); var xs = new System.Xml.Serialization.XmlSerializer(typeof(ToDoFiltableCollection)); var sw = new System.IO.StringWriter(); xs.Serialize(sw, items); var xml = sw.ToString(); var sr = new System.IO.StringReader(xml); var newItems = xs.Deserialize(sr) as ToDoFiltableCollection; Assert.AreEqual(1, newItems.Count); Assert.AreEqual(1, newItems[0].Id); Assert.AreEqual("aaa", newItems[0].Text); Assert.AreEqual(null, newItems[0].DueDate); Assert.AreEqual(new DateTime(2017, 4, 1), newItems[0].CreatedAt); Assert.AreEqual(false, newItems[0].Completed); }
public void TestSortByCreatedAt() { var lst = new List <ToDo>(); lst.Add(new ToDo() { Id = 1, Text = "ccc", DueDate = new DateTime(2017, 5, 3), CreatedAt = new DateTime(2017, 4, 1), Completed = false }); lst.Add(new ToDo() { Id = 2, Text = "bbb", DueDate = new DateTime(2017, 5, 1), CreatedAt = new DateTime(2017, 4, 2), Completed = true }); lst.Add(new ToDo() { Id = 3, Text = "aaa", DueDate = new DateTime(2017, 5, 2), CreatedAt = new DateTime(2017, 4, 3), Completed = false }); var items = new ToDoFiltableCollection(lst); // 作成日順にソートする items.SetFilter(true, 0); Assert.AreEqual(3, items.Count); // 新しい順にソートされる Assert.AreEqual("aaa", items[0].Text); Assert.AreEqual("bbb", items[1].Text); Assert.AreEqual("ccc", items[2].Text); }
public void TestSave() { var lst = new List <ToDo>(); lst.Add(new ToDo() { Id = 1, Text = "ccc", DueDate = new DateTime(2017, 5, 1), CreatedAt = new DateTime(2017, 4, 3), Completed = false }); lst.Add(new ToDo() { Id = 2, Text = "bbb", DueDate = new DateTime(2017, 5, 2), CreatedAt = new DateTime(2017, 4, 2), Completed = true }); lst.Add(new ToDo() { Id = 3, Text = "aaa", DueDate = new DateTime(2017, 5, 3), CreatedAt = new DateTime(2017, 4, 1), Completed = false }); var items = new ToDoFiltableCollection(lst); // シリアライズする var data = Newtonsoft.Json.JsonConvert.SerializeObject(items); // 空白ではない Assert.AreNotEqual("", data); // デシリアライズする var newItems = Newtonsoft.Json.JsonConvert.DeserializeObject <ToDoFiltableCollection>(data); Assert.AreEqual(3, newItems.Count); Assert.AreEqual(1, newItems[0].Id); Assert.AreEqual("ccc", newItems[0].Text); Assert.AreEqual(new DateTime(2017, 5, 1), newItems[0].DueDate); Assert.AreEqual(new DateTime(2017, 4, 3), newItems[0].CreatedAt); Assert.AreEqual(false, newItems[0].Completed); }
/// <summary> /// 内部ストレージから読み込み /// </summary> void Load() { var docs = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments); var file = System.IO.Path.Combine(docs, "save.xml"); if (System.IO.File.Exists(file)) { using (var st = System.IO.File.OpenRead(file)) { if (items == null) { items = new ToDoFiltableCollection(); } if (items.Load(st) == false) { // 失敗時には、初期データを作成する System.IO.File.Delete(file); // 初期データを作成する items = ToDoFiltableCollection.MakeSampleData(); } } } else { // 初期データを作成する items = ToDoFiltableCollection.MakeSampleData(); } }
/// <summary> /// 内部ストレージから読み込み /// </summary> void Load() { if (items == null) { items = new ToDoFiltableCollection(); } using (var st = storage.OpenReader("save.xml")) { if (st == null || items.Load(st) == false) { // 初期データを作成する var lst = new List <ToDo>(); lst.Add(new ToDo() { Id = 1, Text = "sample no.1", DueDate = new DateTime(2017, 5, 1), CreatedAt = new DateTime(2017, 3, 1) }); lst.Add(new ToDo() { Id = 2, Text = "sample no.2", DueDate = new DateTime(2017, 5, 3), CreatedAt = new DateTime(2017, 3, 2) }); lst.Add(new ToDo() { Id = 3, Text = "sample no.3", DueDate = new DateTime(2017, 5, 2), CreatedAt = new DateTime(2017, 3, 3) }); items = new ToDoFiltableCollection(lst); } } }
public void TestAdd1() { var lst = new List <ToDo>(); lst.Add(new ToDo() { Id = 1, Text = "ccc", DueDate = new DateTime(2017, 5, 3), CreatedAt = new DateTime(2017, 4, 1), Completed = false }); lst.Add(new ToDo() { Id = 2, Text = "bbb", DueDate = new DateTime(2017, 5, 1), CreatedAt = new DateTime(2017, 4, 2), Completed = true }); lst.Add(new ToDo() { Id = 3, Text = "aaa", DueDate = new DateTime(2017, 5, 2), CreatedAt = new DateTime(2017, 4, 3), Completed = false }); var items = new ToDoFiltableCollection(lst); // 作成日順にソートする items.SetFilter(true, 0); Assert.AreEqual(3, items.Count); Assert.AreEqual("aaa", items[0].Text); // 新しい項目を追加する items.Add(new ToDo() { Id = 100, Text = "new", DueDate = null, CreatedAt = new DateTime(2017, 5, 1), Completed = false }); // 追加した項目が先頭になる Assert.AreEqual(4, items.Count); Assert.AreEqual("new", items[0].Text); }
public override void ViewDidLoad() { base.ViewDidLoad(); // 内部ストレージから読み込み items = new ToDoFiltableCollection(); this.Load(); TableView.Source = new DataSource(this, items); }
/// <summary> /// 内部ストレージから読み込み /// </summary> void Load() { var items = new ToDoFiltableCollection(); using (var st = storage.OpenReader("save.xml")) { if (st == null || items.Load(st) == false) { // 初期データを作成する items = ToDoFiltableCollection.MakeSampleData(); } } viewModel.Items = items; }
public void TestCountIsZero() { var lst = new List <ToDo>(); var items = new ToDoFiltableCollection(lst); // シリアライズする var data = Newtonsoft.Json.JsonConvert.SerializeObject(items); System.Diagnostics.Debug.WriteLine(data); // 空白ではない Assert.AreNotEqual("", data); // デシリアライズする var newItems = Newtonsoft.Json.JsonConvert.DeserializeObject <ToDoFiltableCollection>(data); Assert.AreEqual(0, newItems.Count); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); // 内部ストレージから読み込み items = new ToDoFiltableCollection(); this.Load(); listview = FindViewById <ListView>(Resource.Id.listView); listview.Adapter = adapter = new TodoAdapter(this, items); listview.ItemClick += Listview_ItemClick; btnNew = FindViewById <Button>(Resource.Id.buttonNew); btnSetting = FindViewById <Button>(Resource.Id.buttonSetting); btnNew.Click += BtnNew_Click; btnSetting.Click += BtnSetting_Click; }
public void TestSaveStream() { var lst = new List <ToDo>(); lst.Add(new ToDo() { Id = 1, Text = "ccc", DueDate = new DateTime(2017, 5, 1), CreatedAt = new DateTime(2017, 4, 3), Completed = false }); lst.Add(new ToDo() { Id = 2, Text = "bbb", DueDate = new DateTime(2017, 5, 2), CreatedAt = new DateTime(2017, 4, 2), Completed = true }); lst.Add(new ToDo() { Id = 3, Text = "aaa", DueDate = new DateTime(2017, 5, 3), CreatedAt = new DateTime(2017, 4, 1), Completed = false }); var items = new ToDoFiltableCollection(lst); var sw = System.IO.File.OpenWrite("save.xml"); bool b = items.Save(sw); sw.Close(); Assert.AreEqual(true, b); /// 新しいコレクションを用意する var newItems = new ToDoFiltableCollection(); var sr = System.IO.File.OpenRead("save.xml"); b = newItems.Load(sr); sr.Close(); Assert.AreEqual(true, b); Assert.AreEqual(3, newItems.Count); Assert.AreEqual(1, newItems[0].Id); Assert.AreEqual("ccc", newItems[0].Text); Assert.AreEqual(new DateTime(2017, 5, 1), newItems[0].DueDate); Assert.AreEqual(new DateTime(2017, 4, 3), newItems[0].CreatedAt); Assert.AreEqual(false, newItems[0].Completed); System.IO.File.Delete("save.xml"); }
/// <summary> /// 内部ストレージから読み込み /// </summary> void Load() { var items = new ToDoFiltableCollection(); // .NET Standard 版では、 // Android/iOSのコードも、共有プロジェクトに書ける var docs = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments); var path = System.IO.Path.Combine(docs, "save.xml"); try { if (System.IO.File.Exists(path)) { var st = System.IO.File.OpenRead(path); if (items.Load(st) == false) { // 初期データを作成する items = ToDoFiltableCollection.MakeSampleData(); } } else { // 初期データを作成する items = ToDoFiltableCollection.MakeSampleData(); } } catch { // UWPを含める場合は従来通り DependencyService を使う using (var st = storage.OpenReader("save.xml")) { if (st == null || items.Load(st) == false) { // 初期データを作成する items = ToDoFiltableCollection.MakeSampleData(); } } } viewModel.Items = items; }
public void TestInit() { var items = new ToDoFiltableCollection(); Assert.AreEqual(0, items.Count); items.Add(new ToDo() { Id = 1, Text = "ccc", DueDate = new DateTime(2017, 5, 1), CreatedAt = new DateTime(2017, 4, 3) }); Assert.AreEqual(1, items.Count); items.Add(new ToDo() { Id = 2, Text = "bbb", DueDate = new DateTime(2017, 5, 2), CreatedAt = new DateTime(2017, 4, 2) }); Assert.AreEqual(2, items.Count); items.Add(new ToDo() { Id = 3, Text = "aaa", DueDate = new DateTime(2017, 5, 3), CreatedAt = new DateTime(2017, 4, 1) }); Assert.AreEqual(3, items.Count); var lst = new List <ToDo>(); lst.Add(new ToDo() { Id = 1, Text = "ccc", DueDate = new DateTime(2017, 5, 1), CreatedAt = new DateTime(2017, 4, 3) }); lst.Add(new ToDo() { Id = 2, Text = "bbb", DueDate = new DateTime(2017, 5, 2), CreatedAt = new DateTime(2017, 4, 2) }); lst.Add(new ToDo() { Id = 3, Text = "aaa", DueDate = new DateTime(2017, 5, 3), CreatedAt = new DateTime(2017, 4, 1) }); items = new ToDoFiltableCollection(lst); Assert.AreEqual(3, items.Count); }
public TodoAdapter(Activity act, ToDoFiltableCollection items) { _activity = act; _items = items; }
public DataSource(MasterViewController controller, ToDoFiltableCollection items) { this.controller = controller; this.items = items; }