Esempio n. 1
0
        public async void WillBackupIfRequested()
        {
            var backupPath = this.target.Path + ".bak";
            var dryRun     = new DryRun(false, this.dryRunLogger);

            var before = await this.fileUtilities.CalculateChecksum(this.target.Path, HashAlgorithmName.SHA256);

            await this.AssertMetadata(BeforeFixSamples, FirmwareVersion);

            var actual = await this.fixer.ProcessFileAsync(this.target.Path, dryRun, true);

            Assert.Equal(FixStatus.Fixed, actual.Status);
            Assert.Contains($"Old total samples was", actual.Message);

            // modified file
            await this.AssertMetadata(AfterFixSamples, FirmwareVersion, PatchedTag);

            // backup
            using (var stream = (FileStream)this.fileSystem.File.OpenRead(backupPath))
            {
                var actualSamples  = (ulong)Flac.ReadTotalSamples(stream);
                var actualFirmware = (FirmwareRecord) await ReadFirmwareAsync(stream);

                Assert.Equal(BeforeFixSamples, actualSamples);
                Assert.Equal(FirmwareVersion, actualFirmware.Version);

                actualFirmware.Tags.Should().BeEquivalentTo(Array.Empty <string>());
            }

            var after = await this.fileUtilities.CalculateChecksum(backupPath, HashAlgorithmName.SHA256);

            // the backup file has the same hash as the original
            Assert.Equal(before, after);
        }
Esempio n. 2
0
 public void ReadTotalSamplesTest(FixtureModel model)
 {
     if (model.Process.ContainsKey(FixtureModel.FlacHeaderExtractor))
     {
         Fin <ulong> totalSamples = Flac.ReadTotalSamples(model.ToTargetInformation(this.RealFileSystem).FileStream);
         Assert.True(totalSamples.IsSucc);
         ((ulong)totalSamples).Should().Be(model.Record.TotalSamples);
     }
 }
Esempio n. 3
0
        private async Task AssertMetadata(ulong samples, decimal firmwareVersion, params string[] tags)
        {
            using var stream = (FileStream) this.fileSystem.File.OpenRead(this.target.Path);
            var actualSamples  = (ulong)Flac.ReadTotalSamples(stream);
            var actualFirmware = (FirmwareRecord) await ReadFirmwareAsync(stream);

            Assert.Equal(samples, actualSamples);
            Assert.Equal(firmwareVersion, actualFirmware.Version);

            actualFirmware.Tags.Should().BeEquivalentTo(tags);
        }
Esempio n. 4
0
        public ValueTask <Recording> ProcessFileAsync(TargetInformation information, Recording recording)
        {
            var samples    = Flac.ReadTotalSamples(information.FileStream);
            var sampleRate = Flac.ReadSampleRate(information.FileStream);
            var channels   = Flac.ReadNumChannels(information.FileStream);
            var bitDepth   = Flac.ReadBitDepth(information.FileStream);

            Rational?duration = samples.IsFail || sampleRate.IsFail || (uint)sampleRate == 0 ? null : (new Rational((ulong)samples) / new Rational((uint)sampleRate));
            uint?    bitRate  = sampleRate.IsFail || bitDepth.IsFail || channels.IsFail ? null : (uint)sampleRate * (uint)bitDepth * (uint)channels;

            recording = recording with
            {
                DurationSeconds = recording.DurationSeconds ?? duration,
                SampleRateHertz = recording.SampleRateHertz ?? (sampleRate.IsFail ? null : (uint)sampleRate),
                TotalSamples    = recording.TotalSamples ?? (samples.IsFail ? null : (ulong)samples),
                Channels        = recording.Channels ?? (channels.IsFail ? null : (byte)channels),
                BitDepth        = recording.BitDepth ?? (bitDepth.IsFail ? null : (byte)bitDepth),
                BitsPerSecond   = recording.BitsPerSecond ?? bitRate,
            };

            return(ValueTask.FromResult(recording));
        }