using System; using NHibernate; using NHibernate.Cfg; using NHibernate.Tool.hbm2ddl; using NUnit.Framework; using Portoa.NHibernate; namespace VideoGameQuotes.Api.Tests.NHibernate { [TestFixture, Ignore] public class SchemaExporter { [Test] public void Export_schema() { new SchemaExport(GetConfig()) .SetDelimiter(";") .SetOutputFile(@"c:\users\tmont\code\VideoGameQuotes\Tests\VideoGameQuotes.Api.Tests\NHibernate\schema.sql") .Execute(false, true, false); } private Configuration GetConfig() { return new Configuration().Configure(GetType().Assembly, GetType().Namespace + ".hibernate.cfg.xml"); } [Test] public void Create_initial_data() { var config = GetConfig(); var admin = new User { Username = "admin", Group = UserGroup.Admin }; admin.ChangePassword("password"); var session = config.BuildSessionFactory().OpenSession(); using (var tx = session.BeginTransaction()) { new NHibernateRepository(session).Save(admin); tx.Commit(); } CreateInitialData(session, admin); } private static void CreateInitialData(ISession session, User creator) { #region systems var fds = new GamingSystem { Abbreviation = "FDS", Name = "Family Computer Disk System", ReleaseDate = new DateTime(1986, 2, 21) }; var nes = new GamingSystem { Abbreviation = "NES", Name = "Nintendo Entertainment System", ReleaseDate = new DateTime(1985, 10, 18) }; var snes = new GamingSystem { Abbreviation = "SNES", Name = "Super Nintendo Entertainment System", ReleaseDate = new DateTime(1991, 8, 23) }; var genny = new GamingSystem { Abbreviation = "Genesis", Name = "Sega Genesis", ReleaseDate = new DateTime(1989, 10, 14) }; var ps = new GamingSystem { Abbreviation = "PS", Name = "PlayStation", ReleaseDate = new DateTime(1995, 9, 9) }; var ps2 = new GamingSystem { Abbreviation = "PS2", Name = "PlayStation 2", ReleaseDate = new DateTime(2000, 3, 4) }; var xbox = new GamingSystem { Abbreviation = "Xbox", Name = "Xbox", ReleaseDate = new DateTime(2002, 2, 22) }; var n64 = new GamingSystem { Abbreviation = "N64", Name = "Nintendo 64", ReleaseDate = new DateTime(1996, 9, 29) }; var gcn = new GamingSystem { Abbreviation = "GCN", Name = "Nintendo GameCube", ReleaseDate = new DateTime(2001, 11, 18) }; var dc = new GamingSystem { Abbreviation = "DC", Name = "Dreamcast", ReleaseDate = new DateTime(1999, 9, 9) }; var wii = new GamingSystem { Abbreviation = "Wii", Name = "Wii", ReleaseDate = new DateTime(2006, 11, 19) }; var xbox360 = new GamingSystem { Abbreviation = "360", Name = "Xbox 360", ReleaseDate = new DateTime(2005, 11, 16) }; var ps3 = new GamingSystem { Abbreviation = "PS3", Name = "PlayStation 3", ReleaseDate = new DateTime(2006, 11, 17) }; var tgfx = new GamingSystem { Abbreviation = "TGfx", Name = "TurboGrafx-16 Entertainment SuperSystem", ReleaseDate = new DateTime(1989, 10, 29) }; var pc = new GamingSystem { Abbreviation = "PC", Name = "Personal Computer", ReleaseDate = new DateTime(1980, 1, 1) }; var gb = new GamingSystem { Abbreviation = "GB", Name = "Game Boy", ReleaseDate = new DateTime(1989, 7, 31) }; var gbc = new GamingSystem { Abbreviation = "GBC", Name = "Game Boy Color", ReleaseDate = new DateTime(1998, 11, 18) }; var gba = new GamingSystem { Abbreviation = "GBA", Name = "Game Boy Advance", ReleaseDate = new DateTime(2001, 6, 11) }; var nds = new GamingSystem { Abbreviation = "NDS", Name = "Nintendo DS", ReleaseDate = new DateTime(2004, 11, 21) }; var psp = new GamingSystem { Abbreviation = "PSP", Name = "PlayStation Portable", ReleaseDate = new DateTime(2005, 3, 24) }; var arcade = new GamingSystem { Abbreviation = "Arcade", Name = "Arcade", ReleaseDate = new DateTime(1966, 1, 1) }; using (var tx = session.BeginTransaction()) { var repo = new NHibernateRepository(session); repo.Save(nes); repo.Save(fds); repo.Save(snes); repo.Save(genny); repo.Save(ps); repo.Save(ps2); repo.Save(xbox); repo.Save(n64); repo.Save(gcn); repo.Save(dc); repo.Save(wii); repo.Save(xbox360); repo.Save(ps3); repo.Save(pc); repo.Save(gb); repo.Save(gbc); repo.Save(gba); repo.Save(nds); repo.Save(psp); repo.Save(arcade); repo.Save(tgfx); tx.Commit(); } #endregion #region publishers var nintendo = new Publisher { Name = "Nintendo", Website = "http://www.nintendo.com/" }; var snk = new Publisher { Name = "SNK", Website = "http://www.snkplaymoreusa.com/" }; var sega = new Publisher { Name = "Sega", Website = "http://www.sega.com/" }; var taito = new Publisher { Name = "Taito", Website = "http://www.taito.com/" }; var kaga = new Publisher { Name = "Kaga Create", Website = "http://www.kaga-create.co.jp/" }; using (var tx = session.BeginTransaction()) { var repo = new NHibernateRepository(session); repo.Save(nintendo); repo.Save(snk); repo.Save(sega); repo.Save(taito); repo.Save(kaga); tx.Commit(); } #endregion #region categories var engrish = new Category { Name = "Engrish" }; var danger = new Category { Name = "Danger" }; var smoke = new Category { Name = "Smoke" }; var dolphins = new Category { Name = "Dolphins" }; using (var tx = session.BeginTransaction()) { var repo = new NHibernateRepository(session); repo.Save(engrish); repo.Save(danger); repo.Save(smoke); repo.Save(dolphins); tx.Commit(); } #endregion #region games var loz = new Game { Creator = creator, Name = "The Legend of Zelda", Website = "http://www.zelda.com/", Region = Region.NorthAmerica | Region.Japan | Region.PAL } .AddSystem(nes) .AddSystem(gba) .AddSystem(gcn) .AddSystem(fds) .AddPublisher(nintendo); var crystalis = new Game { Creator = creator, Name = "Crystalis", Website = "http://en.wikipedia.org/wiki/Crystalis", Region = Region.Japan | Region.NorthAmerica } .AddSystem(nes) .AddSystem(gbc) .AddPublisher(snk) .AddPublisher(nintendo); var zeroWing = new Game { Creator = creator, Name = "Zero Wing", Website = "http://en.wikipedia.org/wiki/Zero_Wing", Region = Region.Japan | Region.Europe } .AddSystem(genny) .AddSystem(arcade) .AddSystem(tgfx) .AddPublisher(taito) .AddPublisher(kaga) .AddPublisher(sega); using (var tx = session.BeginTransaction()) { var repo = new NHibernateRepository(session); repo.Save(loz); repo.Save(crystalis); repo.Save(zeroWing); tx.Commit(); } #endregion #region quotes var allYourBase = new Quote { Creator = creator, Game = zeroWing, Text = "All your base are belong to us." } .AddCategory(engrish) .VoteFor(creator, VoteDirection.Up); var dangerousToGoAlone = new Quote { Creator = creator, Game = loz, Text = "It's dangerous to go alone! Take this." } .AddCategory(danger) .VoteFor(creator, VoteDirection.Up); var dodongo = new Quote { Creator = creator, Game = loz, Text = "Dodongo dislikes smoke." } .AddCategory(smoke); var hopOnMyBack = new Quote { Creator = creator, Game = crystalis, Text = "Please hop on my back. I'll take you wherever you like." } .AddCategory(dolphins); using (var tx = session.BeginTransaction()) { var repo = new NHibernateRepository(session); repo.Save(allYourBase); repo.Save(dangerousToGoAlone); repo.Save(hopOnMyBack); repo.Save(dodongo); tx.Commit(); } #endregion } } }