public void ShouldInsertAndReadSubFingerprints()
        {
            var       track              = new TrackInfo("isrc", "title", "artist");
            var       trackData          = trackDao.InsertTrack(track, 200);
            const int numberOfHashBins   = 100;
            var       genericHashBuckets = GenericHashBuckets();
            var       hashedFingerprints =
                Enumerable.Range(0, numberOfHashBins)
                .Select(
                    sequenceNumber =>
                    new HashedFingerprint(
                        genericHashBuckets,
                        (uint)sequenceNumber,
                        sequenceNumber * 0.928f,
                        Array.Empty <byte>()));

            InsertHashedFingerprintsForTrack(hashedFingerprints, trackData.TrackReference);

            var fingerprints = subFingerprintDao.ReadHashedFingerprintsByTrackReference(trackData.TrackReference)
                               .Select(ToHashedFingerprint()).ToList();

            numberOfHashBins.Should().Be(fingerprints.Count);
            foreach (var hashedFingerprint in fingerprints)
            {
                genericHashBuckets.Should().BeEquivalentTo(hashedFingerprint.HashBins);
            }
        }
Example #2
0
        public void ShouldInsertAndReadSubFingerprints()
        {
            var       track              = new TrackData("isrc", "artist", "title", "album", 1986, 200);
            var       trackReference     = trackDao.InsertTrack(track);
            const int NumberOfHashBins   = 100;
            var       genericHashBuckets = new long[25];
            var       hashedFingerprints =
                Enumerable.Range(0, NumberOfHashBins)
                .Select(
                    sequenceNumber =>
                    new HashedFingerprint(
                        GenericSignature(),
                        genericHashBuckets,
                        sequenceNumber,
                        sequenceNumber * 0.928,
                        Enumerable.Empty <string>()));

            InsertHashedFingerprintsForTrack(hashedFingerprints, trackReference);

            var hashedFingerprintss = subFingerprintDao.ReadHashedFingerprintsByTrackReference(track.TrackReference);

            Assert.AreEqual(NumberOfHashBins, hashedFingerprintss.Count);
            foreach (var hashedFingerprint in hashedFingerprintss)
            {
                CollectionAssert.AreEqual(genericHashBuckets, hashedFingerprint.HashBins);
            }
        }
        public void DeleteHashBinsAndSubfingerprintsOnTrackDelete()
        {
            TagInfo tagInfo        = GetTagInfo(1);
            var     track          = new TrackInfo(tagInfo.ISRC, tagInfo.Title, tagInfo.Artist);
            var     trackReference = trackDao.InsertTrack(track, tagInfo.Duration).TrackReference;
            var     hashData       = FingerprintCommandBuilder.Instance
                                     .BuildFingerprintCommand()
                                     .From(GetAudioSamples())
                                     .UsingServices(audioService)
                                     .Hash()
                                     .Result;

            subFingerprintDao.InsertHashDataForTrack(hashData.Audio, trackReference);
            var actualTrack = trackDao.ReadTrackById(tagInfo.ISRC);

            actualTrack.Should().NotBeNull();
            AssertTracksAreEqual(track, actualTrack);

            // Act
            int modifiedRows = trackDao.DeleteTrack(trackReference) + subFingerprintDao.DeleteSubFingerprintsByTrackReference(trackReference);

            trackDao.ReadTrackById(tagInfo.ISRC).Should().BeNull();
            subFingerprintDao.ReadHashedFingerprintsByTrackReference(actualTrack.TrackReference).Should().BeEmpty();
            modifiedRows.Should().Be(1 + hashData.Count + (25 * hashData.Count));
        }
        public void ShouldReadSubFingerprintsByReference()
        {
            var trackReference = new SolrModelReference("track-id");
            var results        = new SolrQueryResults <SubFingerprintDTO>();
            var dto            = new SubFingerprintDTO
            {
                Clusters         = new[] { "CA" },
                SubFingerprintId = "123-123",
                Hashes           = new Dictionary <int, long>(),
                SequenceAt       = 10d,
                SequenceNumber   = 10,
                TrackId          = "track-id"
            };

            results.AddRange(new List <SubFingerprintDTO> {
                dto
            });
            solr.Setup(s => s.Query("trackId:track-id")).Returns(results);
            dictionaryToHashConverter.Setup(dhc => dhc.FromSolrDictionaryToHashes(It.IsAny <IDictionary <int, long> >()))
            .Returns(new long[0]);
            hashConverter.Setup(hc => hc.ToBytes(It.IsAny <long[]>(), It.IsAny <int>())).Returns(new byte[0]);

            var subs = subFingerprintDao.ReadHashedFingerprintsByTrackReference(trackReference);

            Assert.AreEqual(1, subs.Count);
            CollectionAssert.AreEqual(new[] { "CA" }, subs.First().Clusters);
        }
Example #5
0
 public IList <HashedFingerprint> ReadHashedFingerprintsByTrack(IModelReference trackReference)
 {
     return(SubFingerprintDao.ReadHashedFingerprintsByTrackReference(trackReference)
            .Select(subFingerprint => new HashedFingerprint(
                        subFingerprint.Hashes,
                        subFingerprint.SequenceNumber,
                        subFingerprint.SequenceAt))
            .ToList());
 }