public void InsertAlbum(Album album) { album.Id = PrepareStoredProcedure(SpInsertAlbum) .WithParametersFromModel(album) .Execute() .AsScalar<int>(); }
public void CheckReleaseYearConstraintsAlbum() { string name = MethodBase.GetCurrentMethod().Name; Album a = new Album(); Assert.AreEqual(true, !string.IsNullOrEmpty(a.Name)); Assert.AreEqual(MinYear /*Default value*/, a.ReleaseYear); a.ReleaseYear = 0; /*Release Year (1500..2100]*/ }
public void DeleteTrackByIdTest() { string name = MethodBase.GetCurrentMethod().Name; const int FakeId = int.MinValue; Album album = new Album(FakeId, name, 1986); dalManager.InsertAlbum(album); Assert.AreNotEqual(FakeId, album.Id); Track track = new Track(FakeId, name, name, album.Id); dalManager.InsertTrack(track); Assert.AreNotEqual(FakeId, track.Id); dalManager.DeleteTrack(track.Id); Assert.AreEqual(null, dalManager.ReadAlbumById(album.Id)); Assert.AreEqual(null, dalManager.ReadTrackById(track.Id)); }
public void GetInsertAlbumCommandTest() { string name = MethodBase.GetCurrentMethod().Name; DaoStoredProcedureBuilder target = new DaoStoredProcedureBuilder(); Album album = new Album(0, name, 1998); DbConnection connection = Dbf.CreateConnection(); connection.ConnectionString = ConnectionString; IDbCommand actual = target.GetInsertAlbumCommand(album, connection); Assert.AreEqual(SP_INSERT_ALBUM, actual.CommandText); Assert.AreEqual(CommandType.StoredProcedure, actual.CommandType); Assert.IsNotNull(actual.Connection); Assert.AreEqual(ConnectionState.Closed, actual.Connection.State); Assert.AreEqual(2, actual.Parameters.Count); }
public void ReadFingerprintByIdTest() { string name = MethodBase.GetCurrentMethod().Name; DaoGateway manager = dalManager; const int fakeId = int.MinValue; Album album = new Album(fakeId, name, 1986); manager.InsertAlbum(album); Assert.AreNotEqual(fakeId, album); Track track = new Track(fakeId, name, name, album.Id, 360); manager.InsertTrack(track); Assert.AreNotEqual(fakeId, track.Id); Fingerprint f = new Fingerprint(fakeId, GenericFingerprint, track.Id, 0); manager.InsertFingerprint(f); Assert.AreNotEqual(fakeId, f.Id); Fingerprint readF = manager.ReadFingerprintById(f.Id); Assert.AreEqual(f.Id, readF.Id); Assert.AreEqual(f.Signature.Length, readF.Signature.Length); for (int i = 0; i < f.Signature.Length; i++) { Assert.AreEqual(f.Signature[i], readF.Signature[i]); } Assert.AreEqual(f.TrackId, readF.TrackId); }
public void ReadAlbumByNameTest() { string name = MethodBase.GetCurrentMethod().Name; string albumName = Guid.NewGuid().ToString(); Album album = new Album(int.MinValue, albumName); dalManager.InsertAlbum(album); Assert.AreNotEqual(int.MinValue, album.Id); Album readAlbum = dalManager.ReadAlbumByName(albumName); Assert.IsNotNull(readAlbum); Assert.AreEqual(album.Id, readAlbum.Id); }
public void CreateFingerprintsFromFileAndInsertInDatabaseUsingDirectSoundProxyTest() { Album album = new Album(0, "Random"); dalManager.InsertAlbum(album); Track track = new Track(0, "Track", "Track", album.Id); dalManager.InsertTrack(track); List<bool[]> signatures = workUnitBuilder.BuildWorkUnit().On(PathToWav).With(fingerprintingConfiguration). GetFingerprintsUsingService(fingerprintingServiceWithDirectSound).Result; List<Fingerprint> fingerprints = AssociateFingerprintsToTrack(signatures, track.Id); dalManager.InsertFingerprint(fingerprints); List<Fingerprint> insertedFingerprints = dalManager.ReadFingerprintsByTrackId(track.Id, 0); /*Read all fingerprints*/ Assert.AreEqual(fingerprints.Count, insertedFingerprints.Count); foreach (Fingerprint fingerprint in fingerprints) { foreach (Fingerprint insertedFingerprint in insertedFingerprints) { if (fingerprint.Id == insertedFingerprint.Id) { Assert.AreEqual(fingerprint.Signature.Length, insertedFingerprint.Signature.Length); for (int i = 0; i < fingerprint.Signature.Length; i++) { Assert.AreEqual(fingerprint.Signature[i], insertedFingerprint.Signature[i]); } Assert.AreEqual( fingerprint.TotalFingerprintsPerTrack, insertedFingerprint.TotalFingerprintsPerTrack); Assert.AreEqual(fingerprint.TrackId, insertedFingerprint.TrackId); } } } }
public void ReadTrackByFingerprintTest() { string name = MethodBase.GetCurrentMethod().Name; DaoGateway manager = dalManager; Album album = new Album(int.MinValue, name, 1986); manager.InsertAlbum(album); Track track = new Track(int.MinValue, name, name, album.Id, 360); manager.InsertTrack(track); const int FakeId = int.MinValue; Fingerprint f = new Fingerprint(FakeId, GenericFingerprint, track.Id, int.MinValue); manager.InsertFingerprint(f); Assert.AreNotEqual(FakeId, f.Id); List<Track> list = manager.ReadTrackByFingerprint(f.Id); Track readT = list.FirstOrDefault(temp => temp.Id == track.Id); Assert.AreNotEqual(null, readT); Assert.AreEqual(track.Id, readT.Id); Assert.AreEqual(track.AlbumId, readT.AlbumId); Assert.AreEqual(track.Artist, readT.Artist); Assert.AreEqual(track.Title, readT.Title); Assert.AreEqual(track.TrackLength, readT.TrackLength); }
public void ReadFingerprintByTrackIdTest() { string name = MethodBase.GetCurrentMethod().Name; DaoGateway manager = dalManager; Album album = new Album(0, name, 1986); manager.InsertAlbum(album); Track track = new Track(0, name, name, album.Id, 360); manager.InsertTrack(track); Fingerprint f = new Fingerprint(0, GenericFingerprint, track.Id, 0); manager.InsertFingerprint(f); List<Fingerprint> list = manager.ReadFingerprintsByTrackId(track.Id, 0); Fingerprint readF = list.FirstOrDefault(temp => temp.Id == f.Id); Assert.AreNotEqual(null, readF); Assert.AreEqual(f.Id, readF.Id); Assert.AreEqual(f.Signature.Length, readF.Signature.Length); for (int i = 0; i < f.Signature.Length; i++) { Assert.AreEqual(f.Signature[i], readF.Signature[i]); } Assert.AreEqual(f.TrackId, readF.TrackId); }
public void InsertReadAlbumTest() { string name = MethodBase.GetCurrentMethod().Name; DaoGateway manager = new DaoGateway(connectionstring); const int FakeId = int.MinValue; Album album = new Album { Id = FakeId, Name = name, ReleaseYear = 1986 }; manager.InsertAlbum(album); Assert.AreNotEqual(FakeId, album.Id); List<Album> albums = manager.ReadAlbums(); // read all albums bool found = false; int id = 0; if (albums.Any(a => a.Id == album.Id)) { found = true; id = album.Id; } Assert.IsTrue(found); // check if it was inserted Album b = manager.ReadAlbumById(id); Assert.AreEqual(id, b.Id); Assert.AreEqual(album.Name, b.Name); Assert.AreEqual(album.ReleaseYear, b.ReleaseYear); List<Album> listAlbums = new List<Album>(); List<int> lId = new List<int>(); for (int i = 0; i < 10; i++) { Album a = new Album(FakeId, name + ":" + i, i + 1986); listAlbums.Add(a); } manager.InsertAlbum(listAlbums); /*Insert a list of albums*/ foreach (Album item in listAlbums) { Assert.AreNotEqual(FakeId, item.Id); lId.Add(item.Id); } List<Album> readAlbums = manager.ReadAlbums(); /*read all albums*/ List<int> lReadIds = readAlbums.Select(a => a.Id).ToList(); foreach (int i in lId) { Assert.AreEqual(true, lReadIds.Contains(i)); } }
public void InsertFingerprintWithBadTrackIdForeignKeyreference() { string name = MethodBase.GetCurrentMethod().Name; Album a = new Album(0, name, 1990); Track track = new Track(0, name, name, a.Id); Fingerprint f = new Fingerprint(0, GenericFingerprint, track.Id, 0); dalManager.InsertFingerprint(f); }
public void DeleteTrackTest() { string name = MethodBase.GetCurrentMethod().Name; Album album = new Album(0, name, 1986); dalManager.InsertAlbum(album); Track track = new Track(0, name, name, album.Id); dalManager.InsertTrack(track); dalManager.DeleteTrack(track); Assert.AreEqual(null, dalManager.ReadAlbumById(album.Id)); Assert.AreEqual(null, dalManager.ReadTrackById(track.Id)); }
public void DeleteTrackListTest() { string name = MethodBase.GetCurrentMethod().Name; Album album = new Album(int.MinValue, name, 1986); dalManager.InsertAlbum(album); List<Track> listTracks = new List<Track>(); List<int> lId = new List<int>(); for (int i = 0; i < 10; i++) { Track a = new Track(int.MinValue, name + i, name + i, album.Id); listTracks.Add(a); } dalManager.InsertTrack(listTracks); List<Fingerprint> fingerprintList = new List<Fingerprint>(); for (int j = 0; j < 100; j++) { fingerprintList.Add(new Fingerprint(0, GenericFingerprint, listTracks[j / 10].Id, 0)); } dalManager.InsertFingerprint(fingerprintList); List<Track> listOfTracks = dalManager.ReadTracks(); Assert.AreEqual(0, (listOfTracks == null) ? 0 : listOfTracks.Count); Album ab = dalManager.ReadAlbumById(album.Id); Assert.AreEqual(0, (ab == null) ? 0 : 1); List<Fingerprint> list = dalManager.ReadFingerprints(); Assert.AreEqual(0, (list == null) ? 0 : list.Count); }
public void DeleteTrackListOfIdTest() { string name = MethodBase.GetCurrentMethod().Name; const int FakeId = int.MinValue; Album album = new Album(FakeId, name, 1986); dalManager.InsertAlbum(album); Assert.AreNotEqual(FakeId, album.Id); List<Track> listTracks = new List<Track>(); for (int i = 0; i < 10; i++) { Track a = new Track(FakeId, name + i, name + i, album.Id); listTracks.Add(a); } dalManager.InsertTrack(listTracks); foreach (Track track in listTracks) Assert.AreNotEqual(FakeId, track.Id); List<Fingerprint> fingerprintList = new List<Fingerprint>(); for (int j = 0; j < 100; j++) fingerprintList.Add(new Fingerprint(FakeId, GenericFingerprint, listTracks[j / 10].Id, 0)); dalManager.InsertFingerprint(fingerprintList); foreach (Fingerprint finger in fingerprintList) Assert.AreNotEqual(FakeId, finger.Id); List<Track> listOfTracks = dalManager.ReadTracks(); List<int> lId = listOfTracks.Select(t => t.Id).ToList(); listOfTracks = dalManager.ReadTracks(); Assert.AreEqual(0, (listOfTracks == null) ? 0 : listOfTracks.Count); Album ab = dalManager.ReadAlbumById(album.Id); Assert.AreEqual(0, (ab == null) ? 0 : 1); List<Fingerprint> list = dalManager.ReadFingerprints(); Assert.AreEqual(0, (list == null) ? 0 : list.Count); }
public void ReadFingerprintByMultipleTrackIdTest() { string name = MethodBase.GetCurrentMethod().Name; DaoGateway manager = dalManager; Album album = new Album(0, name, 1986); manager.InsertAlbum(album); Track track0 = new Track(0, name, name, album.Id, 360); manager.InsertTrack(track0); Track track1 = new Track(0, name, name, album.Id, 360); manager.InsertTrack(track1); Track track2 = new Track(0, name, name, album.Id, 360); manager.InsertTrack(track2); Fingerprint f0 = new Fingerprint(0, GenericFingerprint, track0.Id, 0); manager.InsertFingerprint(f0); Fingerprint f1 = new Fingerprint(0, GenericFingerprint, track0.Id, 1); manager.InsertFingerprint(f1); Fingerprint f2 = new Fingerprint(0, GenericFingerprint, track1.Id, 2); manager.InsertFingerprint(f2); Fingerprint f3 = new Fingerprint(0, GenericFingerprint, track1.Id, 3); manager.InsertFingerprint(f3); Fingerprint f4 = new Fingerprint(0, GenericFingerprint, track2.Id, 4); manager.InsertFingerprint(f4); Fingerprint f5 = new Fingerprint(0, GenericFingerprint, track2.Id, 5); manager.InsertFingerprint(f5); Fingerprint f6 = new Fingerprint(0, GenericFingerprint, track0.Id, 6); manager.InsertFingerprint(f6); Fingerprint f7 = new Fingerprint(0, GenericFingerprint, track1.Id, 7); manager.InsertFingerprint(f7); Fingerprint f8 = new Fingerprint(0, GenericFingerprint, track2.Id, 8); manager.InsertFingerprint(f8); Dictionary<int, List<Fingerprint>> dict = manager.ReadFingerprintsByMultipleTrackId(new List<Track> { track0, track1, track2 }, 0); Assert.AreNotEqual(null, dict); Assert.AreEqual(3, dict.Keys.Count); foreach (KeyValuePair<int, List<Fingerprint>> item in dict) { Assert.AreEqual(3, item.Value.Count); } Assert.AreEqual(true, dict.ContainsKey(track0.Id)); Assert.AreEqual(true, dict.ContainsKey(track1.Id)); Assert.AreEqual(true, dict.ContainsKey(track2.Id)); foreach (KeyValuePair<int, List<Fingerprint>> pair in dict) { Assert.AreEqual(3, pair.Value.Count); } }
public void ReadFingerprintByMultipleTrackIdTest1() { string name = MethodBase.GetCurrentMethod().Name; DaoGateway manager = dalManager; Album album = new Album(0, name, 1986); manager.InsertAlbum(album); const int NumberOfTracks = 1153; const int NumberOfFingerprintsPerTrack = 10; List<Track> listTrack = new List<Track>(); List<Fingerprint> listOfFingerprints = new List<Fingerprint>(); for (int i = 0; i < NumberOfTracks; i++) { Track track0 = new Track(0, name, name, album.Id, 360); listTrack.Add(track0); manager.InsertTrack(track0); for (int j = 0; j < NumberOfFingerprintsPerTrack; j++) { Fingerprint f0 = new Fingerprint(0, GenericFingerprint, track0.Id, 0); listOfFingerprints.Add(f0); } } manager.InsertFingerprint(listOfFingerprints); Dictionary<int, List<Fingerprint>> dict = manager.ReadFingerprintsByMultipleTrackId(listTrack, 0); Assert.AreNotEqual(null, dict); Assert.AreEqual(NumberOfTracks, dict.Keys.Count); foreach (Track track in listTrack) { Assert.AreEqual(true, dict.ContainsKey(track.Id)); Assert.AreEqual(NumberOfFingerprintsPerTrack, dict[track.Id].Count); } }
public void InsertReadFingerprintTest() { string name = MethodBase.GetCurrentMethod().Name; DaoGateway manager = dalManager; Album album = new Album(0, name, 1986); manager.InsertAlbum(album); Track track = new Track(0, name, name, album.Id, 360); manager.InsertTrack(track); Fingerprint f = new Fingerprint(0, GenericFingerprint, track.Id, 0); manager.InsertFingerprint(f); List<Fingerprint> allFingerprints = manager.ReadFingerprints(); List<int> lGuid = allFingerprints.Select(temp => temp.Id).ToList(); Assert.AreEqual(true, lGuid.Contains(f.Id)); List<Fingerprint> addList = new List<Fingerprint>(); for (int i = 0; i < 10; i++) { addList.Add(new Fingerprint(0, GenericFingerprint, track.Id, 0)); } manager.InsertFingerprint(addList); allFingerprints = manager.ReadFingerprints(); lGuid.Clear(); lGuid.AddRange(allFingerprints.Select(temp => temp.Id)); foreach (Fingerprint finger in addList) { Assert.AreEqual(true, lGuid.Contains(finger.Id)); } }
public void ReadTrackByFingerprintInexistantIdTest() { string name = MethodBase.GetCurrentMethod().Name; DaoGateway manager = dalManager; const int FakeId = int.MinValue; Album album = new Album(FakeId, name, 1986); manager.InsertAlbum(album); Track track = new Track(FakeId, name, name, album.Id, 360); manager.InsertTrack(track); Fingerprint f = new Fingerprint(FakeId, GenericFingerprint, track.Id, 0); List<Track> list = manager.ReadTrackByFingerprint(f.Id); Assert.AreEqual(null, list); }
public void InsertReadTrackTest() { string name = MethodBase.GetCurrentMethod().Name; DaoGateway manager = dalManager; Album album = new Album(int.MinValue, name, 1986); manager.InsertAlbum(album); Assert.AreNotEqual(int.MinValue, album.Id); Track track = new Track(int.MinValue, name, name, album.Id, 360); manager.InsertTrack(track); Assert.AreNotEqual(int.MinValue, track.Id); List<Track> listOfTracks = manager.ReadTracks(); bool found = false; foreach (Track temp in listOfTracks) { Assert.IsTrue(temp.Id > 0); if (temp.Id == track.Id) { found = true; break; } } Assert.AreEqual(true, found); Track t = manager.ReadTrackById(track.Id); Assert.AreEqual(track.Id, t.Id); Assert.AreEqual(track.AlbumId, t.AlbumId); Assert.AreEqual(track.Artist, t.Artist); Assert.AreEqual(track.Title, t.Title); Assert.AreEqual(track.TrackLength, t.TrackLength); List<Album> listAlbums = new List<Album>(); for (int i = 0; i < 10; i++) { Album a = new Album(int.MinValue, name + i, i + 1986); listAlbums.Add(a); } manager.InsertAlbum(listAlbums); foreach (Album a in listAlbums) { Assert.AreNotEqual(int.MinValue, a.Id); } List<Track> listTracks = new List<Track>(); List<int> lId = new List<int>(); for (int i = 0; i < 10; i++) { Track a = new Track(int.MinValue, name + i, name + i, listAlbums[i].Id); listTracks.Add(a); } manager.InsertTrack(listTracks); foreach (Track item in listTracks) { Assert.AreNotEqual(int.MinValue, item.Id); } List<Track> readTracks = manager.ReadTracks(); List<int> lReadIds = readTracks.Select(a => a.Id).ToList(); foreach (int i in lId) { Assert.AreEqual(true, lReadIds.Contains(i)); } }
/// <summary> /// Start inserting into the database /// </summary> private void BtnStartClick(object sender, EventArgs e) { string connectionString = _cmbDBFillerConnectionString.SelectedItem.ToString(); //Set Connection String try { _dalManager.SetConnectionString(connectionString); //Try Connection String } catch (Exception ex) { MessageBox.Show(ex.Message, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); FadeAllControls(false); return; } if (!String.IsNullOrEmpty(_tbRootFolder.Text) || !String.IsNullOrEmpty(_tbSingleFile.Text) && _fileList == null) { _fileList = new List<string>(); if (!String.IsNullOrEmpty(_tbRootFolder.Text)) TbRootFolderTextChanged(this, null); if (!String.IsNullOrEmpty(_tbSingleFile.Text)) TbSingleFileTextChanged(this, null); } if (_fileList == null || _fileList.Count == 0) { MessageBox.Show(Resources.FileListEmpty, Resources.FileListEmptyCaption, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } FadeAllControls(true); //Fade all controls int rest = _fileList.Count%THREADS; int filesPerThread = _fileList.Count/THREADS; _listOfAllAlbums = _dalManager.ReadAlbums(); //Get all albums _unknownAlbum = _dalManager.ReadUnknownAlbum(); //Read unknown album int topWavelets = (int) _nudTopWav.Value; _fingerManager = new FingerprintManager {TopWavelets = topWavelets}; switch (_hashAlgorithm) { case HashAlgorithm.LSH: _hashTables = (int) _nudHashTables.Value; //If LSH is used # of Hash tables _hashKeys = (int) _nudHashKeys.Value; //If LSH is used # of keys per table break; case HashAlgorithm.NeuralHasher: if (String.IsNullOrEmpty(_tbPathToEnsemble.Text)) //Check if the path to ensemble is specified { MessageBox.Show(Resources.SpecifyPathToNetworkEnsemble, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); FadeAllControls(false); return; } try { _ensemble = NNEnsemble.Load(_tbPathToEnsemble.Text); //Load the ensemble } catch (Exception ex) { MessageBox.Show(ex.Message); FadeAllControls(false); return; } break; case HashAlgorithm.None: break; } BeginInvoke(new Action(() => { }), null); ResetControls(); int runningThreads = THREADS; for (int i = 0; i < THREADS; i++) //Start asynchronous operation { int start = i*filesPerThread; //Define start and end indexes int end = (i == THREADS - 1) ? i*filesPerThread + filesPerThread + rest : i*filesPerThread + filesPerThread; Action<int, int> action = InsertInDatabase; action.BeginInvoke(start, end, (result) => { //End Asynchronous operation Action<int, int> item = (Action<int, int>) result.AsyncState; item.EndInvoke(result); Interlocked.Decrement(ref runningThreads); if (runningThreads == 0) { /********* END OF INSERTION PROCESS HERE!********/ Invoke(new Action(() => { _pbTotalSongs.Visible = false; FadeAllControls(false); _tbRootFolder.Text = null; _tbSingleFile.Text = null; })); MessageBox.Show(Resources.InsertionEnded, Resources.End, MessageBoxButtons.OK, MessageBoxIcon.Information); } }, action); } }
public void InsertTrackWithBadAlbumIdForeignKeyReference() { string name = MethodBase.GetCurrentMethod().Name; Album a = new Album(int.MinValue, name, 1990); Track track = new Track(int.MinValue, name, name, a.Id); dalManager.InsertTrack(track); }
/// <summary> /// Get a command to insert an item to the database /// </summary> /// <param name = "album">Album to be inserted</param> /// <param name = "connection">Connection used to insert the album</param> /// <returns>Command to be executed</returns> public DbCommand GetInsertAlbumCommand(Album album, DbConnection connection) { DbCommand command = GetStoredProcedureCommand(SP_INSERT_ALBUM, connection); DbParameter param = command.CreateParameter(); param.ParameterName = PARAM_ALBUM_NAME; param.DbType = DbType.String; param.Value = album.Name; command.Parameters.Add(param); param = command.CreateParameter(); param.ParameterName = PARAM_ALBUM_RELEASE_YEAR; param.DbType = DbType.Int32; param.Value = album.ReleaseYear; command.Parameters.Add(param); return command; }
public void CreateFingerprintsFromFileAndInsertInDatabaseUsingBassProxyCheckCorrectitudeOfFingerprintsTest() { Album album = new Album(0, "Sample"); dalManager.InsertAlbum(album); Track track = new Track(0, "Sample", "Sample", album.Id); dalManager.InsertTrack(track); var signatures = workUnitBuilder.BuildWorkUnit().On(PathToMp3).With(fingerprintingConfiguration). GetFingerprintsUsingService(fingerprintingServiceWithBass).Result; List<Fingerprint> fingerprints = AssociateFingerprintsToTrack(signatures, track.Id); dalManager.InsertFingerprint(fingerprints); List<Fingerprint> insertedFingerprints = AssociateFingerprintsToTrack(signatures, track.Id); Assert.AreEqual(fingerprints.Count, insertedFingerprints.Count); foreach (Fingerprint fingerprint in fingerprints) { foreach (var insertedFingerprint in insertedFingerprints) { if (fingerprint.Id == insertedFingerprint.Id) { Assert.AreEqual(fingerprint.Signature.Length, insertedFingerprint.Signature.Length); for (int i = 0; i < fingerprint.Signature.Length; i++) { Assert.AreEqual(fingerprint.Signature[i], insertedFingerprint.Signature[i]); } Assert.AreEqual( fingerprint.TotalFingerprintsPerTrack, insertedFingerprint.TotalFingerprintsPerTrack); Assert.AreEqual(fingerprint.TrackId, insertedFingerprint.TrackId); } } } }