SoundTests ClassDelta Engine Documentation
Inheritance Hierarchy

System Object
  DeltaEngine.Platforms TestWithMocksOrVisually
    DeltaEngine.Multimedia.Tests SoundTests

Namespace: DeltaEngine.Multimedia.Tests
Assembly: DeltaEngine.Multimedia.Tests (in DeltaEngine.Multimedia.Tests.dll) Version: 1.1.1.0 (1.1.1)
Syntax

public class SoundTests : TestWithMocksOrVisually

The SoundTests type exposes the following members.

Constructors

  NameDescription
Public methodSoundTests
Initializes a new instance of the SoundTests class
Top
Methods

  NameDescription
Protected methodAdvanceTimeAndUpdateEntities (Inherited from TestWithMocksOrVisually.)
Public methodDisposeSoundInstance
Public methodDisposeSoundInstancesFromSoundClass
Public methodInitializeResolver (Inherited from TestWithMocksOrVisually.)
Public methodNumberOfPlayingInstances
Public methodPlayAndStop
Public methodPlayAndStopEvents
Public methodPlayAndStopInstance
Public methodPlayMultipleSoundInstances
Public methodPlaySound
Public methodPlaySoundAndDispose
Public methodPlaySoundFromConvertedSoundOggContent
Public methodPlaySoundFromMp3MusicContent
Public methodPlaySoundFromOggMusicContent
Public methodPlaySoundFromWmaMusicContent
Public methodPlaySoundInstance
Public methodPlaySoundLeft
Public methodPlaySoundOnClick
Public methodPlaySoundRightAndPitched
Public methodPlaySoundVerySilent
Protected methodRegisterMock T  (Inherited from TestWithMocksOrVisually.)
Protected methodResolve T  (Inherited from TestWithMocksOrVisually.)
Protected methodRunAfterFirstFrame (Inherited from TestWithMocksOrVisually.)
Public methodRunTestAndDisposeResolverWhenDone (Inherited from TestWithMocksOrVisually.)
Public methodShouldThrowIfSoundNotLoadedInDebugModeOrWithDebuggerAttached
Top
Properties

  NameDescription
Protected propertyIsMockResolver (Inherited from TestWithMocksOrVisually.)
Top
Examples

[Test]
public void PlaySound()
{
    ContentLoader.Load<Sound>("DefaultSound").Play();
}
[Test]
public void PlaySoundFromMp3MusicContent()
{
    ContentLoader.Load<Sound>("DefaultMusic").Play();
}
[Test]
public void PlaySoundFromOggMusicContent()
{
    ContentLoader.Load<Sound>("OggMusic").Play();
}
[Test]
public void PlaySoundFromWmaMusicContent()
{
    ContentLoader.Load<Sound>("WmaMusic").Play();
}
[Test]
public void PlaySoundFromConvertedSoundOggContent()
{
    ContentLoader.Load<Sound>("TurnPage").Play();
}
[Test]
public void PlaySoundVerySilent()
{
    ContentLoader.Load<Sound>("DefaultSound").Play(0.1f);
}
[Test]
public void PlaySoundOnClick()
{
    new Command(() => ContentLoader.Load<Sound>("DefaultSound").Play()).Add(
        new MouseButtonTrigger());
}
[Test]
public void PlaySoundAndDispose()
{
    var sound = ContentLoader.Load<Sound>("DefaultSound");
    sound.Dispose();
}
[Test]
public void PlaySoundLeft()
{
    ContentLoader.Load<Sound>("DefaultSound").Play(1, -1);
}
[Test]
public void PlaySoundRightAndPitched()
{
    var sound = ContentLoader.Load<Sound>("DefaultSound");
    var instance = sound.CreateSoundInstance();
    instance.Panning = 1.0f;
    instance.Pitch = 2.0f;
    instance.Play();
}
[Test]
public void PlaySoundInstance()
{
    var sound = ContentLoader.Load<Sound>("DefaultSound");
    var instance = sound.CreateSoundInstance();
    Assert.AreEqual(0.48f, sound.LengthInSeconds, 0.01f);
    Assert.AreEqual(false, instance.IsPlaying);
    instance.Play();
    Assert.AreEqual(true, instance.IsPlaying);
}
[Test]
public void PlayMultipleSoundInstances()
{
    var sound = ContentLoader.Load<Sound>("DefaultSound");
    var instance1 = sound.CreateSoundInstance();
    var instance2 = sound.CreateSoundInstance();
    Assert.AreEqual(false, instance1.IsPlaying);
    instance1.Play();
    Assert.AreEqual(true, instance1.IsPlaying);
    Assert.AreEqual(false, instance2.IsPlaying);
    instance2.Volume = 0.5f;
    instance2.Panning = -1.0f;
    instance2.Play();
    Assert.AreEqual(true, instance2.IsPlaying);
}
[Test]
public void NumberOfPlayingInstances()
{
    var sound = ContentLoader.Load<Sound>("DefaultSound");
    Assert.AreEqual(0, sound.NumberOfPlayingInstances);
    sound.Play();
    Assert.AreEqual(1, sound.NumberOfPlayingInstances);
    sound.Play();
    Assert.AreEqual(2, sound.NumberOfPlayingInstances);
}
[Test]
public void PlayAndStop()
{
    var sound = ContentLoader.Load<Sound>("DefaultSound");
    Assert.IsFalse(sound.IsAnyInstancePlaying);
    sound.Play();
    Assert.IsTrue(sound.IsAnyInstancePlaying);
    sound.StopAll();
    WaitUntilSoundStateIsUpdated();
    Assert.IsFalse(sound.IsAnyInstancePlaying);
    sound.Play();
}
[Test]
public void PlayAndStopEvents()
{
    var sound = ContentLoader.Load<Sound>("DefaultSound");
    sound.OnPlay += instance => Assert.True(sound.IsAnyInstancePlaying);
    sound.OnStop += instance => Assert.False(sound.IsAnyInstancePlaying);
    sound.Play();
    sound.StopAll();
    WaitUntilSoundStateIsUpdated();
}
[Test]
public void PlayAndStopInstance()
{
    var sound = ContentLoader.Load<Sound>("DefaultSound");
    var instance = sound.CreateSoundInstance();
    Assert.IsFalse(sound.IsAnyInstancePlaying);
    Assert.AreEqual(0f, instance.PositionInSeconds);
    instance.Play();
    Assert.IsTrue(sound.IsAnyInstancePlaying);
    WaitUntilSoundStateIsUpdated();
    Assert.Greater(instance.PositionInSeconds, 0f);
    sound.StopAll();
    WaitUntilSoundStateIsUpdated();
    Assert.AreEqual(0f, instance.PositionInSeconds);
    Assert.IsFalse(sound.IsAnyInstancePlaying);
}
[Test]
public void DisposeSoundInstance()
{
    var sound = ContentLoader.Load<Sound>("DefaultSound");
    var instance = sound.CreateSoundInstance();
    Assert.AreEqual(1, sound.NumberOfInstances);
    Assert.AreEqual(0, sound.NumberOfPlayingInstances);
    instance.Dispose();
    Assert.AreEqual(0, sound.NumberOfInstances);
    Assert.AreEqual(0, sound.NumberOfPlayingInstances);
}
[Test]
public void DisposeSoundInstancesFromSoundClass()
{
    var sound = ContentLoader.Load<Sound>("DefaultSound");
    sound.CreateSoundInstance();
    sound.Play();
    Assert.AreEqual(2, sound.NumberOfInstances);
    Assert.AreEqual(1, sound.NumberOfPlayingInstances);
    sound.Dispose();
    Assert.AreEqual(0, sound.NumberOfInstances);
    Assert.AreEqual(0, sound.NumberOfPlayingInstances);
}
[Test]
public void ShouldThrowIfSoundNotLoadedInDebugModeOrWithDebuggerAttached()
{
    if (!Debugger.IsAttached)
        return;
    //ncrunch: no coverage start
    Assert.Throws<ContentLoader.ContentNotFound>(
        () => ContentLoader.Load<Sound>("UnavailableSound"));
}
See Also