public void TestReadMonoSamplesFromFile() { var waveStream = new Mock <WaveStream>(MockBehavior.Strict); naudioFactory.Setup(factory => factory.GetStream("path-to-audio-file")).Returns(waveStream.Object); const int Mono = 1; WaveFormat waveFormat = WaveFormat.CreateIeeeFloatWaveFormat(5512, Mono); waveStream.Setup(stream => stream.WaveFormat).Returns(waveFormat); waveStream.Setup(stream => stream.TotalTime).Returns(TimeSpan.FromSeconds(120)); waveStream.Setup(stream => stream.Close()); const double StartAt = 20d; waveStream.Setup(stream => stream.CurrentTime).Returns(new TimeSpan()); waveStream.SetupSet(stream => stream.CurrentTime = TimeSpan.FromSeconds(StartAt)); var resampler = new Mock <MediaFoundationTransform>(MockBehavior.Strict, new object[] { waveStream.Object, waveFormat }); resampler.Protected().Setup("Dispose", new object[] { true }); naudioFactory.Setup(factory => factory.GetResampler(waveStream.Object, 5512, Mono)).Returns(resampler.Object); float[] samplesArray = new float[1024]; const double SecondsToRead = 10d; samplesAggregator.Setup(agg => agg.ReadSamplesFromSource(It.IsAny <NAudioSamplesProviderAdapter>(), SecondsToRead, 5512)) .Returns(samplesArray); var result = sourceReader.ReadMonoFromSource("path-to-audio-file", 5512, SecondsToRead, StartAt); Assert.AreSame(samplesArray, result); }
public void TestReadMonoSamplesFromFile() { Mock <WaveStream> waveStream = new Mock <WaveStream>(MockBehavior.Strict); naudioFactory.Setup(factory => factory.GetStream("path-to-audio-file")).Returns(waveStream.Object); const int Mono = 1; WaveFormat waveFormat = WaveFormat.CreateIeeeFloatWaveFormat(SampleRate, Mono); waveStream.Setup(stream => stream.WaveFormat).Returns(waveFormat); waveStream.Setup(stream => stream.Close()); const int StartAt = 20; waveStream.Setup(stream => stream.Seek(SampleRate * waveFormat.BitsPerSample / 8 * StartAt, SeekOrigin.Begin)) .Returns(440960); Mock <MediaFoundationTransform> resampler = new Mock <MediaFoundationTransform>( MockBehavior.Strict, new object[] { waveStream.Object, waveFormat }); resampler.Protected().Setup("Dispose", new object[] { true }); naudioFactory.Setup(factory => factory.GetResampler(waveStream.Object, SampleRate, Mono)).Returns(resampler.Object); float[] samplesArray = TestUtilities.GenerateRandomFloatArray(1024); const int SecondsToRead = 10; samplesAggregator.Setup( agg => agg.ReadSamplesFromSource(It.IsAny <NAudioSamplesProviderAdapter>(), SecondsToRead, SampleRate)).Returns( samplesArray); var result = sourceReader.ReadMonoFromSource("path-to-audio-file", SampleRate, SecondsToRead, StartAt); Assert.AreSame(samplesArray, result); }