public void AddAndRemoveCatalogTest() { int int1 = repository.AddCatalog("Dune", "Frank Herbert"); int int2 = repository.AddCatalog("Krol", "Szczepan Twardoch"); Assert.AreEqual(repository.GetAllCatalogIds().Count, 2); repository.RemoveCatalog(int1); repository.RemoveCatalog(int2); Assert.AreEqual(repository.GetAllCatalogIds().Count, 0); }
public void TestCatalogModel() { LibraryRepository repository = new LibraryRepository(); ObservableCollection <CatalogModel> models = CatalogModel.GetCatalogs(); Assert.AreEqual(repository.GetAllCatalogIds().Count, models.Count); foreach (CatalogModel model in models) { Assert.IsTrue(repository.GetAllCatalogIds().Exists(id => id == model.Id)); } }
string IDataErrorInfo.this[string columnName] { get { List <int> availableIds = repository.GetAllCatalogIds(); switch (columnName) { case "IsBorrowed": if (string.IsNullOrEmpty(isBorrowed)) { return("IsBorrowed cannot be empty!"); } if (!bool.TryParse(isBorrowed, out bool parsedBool)) { return("That is not boolean value"); } break; case "CatalogId": if (string.IsNullOrEmpty(catalogId)) { return("CatalogId cannot be empty!"); } if (!Int32.TryParse(catalogId, out int parsedInt)) { return("That is not number value"); } if (!availableIds.Contains(parsedInt)) { return("That is not a proper Catalog ID"); } break; } ; return(null); } }
public static ObservableCollection <CatalogModel> GetCatalogs() { List <int> catalogIDs = new List <int>(); catalogIDs = repository.GetAllCatalogIds(); models = new ObservableCollection <CatalogModel>(); foreach (int id in catalogIDs) { models.Add(new CatalogModel(id, repository.GetCatalogTitle(id), repository.GetCatalogAuthor(id))); } return(models); }
string IDataErrorInfo.this[string columnName] { get { List <int> availableIds = repository.GetAllCatalogIds(); switch (columnName) { case "Id": if (string.IsNullOrEmpty(Id)) { return("CatalogId cannot be empty!"); } if (!Int32.TryParse(Id, out int parsedInt)) { return("That is not number value"); } if (!availableIds.Contains(parsedInt)) { return("That is not a proper Catalog ID"); } break; case "Title": if (string.IsNullOrEmpty(title)) { return("Title cannot be empty!"); } if (title.Length > 64) { return("Title cannot be that long"); } break; case "Author": if (string.IsNullOrEmpty(author)) { return("Author cannot be empty!"); } if (author.Length > 64) { return("Author cannot be that long"); } break; } ; return(null); } }