public void WriteListToDb() { var repository = new NHibernateRepository <Artist>(); NHibernateHelper.CreateDatabaseIfNeeded(); var testData = @"[{ ""Id"": 760, ""Name"": ""\""Weird Al\"" Yankovic"" }, { ""Id"": 3, ""Name"": "".38 Special"" }, { ""Id"": 1, ""Name"": ""3 Doors Down"" }]" ; var testObject = JSONToDatabaseReader.JSON.Serialization.Deserialize <List <Artist> >(testData); var resultingList = ReadJSONAndWriteToDb.FilterEnumerable(testObject, x => x.Name.Contains("3")); foreach (var item in resultingList) { repository.Save(item); } var nrOfArtists = repository.GetAll().Count; Assert.IsTrue(nrOfArtists == 2); }
public void MappingTest() { var testObject = new Artist { Id = 123, Name = "TestBoodschap" }; var repository = new NHibernateRepository <Artist>(); NHibernateHelper.CreateDatabaseIfNeeded(); repository.Save(testObject); var result = repository.Get(123); Assert.IsTrue(testObject == result); Assert.IsTrue(repository.GetAll().Count > 0); }
private NHibernateRepository <Song> Prepare() { var firstrun = !System.IO.File.Exists("test.db"); if (firstrun) { NHibernateHelper.CreateDatabaseIfNeeded(); var repository = new NHibernateRepository <Song>(); var filename = Configuration["JSONSongFile"]; var songlist = JSONToDatabaseReader.ReadJSONAndWriteToDb.ReadFile <List <Song> >(filename); var filteredsonglist = JSONToDatabaseReader.ReadJSONAndWriteToDb.FilterEnumerable(songlist, x => x.Genre.Contains("Metal") && x.Year < 2016); foreach (var item in filteredsonglist) { repository.Save(item); } return(repository); } return(new JSONToDatabaseReader.Repository.NHibernateRepository <Song>()); }