public void ItemsTest() { User.Kill(App.CurrentPath, "entries"); var u = User.Create(ApplicationType.Web, App.CurrentPath, "entries", "123"); var currency = new Currency(); currency.LongName = "Российский рубль"; currency.ShortName = "₽"; currency.Code = "RUB"; u.Save(currency); var accountType = new AccountType(); accountType.Name = "Сундук"; u.Save(accountType); var account = new Account(); account.Name = "Денежный счет items"; account.AccountTypeId = accountType.Id; account.CurrencyCode = currency.Code; u.Save(account); var cat = new Category(); cat.Name = "Главная статья доходов"; cat.CategoryType = EntryType.Income; cat.FontStyle = FontStyle.Bold; u.Save(cat); var items = new List<MoneyItem>(); var rnd = new Random(DateTime.Now.Millisecond); var date = DateTime.Now; for (int i = 1; i <= 100; i++) { var item = new MoneyItem(); item.AccountId = account.Id; item.Amount = rnd.Next(1000, Int32.MaxValue); item.EntryType = EntryType.Income; item.CategoryId = cat.Id; item.DateEntry = date; item.DateCreated = date; item.Description = "Вот такой вот доход!"; item.Title = String.Format("Запись #{0}", i); items.Add(item); } u.Save(items); for (int i = 1; i < 10; i++) { var list = u.GetMoneyItems(page: i, maxDataPerPage: 10); Assert.AreEqual(list[0].Id, 100 - ((i - 1) * 10)); Assert.AreEqual(list[0].Title, String.Format("Запись #{0}", 100 - ((i - 1) * 10))); } var list2 = u.GetMoneyItems(search: "Запись #50"); Assert.IsTrue(list2.Count == 1); u.Delete(items); // выборка по датам items = new List<MoneyItem>(); for (int i = -5; i <= 5; i++) { var entry = new MoneyItem(); entry.AccountId = account.Id; entry.Amount = rnd.Next(1000, Int32.MaxValue); entry.EntryType = EntryType.Income; entry.CategoryId = cat.Id; entry.DateEntry = DateTime.Now.AddDays(i); entry.Description = "Вот такой вот доход!"; entry.Title = String.Format("Запись #{0}", i); items.Add(entry); } u.Save(items); // выше от текущей даты list2 = u.GetMoneyItems(dateFrom: DateTime.Now); for (int i = 0; i <= 5; i++) { Assert.IsTrue(System.DateTime.Now.AddDays(i).Date.Subtract(list2[5 - i].DateEntry.Date).TotalSeconds == 0); } // до текущей даты list2 = u.GetMoneyItems(dateTo: DateTime.Now); for (int i = 0; i <= 5; i++) { Assert.IsTrue(System.DateTime.Now.AddDays(-i).Date.Subtract(list2[i].DateEntry.Date).TotalSeconds == 0); } // между двух дат list2 = u.GetMoneyItems(dateFrom: DateTime.Now.AddDays(-2), dateTo: DateTime.Now.AddDays(2)); Assert.IsTrue(System.DateTime.Now.Date.Subtract(list2[2].DateEntry.Date).TotalSeconds == 0); }
public void TestMethod1() { User.Kill(App.CurrentPath, "user"); var u = User.Create(ApplicationType.Desktop, App.CurrentPath, "user", "123"); var account = new Account(); account.Name = "Проверочный счет user"; Console.WriteLine("acc: {0}", u.Accounts.Count); u.Save(account); Assert.AreEqual(account.Id, 1); var deleted = u.Delete(account); Assert.AreEqual(deleted, 1); deleted = u.Delete(account); Assert.AreEqual(deleted, 0); var category = new Category(); category.Name = "Проверка"; category.ForeColor = Color.Red; category.BackColor = Color.Yellow; category.FontStyle = FontStyle.Bold | FontStyle.Italic; u.Save(category); Assert.AreEqual(u.Categories[1].ForeColor.ToArgb(), Color.Red.ToArgb()); Assert.AreEqual(u.Categories[1].BackColor.ToArgb(), Color.Yellow.ToArgb()); Assert.AreEqual(u.Categories[1].FontStyle, FontStyle.Bold | FontStyle.Italic); }