public void Equals() { Playlist p1 = new Playlist("p"); Playlist p2 = new Playlist("p"); Assert.AreEqual(p1, p2); }
public void can_initialise() { Playlist playlist = new Playlist("playlist"); Track track0 = new Track( new Autor("autor"), new Bpm(null), new Code("12345"), new Interpret("interpret"), new Label("label"), new Laenge("04:30"), new Titel("titel__0"), new Verlag("verlag"), new Year(null), new Ending(Ending.Attribute.None) ); track0.addEinsatz(new Einsatz(playlist, track0)); string queryID = "1"; IList<Einsatz> einsaetze = new List<Einsatz>(new Einsatz[] { track0.Einsaetze[0]}); Expect.Once.On(view).GetProperty("QueryId").Will(Return.Value(queryID)); Expect.Once.On(dao).Method("GetById").WithAnyArguments().Will(Return.Value(track0)); Expect.Once.On(view).SetProperty("Entity").To(track0); Expect.Once.On(view).SetProperty("Einsaetze").To(einsaetze); this.presenter.initialise(); }
public static IList<Track> getTracks(Playlist p) { IList<Track> tracks = new List<Track>(); foreach(Einsatz einsatz in p.Einsaetze) tracks.Add(einsatz.Track); return tracks; }
public void un_Equals() { Playlist p1 = new Playlist("p1"); Playlist p2 = new Playlist("p2"); Assert.AreNotEqual(p1, null); Assert.AreNotEqual(p2, null); Assert.AreNotEqual(p1, p2); }
public static IList<Einsatz> getEinsaetze(string path, Playlist playlist) { Check.Require( new NHibernateDaoFactory().getPlaylistDao().GetUniqueByExample(playlist, Playlist.Property.Description.ToString(), Playlist.Property.IsClosed.ToString(), Playlist.Property.Sendetermin.ToString()) == null, String.Format( "A {0} entity '{1}' does already exist.", playlist.GetType().Name, playlist.Name)); object template = path; object isNewTemplate = false; object documentType = WdNewDocumentType.wdNewBlankDocument; object isVisible = false; Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application(); Microsoft.Office.Interop.Word.Document doc = app.Documents.Add(ref template, ref isNewTemplate, ref documentType, ref isVisible); Check.Require(doc.Tables[1].Tables.Count < 2, "Undefined word template."); IList<Einsatz> einsaetze = new List<Einsatz>(); if(doc.Tables[1].Tables.Count == 0 && doc.Tables[1].Rows[1].Cells.Count == 4) { einsaetze = FileUpload_Service.readMdrFormat(doc, playlist); } else if(doc.Tables[1].Tables.Count == 0 && doc.Tables[1].Rows[1].Cells.Count == 7) { einsaetze = FileUpload_Service.readOldFormat(doc, playlist); } else if(doc.Tables[1].Tables.Count == 1) { Check.Require(doc.Tables[1].Rows[1].Cells[1].Range.Text.StartsWith("Titel"), String.Format( "New format: row should start with 'Titel' but starts with {0}.", doc.Tables[1].Rows[1].Cells[1].Range.Text.Substring(0, 10))); Check.Require(doc.Tables[1].Rows[1].Cells.Count == 1, String.Format( "New format: column number should be 1 but is {0}.", doc.Tables[1].Rows[1].Cells.Count)); Check.Require(doc.Tables[1].Rows[2].Cells[1].Range.Text.StartsWith("Musiktitel"), String.Format( "New format: row should start with 'Musiktitel' but starts with {0}.", doc.Tables[1].Rows[2].Cells[1].Range.Text.Substring(0, 10))); Check.Require(doc.Tables[1].Rows[3].Cells.Count == 7, String.Format( "New format: column number should be 7 but is {0}.", doc.Tables[1].Rows[3].Cells.Count)); einsaetze = FileUpload_Service.readNewFormat(doc, playlist); } else if(doc.Tables.Count == 2 && doc.Tables[1].Rows[1].Cells.Count == 3) { einsaetze = FileUpload_Service.readShortFormat(doc, playlist); } else { throw new PreconditionException("Unknown playlist format."); } object SaveChanges = WdSaveOptions.wdDoNotSaveChanges; object OriginalFormat = WdOriginalFormat.wdWordDocument; object RouteDocument = true; ((Microsoft.Office.Interop.Word.Application)app).Quit(ref SaveChanges, ref OriginalFormat, ref RouteDocument); return einsaetze; }
/// <remarks> /// Kann nicht der ganzer scheiss so behandelt werden, das wirklich erst am Ende der Session, quasi explicit, /// DB-Synchronisierung erfolgt? Was mein' ich bloss... /// </remarks> /// @todo Warum Einsatz saven? Nicht testbar public static void insertAt( int position, Track track, Playlist playlist ) { if(playlist.Einsaetze.count < 1 || position < 1 || position > playlist.Einsaetze.count + 1) { Playlist_Service.append( track, playlist ); return; } Einsatz einsatz = new Einsatz(playlist, track, position ); //einsatz = new NHibernateDaoFactory().getEinsatzDao().save(einsatz); playlist.Einsaetze.insert( position - 1, einsatz ); Playlist_Service.updatePositions( playlist ); }
public static void persist(Playlist playlist, IList<Einsatz> einsaetze) { NHibernateDaoFactory daoFactory = new NHibernateDaoFactory(); IPlaylistDao playlistDao = daoFactory.getPlaylistDao(); ITrackDao trackDao = daoFactory.getTrackDao(); IEinsatzDao einsatzDao = daoFactory.getEinsatzDao(); playlistDao.save(playlist); foreach(Einsatz einsatz in einsaetze) { einsatz.Track = trackDao.save(einsatz.Track); einsatzDao.save(einsatz); } }
private void process( HttpPostedFile file ) { string path = this.Server.MapPath(UPLOAD_DIR) + Path.GetFileName(file.FileName); file.SaveAs( path ); Playlist playlist = new Playlist(Regex.Replace(Path.GetFileName(file.FileName), @"\.doc", String.Empty)); IList<Einsatz> einsaetze = FileUpload_Service.getEinsaetze(path, playlist); playlist.IsClosed = true; playlist.Sendetermin = this.dateTimeTryParse(file.FileName); FileUpload_Service.persist(playlist, einsaetze); this.lblMessage.ForeColor = Color.Green; lblMessage.Text += String.Format("'{0}' uploaded.", file.FileName); }
public void initialise_trackNumber_eq_0() { string cmd = "insert into Playlist(Id, Name) values(1, 'x')"; new SQLiteCommand(cmd, this.conn).ExecuteNonQuery(); Playlist p = new Playlist("x"); new DomainObjectIdSetter().SetIdOf(p, 1L); using(mocks.Record()) { Expect.Call<String>(this.view.QueryId).Return("1"); this.view.Tracks = new List<Track>(); this.view.Playlist = p; } using(mocks.Playback()) { presenter.initialise(); } }
public void cant_load_playlist_newFormat() { object template = BB080627; object isNewTemplate = false; object documentType = WdNewDocumentType.wdNewBlankDocument; object isVisible = false; Microsoft.Office.Interop.Word.ApplicationClass app = new Microsoft.Office.Interop.Word.ApplicationClass(); Microsoft.Office.Interop.Word.Document doc = app.Documents.Add(ref template, ref isNewTemplate, ref documentType, ref isVisible); Playlist playlist = new Playlist("x"); IList<Einsatz> einsaetze = new List<Einsatz>(); for(int i = 3; i <= doc.Tables[1].Rows.Count - 1; i++) { Row row = doc.Tables[1].Rows[i]; Track track = new Track( new Autor(" "), new Bpm(null), new Code(init(brush(row.Cells[4].Range.Text))), new Interpret(init(brush(row.Cells[5].Range.Text))), new Label(init(brush(row.Cells[3].Range.Text))), new Laenge(init(brush(row.Cells[7].Range.Text))), new Titel(init(brush(row.Cells[1].Range.Text))), new Verlag(" "), new Year(null), new Ending(Ending.Attribute.None)); einsaetze.Add(new Einsatz(playlist, track, row.Index - 2)); } /* * One dataset is actually missing. */ Assert.AreNotEqual(doc.Tables[1].Rows.Count - 2, einsaetze.Count); /* * Do throw PostconditionException! */ Check.Ensure(doc.Tables[1].Rows.Count - 2 == einsaetze.Count, String.Format("Playlist unvollstaendig! Lesbare Datensaezte: {0} von {1}.", einsaetze.Count, doc.Tables[1].Rows.Count - 2)); }
/// <summary> /// Change positions. /// </summary> /// <param name="position1">A positiv integer, not a zero based index!</param> /// <param name="position2">A positiv integer, not a zero based index!</param> public static void switchPositions( int position1, int position2, Playlist playlist ) { if(position1 == position2) { return; } if( position1 < 1 || position2 < 1 || position1 > playlist.Einsaetze.count || position2 > playlist.Einsaetze.count) { return; } // impossible action int index1 = position1 - 1; int index2 = position2 - 1; Track track1 = playlist.Einsaetze[index1].Track; Track track2 = playlist.Einsaetze[index2].Track; if( track1.Equals( track2 ) ) { return; } playlist.Einsaetze[index1].Track = track2; playlist.Einsaetze[index2].Track = track1; Playlist_Service.updatePositions( playlist ); }
public void initialise() { Track t = new Track( new Autor("autor"), new Bpm(null), new Code("12345"), new Interpret("interpret"), new Label("label"), new Laenge("04:30"), new Titel("titel"), new Verlag("verlag"), new Year(null), new Ending(Ending.Attribute.None) ); new DomainObjectIdSetter().SetIdOf(t, 1L); IList<Track> tracks = new List<Track>(1); tracks.Add(t); string cmd = @" insert into Track values(1,1,1,1,1,1,1,1,1,1,1); insert into Playlist(Id, Name) values(1,'p'); insert into Einsatz values(1,1,1,1); "; new SQLiteCommand(cmd, this.conn).ExecuteNonQuery(); Playlist p = new Playlist("x"); new DomainObjectIdSetter().SetIdOf(p, 1L); using(mocks.Record()) { Expect.Call<String>(this.view.QueryId).Return("1"); this.view.Tracks = tracks; this.view.Playlist = p; } using(mocks.Playback()) { presenter.initialise(); } }
public void runBeforTest() { track0 = new Track( new Autor("autor"), new Bpm(null), new Code("12345"), new Interpret("interpret"), new Label("label"), new Laenge("04:30"), new Titel("titel__0"), new Verlag("verlag"), new Year(null), new Ending(Ending.Attribute.None) ); track1 = new Track( new Autor("autor"), new Bpm(null), new Code("12345"), new Interpret("interpret"), new Label("label"), new Laenge("04:30"), new Titel("titel__1"), new Verlag("verlag"), new Year(null), new Ending(Ending.Attribute.None) ); track2 = new Track( new Autor("autor"), new Bpm(null), new Code("12345"), new Interpret("interpret"), new Label("label"), new Laenge("04:30"), new Titel("titel__2"), new Verlag("verlag"), new Year(null), new Ending(Ending.Attribute.None) ); playlist = new Playlist( "playlist" ); }
public void load_playlist_oldFormat() { string path = BB080111; object template = path; object isNewTemplate = false; object documentType = 0; object isVisible = false; Microsoft.Office.Interop.Word.ApplicationClass app = new Microsoft.Office.Interop.Word.ApplicationClass(); Microsoft.Office.Interop.Word.Document doc = app.Documents.Add(ref template, ref isNewTemplate, ref documentType, ref isVisible); Playlist playlist = new Playlist("blah"); IList<Einsatz> einsaetze = new List<Einsatz>(doc.Tables[1].Rows.Count); foreach(Row row in doc.Tables[1].Rows) { Track track = new Track( new Autor(init(brush(row.Cells[1].Range.Text))), new Bpm(null), new Code(init(brush(row.Cells[2].Range.Text))), new Interpret(init(brush(row.Cells[3].Range.Text))), new Label(init(brush(row.Cells[4].Range.Text))), new Laenge(init(brush(row.Cells[5].Range.Text))), new Titel(init(brush(row.Cells[6].Range.Text))), new Verlag(init(brush(row.Cells[7].Range.Text))), new Year(null), new Ending(Ending.Attribute.None)); einsaetze.Add(new Einsatz(playlist, track, row.Index)); } Assert.AreEqual(doc.Tables[1].Rows.Count, einsaetze.Count); object saveChanges = false; object originalFormat = false; object routeDocument = false; app.Quit(ref saveChanges, ref originalFormat, ref routeDocument); }
protected void Page_Load( object sender, EventArgs e ) { this.playlist = ((IPlaylistBody)this.Page).getPlaylist(false); }
public void can_distinguish_playlist_format() { string path_oldPlaylist = @"C:\Development\VS2005\projects\Gema.trunk\tanzer.gema.test\service\BB080627.old.format.doc"; string path_newPlaylist = @"C:\Development\VS2005\projects\Gema.trunk\tanzer.gema.test\service\BB080627.new.format.doc"; string path_newestPlaylist = @"C:\Development\VS2005\projects\Gema.trunk\tanzer.gema.test\service\BB080711.doc"; string path_shortList = @"C:\Development\VS2005\projects\Gema.trunk\tanzer.gema.test\service\BB080829.doc"; object oldTemplate = path_oldPlaylist; object newTemplate = path_newPlaylist; object newestTemplate = path_newestPlaylist; object shortList = path_shortList; object isNewTemplate = false; object documentType = WdNewDocumentType.wdNewBlankDocument; object isVisible = false; Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application(); Microsoft.Office.Interop.Word.Document doc = app.Documents.Add(ref oldTemplate, ref isNewTemplate, ref documentType, ref isVisible); //Word.Document doc = app.Documents.Add(ref newTemplate, ref isNewTemplate, ref documentType, ref isVisible); //Word.Document doc = app.Documents.Add(ref newestTemplate, ref isNewTemplate, ref documentType, ref isVisible); //Word.Document doc = app.Documents.Add(ref shortList, ref isNewTemplate, ref documentType, ref isVisible); Playlist playlist = new Playlist("BB080627"); Check.Require( new NHibernateDaoFactory().getPlaylistDao().GetUniqueByExample(playlist, Playlist.Property.Description.ToString(), Playlist.Property.IsClosed.ToString(), Playlist.Property.Sendetermin.ToString()) == null, String.Format("A {0} entity '{1}' does already exist.", playlist.GetType().Name, playlist.Name)); Check.Require(doc.Tables[1].Tables.Count < 2, "Undefined word template."); IList<Einsatz> einsaetze = new List<Einsatz>(); if(doc.Tables[1].Tables.Count == 0 && doc.Tables[1].Rows[1].Cells.Count == 4) { /* * neuer MDR Vordruck, wie auch immer die Burchen den hergestellt haben... * * Zeilen 1-3 Metadaten * Zeile 4 Column Names * ab Zeile 5 Daten */ einsaetze = this.readMdrFormat(doc, playlist); } else if(doc.Tables[1].Tables.Count == 0 && doc.Tables[1].Rows[1].Cells.Count == 7) { /* * alter Vordruck * * ab Zeile 1 Daten ( Metadaten und Column Names in separater Kopfzeile) */ einsaetze = this.readOldFormat(doc, playlist); } else if(doc.Tables[1].Tables.Count == 1) { /* * neues, eigens Format */ Check.Require(doc.Tables[1].Rows[1].Cells[1].Range.Text.StartsWith("Titel"), String.Format( "New format: row should start with 'Titel' but starts with {0}.", doc.Tables[1].Rows[1].Cells[1].Range.Text.Substring(0, 10))); Check.Require(doc.Tables[1].Rows[1].Cells.Count == 1, String.Format( "New format: column number should be 1 but is {0}.", doc.Tables[1].Rows[1].Cells.Count)); Check.Require(doc.Tables[1].Rows[2].Cells[1].Range.Text.StartsWith("Musiktitel"), String.Format( "New format: row should start with 'Musiktitel' but starts with {0}.", doc.Tables[1].Rows[2].Cells[1].Range.Text.Substring(0, 10))); Check.Require(doc.Tables[1].Rows[3].Cells.Count == 7, String.Format( "New format: column number should be 7 but is {0}.", doc.Tables[1].Rows[3].Cells.Count)); einsaetze = this.readNewFormat(doc, playlist); } else if( doc.Tables.Count == 2 && doc.Tables[1].Rows[1].Cells.Count == 3) { /* * short Format * */ einsaetze = this.readShortFormat(doc, playlist); } else { throw new PreconditionException("Unknown playlist format."); } foreach(Einsatz einsatz in einsaetze ) Console.WriteLine("{0}:{1}:{2}:{3}:{4}:{5}:{6}:{7}:{8}:{9}", einsatz.Track.Autor.Name, einsatz.Track.Bpm.ValueAsString, einsatz.Track.Code.Name, einsatz.Track.Interpret.Name, einsatz.Track.Label.Name, einsatz.Track.Laenge.Dauer, einsatz.Track.Titel.Name, einsatz.Track.Verlag.Name, einsatz.Track.Year.ValueAsString, einsatz.Track.Ending.EndingAsString); this.persist(playlist, einsaetze); object SaveChanges = WdSaveOptions.wdDoNotSaveChanges; object OriginalFormat = WdOriginalFormat.wdWordDocument; object RouteDocument = true; ((Microsoft.Office.Interop.Word.Application)app).Quit(ref SaveChanges, ref OriginalFormat, ref RouteDocument); }
/* * neues, eigenes Gema-Format */ private static IList<Einsatz> readNewFormat(Microsoft.Office.Interop.Word.Document doc, Playlist playlist) { IList<Einsatz> einsaetze = new List<Einsatz>(doc.Tables[1].Rows.Count - 2); for(int i = 3; i <= doc.Tables[1].Rows.Count; i++) { Row row = doc.Tables[1].Rows[i]; Track track = new Track( new Autor(" "), new Bpm(null), new Code(init(brush(row.Cells[4].Range.Text))), new Interpret(init(brush(row.Cells[5].Range.Text))), new Label(init(brush(row.Cells[3].Range.Text))), new Laenge(init(brush(row.Cells[7].Range.Text))), new Titel(init(brush(row.Cells[1].Range.Text))), new Verlag(" "), new Year(null), new Ending(Ending.Attribute.None)); einsaetze.Add(new Einsatz(playlist, track, row.Index - 2)); } Check.Ensure(doc.Tables[1].Rows.Count - 2 == einsaetze.Count, String.Format( "Playlist unvollstaendig! Lesbare Datensaezte: {0} von {1}.", einsaetze.Count, doc.Tables[1].Rows.Count - 2)); return einsaetze; }
/* * neues, short Format * * Column Daten in einzeiliger Extra-Tabelle * ab Tabelle 2 Zeile 1 Daten */ private static IList<Einsatz> readShortFormat(Document doc, Playlist playlist) { IList<Einsatz> einsaetze = new List<Einsatz>(doc.Tables[2].Rows.Count); foreach(Row row in doc.Tables[2].Rows) { Track track = new Track( new Autor(" "), new Bpm(null), new Code(" "), new Interpret(init(brush(row.Cells[1].Range.Text))), new Label(init(brush(row.Cells[3].Range.Text))), new Laenge(" "), new Titel(init(brush(row.Cells[2].Range.Text))), new Verlag(" "), new Year(null), new Ending(Ending.Attribute.None)); einsaetze.Add(new Einsatz(playlist, track, row.Index)); } Check.Ensure(doc.Tables[2].Rows.Count == einsaetze.Count, String.Format( "Playlist unvollstaendig! Lesbare Datensaezte: {0} von {1}.", einsaetze.Count, doc.Tables[2].Rows.Count)); return einsaetze; }
static void updatePositions( Playlist playlist ) { for( int i = 0; i < playlist.Einsaetze.count; i++ ) playlist.Einsaetze[i].PositionOnList = i + 1; }
public void runOnceBeforEveryTest() { t = new Track( new Autor("autor"), new Bpm(null), new Code("12345"), new Interpret("interpret"), new Label("label"), new Laenge("04:30"), new Titel("titel"), new Verlag("verlag"), new Year(null), new Ending(Ending.Attribute.None) ); p = new Playlist("Playlist"); }
public void load_playlist_newFormat() { string path = BB080627; object template = path; object isNewTemplate = false; object documentType = WdNewDocumentType.wdNewBlankDocument; object isVisible = false; Microsoft.Office.Interop.Word.ApplicationClass app = new Microsoft.Office.Interop.Word.ApplicationClass(); Microsoft.Office.Interop.Word.Document doc = app.Documents.Add(ref template, ref isNewTemplate, ref documentType, ref isVisible); Playlist playlist = new Playlist("whatever"); IList<Einsatz> einsaetze = new List<Einsatz>(); /* * This loop is specific for new Playlist format. */ for(int i = 3; i <= doc.Tables[1].Rows.Count; i++) { Row row = doc.Tables[1].Rows[i]; Track track = new Track( new Autor(" "), new Bpm(null), new Code(init(brush(row.Cells[4].Range.Text))), new Interpret(init(brush(row.Cells[5].Range.Text))), new Label(init(brush(row.Cells[3].Range.Text))), new Laenge(init(brush(row.Cells[7].Range.Text))), new Titel(init(brush(row.Cells[1].Range.Text))), new Verlag(" "), new Year(null), new Ending(Ending.Attribute.None)); einsaetze.Add(new Einsatz(playlist, track, row.Index)); Console.WriteLine("{0}:{1}:{2}:{3}:{4}:{5}:{6}:{7}:{8}:{9}", track.Autor.Name, track.Bpm.ValueAsString, track.Code.Name, track.Interpret.Name, track.Label.Name, track.Laenge.Dauer, track.Titel.Name, track.Verlag.Name, track.Year.ValueAsString, track.Ending.EndingAsString); } Check.Ensure(doc.Tables[1].Rows.Count - 2 == einsaetze.Count, String.Format("Playlist unvollstaendig eingelesen: {0} statt {1} Datensaezte.", einsaetze.Count, doc.Tables[1].Rows.Count - 2)); Assert.AreEqual(doc.Tables[1].Rows.Count - 2, einsaetze.Count); }
public void instantiate() { Playlist p = new Playlist("Playlist"); Assert.AreEqual("Playlist", p.Name); }
public Einsatz( Playlist playlist, Track track ) { this.Playlist = playlist; this.Track = track; }
public static void delete(Playlist playlist, Einsatz einsatz ) { playlist.Einsaetze.remove( einsatz ); new NHibernateDaoFactory().getEinsatzDao().delete(einsatz); Playlist_Service.updatePositions(playlist); }
public static void append( Track track, Playlist playlist ) { playlist.addEinsatz( new Einsatz( playlist, track ) ); Playlist_Service.updatePositions(playlist); }
public Einsatz( Playlist playlist, Track track, int position ) { this.Playlist = playlist; this.Track = track; this.PositionOnList = position; }
public void can_use_FileUpload_Service() { string path1 = @"C:\Development\VS2005\projects\Gema.trunk\tanzer.gema.test\service\BB080627.old.format.doc"; Playlist playlist1 = new Playlist("oldformat"); IList<Einsatz> einsaetze1 = FileUpload_Service.getEinsaetze(path1, playlist1); string path2 = @"C:\Development\VS2005\projects\Gema.trunk\tanzer.gema.test\service\BB080627.new.format.doc"; Playlist playlist2 = new Playlist("newFormat"); IList<Einsatz> einsaetze2 = FileUpload_Service.getEinsaetze(path2, playlist2); Assert.IsTrue(einsaetze1.Count == einsaetze2.Count); Assert.IsTrue(einsaetze1.Count > 0); FileUpload_Service.persist(playlist1, einsaetze1); FileUpload_Service.persist(playlist2, einsaetze2); }