2011-02-09 19:28:33 +00:00
|
|
|
|
using System;
|
2011-02-12 23:53:43 +00:00
|
|
|
|
using NHibernate;
|
2011-02-09 19:28:33 +00:00
|
|
|
|
using NHibernate.Cfg;
|
2011-02-09 00:05:32 +00:00
|
|
|
|
using NHibernate.Tool.hbm2ddl;
|
|
|
|
|
using NUnit.Framework;
|
2011-02-09 03:41:35 +00:00
|
|
|
|
using Portoa.NHibernate;
|
2011-02-09 00:05:32 +00:00
|
|
|
|
|
|
|
|
|
namespace VideoGameQuotes.Api.Tests.NHibernate {
|
2011-02-09 03:41:35 +00:00
|
|
|
|
[TestFixture, Ignore]
|
2011-02-09 00:05:32 +00:00
|
|
|
|
public class SchemaExporter {
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Export_schema() {
|
2011-02-09 03:41:35 +00:00
|
|
|
|
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]
|
2011-02-09 19:28:33 +00:00
|
|
|
|
public void Create_initial_data() {
|
2011-02-09 03:41:35 +00:00
|
|
|
|
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<User>(session).Save(admin);
|
|
|
|
|
tx.Commit();
|
|
|
|
|
}
|
2011-02-09 19:28:33 +00:00
|
|
|
|
|
2011-02-12 23:53:43 +00:00
|
|
|
|
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) };
|
2011-02-09 19:28:33 +00:00
|
|
|
|
|
|
|
|
|
using (var tx = session.BeginTransaction()) {
|
2011-02-12 23:53:43 +00:00
|
|
|
|
var repo = new NHibernateRepository<GamingSystem>(session);
|
2011-02-09 19:28:33 +00:00
|
|
|
|
repo.Save(nes);
|
2011-02-12 23:53:43 +00:00
|
|
|
|
repo.Save(fds);
|
2011-02-09 19:28:33 +00:00
|
|
|
|
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);
|
2011-02-12 23:53:43 +00:00
|
|
|
|
repo.Save(arcade);
|
|
|
|
|
repo.Save(tgfx);
|
2011-02-09 19:28:33 +00:00
|
|
|
|
tx.Commit();
|
|
|
|
|
}
|
2011-02-12 23:53:43 +00:00
|
|
|
|
#endregion
|
2011-02-09 00:05:32 +00:00
|
|
|
|
|
2011-02-12 23:53:43 +00:00
|
|
|
|
#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<Publisher>(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" };
|
|
|
|
|
|
|
|
|
|
using (var tx = session.BeginTransaction()) {
|
|
|
|
|
var repo = new NHibernateRepository<Category>(session);
|
|
|
|
|
repo.Save(engrish);
|
|
|
|
|
repo.Save(danger);
|
|
|
|
|
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<Game>(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 is dangerous to go alone." }
|
|
|
|
|
.AddCategory(danger)
|
|
|
|
|
.VoteFor(creator, VoteDirection.Up);
|
|
|
|
|
|
|
|
|
|
using (var tx = session.BeginTransaction()) {
|
|
|
|
|
var repo = new NHibernateRepository<Quote>(session);
|
|
|
|
|
repo.Save(allYourBase);
|
|
|
|
|
repo.Save(dangerousToGoAlone);
|
|
|
|
|
tx.Commit();
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
2011-02-09 00:05:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|