mercredi 18 mai 2016

how to test system.media.SoundPlayer

I am trying to test a class, whitch shall only play a little sound. I use Windows 10, Visual Studio Enterprise. This is the class which has to be tested:

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Avss
{
public class SoundManager
{
    public void PlaySound(string path)
    {
        System.Media.SoundPlayer player = new System.Media.SoundPlayer();
        player.SoundLocation = path;
        player.Load();
        player.Play();
    }
}
}

And this is the class in whitch I want to test it:

using Microsoft.VisualStudio.TestTools.UnitTesting;
using Avss;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Avss.Tests
{
[TestClass()]
public class SoundManagerTests
{
    SoundManager mTest = new SoundManager();
    [TestMethod()]
    public void PlaySoundTest()
    {
        string path = "044.wav";
        mTest.PlaySound(path);
        Assert.Fail();
    }
}
}

My question: How must the test class look like? I just want to test, if "PlaySound()" can play any sound.

Thanks for helping!

Aucun commentaire:

Enregistrer un commentaire