public void TearDown()
        {
            var allTracks = trackDao.ReadAll();

            foreach (var track in allTracks)
            {
                trackDao.DeleteTrack(track.TrackReference);
            }
        }
Exemplo n.º 2
0
        public void ShouldDeleteTrack()
        {
            var expected  = new TrackData("isrc", "artist", "title", "album", 1994, 4.0);
            var reference = trackDao.InsertTrack(expected);
            var actual    = trackDao.ReadTrack(reference);

            AssertTracksAreEqual(expected, actual);

            trackDao.DeleteTrack(reference);

            var tracks = trackDao.ReadAll();

            Assert.AreEqual(0, tracks.Count);
        }
        public void DeleteCollectionOfTracksFact()
        {
            const int numberOfTracks = 10;
            var       tracks         = InsertTracks(numberOfTracks);

            var allTracks = trackDao.ReadAll().ToList();

            allTracks.Count.Should().Be(numberOfTracks);
            foreach (var track in tracks)
            {
                trackDao.DeleteTrack(track.TrackReference);
            }

            trackDao.ReadAll().Should().BeEmpty();
        }
Exemplo n.º 4
0
        public void DeleteOneTrackTest()
        {
            TrackData track          = GetTrack();
            var       trackReference = TrackDao.InsertTrack(track);

            TrackDao.DeleteTrack(trackReference);

            Assert.IsNull(TrackDao.ReadTrack(trackReference));
        }
Exemplo n.º 5
0
        public void DeleteOneTrackTest()
        {
            string    name    = MethodBase.GetCurrentMethod().Name;
            TrackData track   = GetTrack(name);
            int       trackId = TrackDao.Insert(track);

            TrackDao.DeleteTrack(trackId);

            Assert.IsNull(TrackDao.ReadById(trackId));
        }
Exemplo n.º 6
0
        public void DeleteHashBinsAndSubfingerprintsOnTrackDelete()
        {
            const int StaticStride     = 5115;
            const int SecondsToProcess = 20;
            const int StartAtSecond    = 30;
            TagInfo   tagInfo          = tagService.GetTagInfo(PathToMp3);
            int       releaseYear      = tagInfo.Year;
            TrackData track            = new TrackData(tagInfo.ISRC, tagInfo.Artist, tagInfo.Title, tagInfo.Album, releaseYear, (int)tagInfo.Duration);
            int       trackId          = TrackDao.Insert(track);
            var       hashData         = fingerprintCommandBuilder
                                         .BuildFingerprintCommand()
                                         .From(PathToMp3, SecondsToProcess, StartAtSecond)
                                         .WithFingerprintConfig(config =>
            {
                config.Stride = new IncrementalStaticStride(StaticStride, config.SamplesPerFingerprint);
            })
                                         .Hash()
                                         .Result;

            List <long> subFingerprintIds = new List <long>();

            foreach (var hash in hashData)
            {
                long subFingerprintId = SubFingerprintDao.Insert(hash.SubFingerprint, trackId);
                HashBinDao.Insert(hash.HashBins, subFingerprintId);
                subFingerprintIds.Add(subFingerprintId);
            }

            var actualTrack = TrackDao.ReadTrackByISRC(tagInfo.ISRC);

            Assert.IsNotNull(actualTrack);
            AssertTracksAreEqual(track, actualTrack);

            // Act
            int modifiedRows = TrackDao.DeleteTrack(trackId);

            Assert.IsNull(TrackDao.ReadTrackByISRC(tagInfo.ISRC));
            foreach (var id in subFingerprintIds)
            {
                Assert.IsTrue(id != 0);
                Assert.IsNull(SubFingerprintDao.ReadById(id));
            }

            for (int i = 1; i <= 25; i++)
            {
                Assert.IsTrue(HashBinDao.ReadHashBinsByHashTable(i).Count == 0);
            }

            Assert.AreEqual(1 + hashData.Count + (25 * hashData.Count), modifiedRows);
        }
Exemplo n.º 7
0
        public void DeleteCollectionOfTracksTest()
        {
            const int NumberOfTracks = 10;
            var       tracks         = InsertTracks(NumberOfTracks);

            var allTracks = TrackDao.ReadAll();

            Assert.IsTrue(allTracks.Count == NumberOfTracks);
            foreach (var track in tracks)
            {
                TrackDao.DeleteTrack(track.TrackReference);
            }

            Assert.IsTrue(TrackDao.ReadAll().Count == 0);
        }
Exemplo n.º 8
0
        public void DeleteHashBinsAndSubfingerprintsOnTrackDelete()
        {
            const int StaticStride     = 5115;
            const int SecondsToProcess = 20;
            const int StartAtSecond    = 30;
            TagInfo   tagInfo          = tagService.GetTagInfo(PathToMp3);
            int       releaseYear      = tagInfo.Year;
            TrackData track            = new TrackData(tagInfo.ISRC, tagInfo.Artist, tagInfo.Title, tagInfo.Album, releaseYear, (int)tagInfo.Duration);
            var       trackReference   = TrackDao.InsertTrack(track);
            var       hashData         = fingerprintCommandBuilder
                                         .BuildFingerprintCommand()
                                         .From(PathToMp3, SecondsToProcess, StartAtSecond)
                                         .WithFingerprintConfig(config =>
            {
                config.Stride = new IncrementalStaticStride(StaticStride, config.SamplesPerFingerprint);
            })
                                         .UsingServices(audioService)
                                         .Hash()
                                         .Result;

            var subFingerprintReferences = new List <IModelReference>();

            foreach (var hash in hashData)
            {
                var subFingerprintReference = SubFingerprintDao.InsertSubFingerprint(hash.SubFingerprint, trackReference);
                HashBinDao.InsertHashBins(hash.HashBins, subFingerprintReference, trackReference);
                subFingerprintReferences.Add(subFingerprintReference);
            }

            var actualTrack = TrackDao.ReadTrackByISRC(tagInfo.ISRC);

            Assert.IsNotNull(actualTrack);
            AssertTracksAreEqual(track, actualTrack);

            // Act
            int modifiedRows = TrackDao.DeleteTrack(trackReference);

            Assert.IsNull(TrackDao.ReadTrackByISRC(tagInfo.ISRC));
            foreach (var id in subFingerprintReferences)
            {
                Assert.IsTrue(id.GetHashCode() != 0);
                Assert.IsNull(SubFingerprintDao.ReadSubFingerprint(id));
            }

            Assert.IsTrue(HashBinDao.ReadHashDataByTrackReference(actualTrack.TrackReference).Count == 0);
            Assert.AreEqual(1 + hashData.Count + (25 * hashData.Count), modifiedRows);
        }
        public Response DeleteTrack(int id)
        {
            if (id == 0)
            {
                return(responseFactory.CreateResponse("Error: track id is null", ResponseStatus.BADREQUEST));
            }

            response = new Response();

            try
            {
                response = trackDao.DeleteTrack(id);
            }
            catch (Exception exception)
            {
                return(responseFactory.CreateResponse(exception.Message, ResponseStatus.EXCEPTION));
            }

            return(response);
        }
Exemplo n.º 10
0
        public void DeleteCollectionOfTracksTest()
        {
            const int NumberOfTracks       = 10;
            IEnumerable <TrackData> tracks = GetRandomListOfTracks(NumberOfTracks);
            List <int> trackIds            = new List <int>();

            foreach (var track in tracks)
            {
                trackIds.Add(TrackDao.Insert(track));
            }

            var allTracks = TrackDao.ReadAll();

            Assert.IsTrue(allTracks.Count > 0);
            foreach (var trackId in trackIds)
            {
                TrackDao.DeleteTrack(trackId);
            }

            Assert.IsTrue(TrackDao.ReadAll().Count == 0);
        }
Exemplo n.º 11
0
        public virtual int DeleteTrack(string trackId)
        {
            var track = TrackDao.ReadTrackById(trackId);

            if (track == null)
            {
                return(0);
            }

            var trackReference = track.TrackReference;

            return(SubFingerprintDao.DeleteSubFingerprintsByTrackReference(trackReference) + TrackDao.DeleteTrack(trackReference));
        }
Exemplo n.º 12
0
        public void DeleteNonExistentTrackTest()
        {
            int actual = TrackDao.DeleteTrack(1234);

            Assert.AreEqual(0, actual);
        }