Skip to content
Snippets Groups Projects
Commit 1eca6da5 authored by Jonas Landsfeldt's avatar Jonas Landsfeldt
Browse files

New mock method for buzzer

parent bd5c5486
No related branches found
No related tags found
Loading
Pipeline #194396 passed
......@@ -25,5 +25,13 @@ namespace Microwave.Classes.Boundary
Thread.Sleep(burstDurationMs);
}
}
public void BuzzToConsole(int numberOfBursts, int burstDurationMs)
{
for (int i = 0; i < numberOfBursts; i++)
{
Console.WriteLine("Buzz");
Thread.Sleep(burstDurationMs);
}
}
}
}
\ No newline at end of file
......@@ -4,8 +4,10 @@ using System.IO;
using System.Media;
using System.Threading;
using Microwave.Classes.Boundary;
using Microsoft.VisualStudio.TestPlatform.Utilities;
using System.Linq;
namespace Microwave.Test.Unit.Boundary
namespace Microwave.Test.Unit
{
[TestFixture]
public class BuzzerTest
......@@ -30,24 +32,27 @@ namespace Microwave.Test.Unit.Boundary
}
[Test]
public void Buzz_FileFound_PlaysSound()
public void BuzzToConsole_ConsoleOutput_PrintsBuzz()
{
// Arrange
var soundFileName = "yes.wav";
var soundFilePath = Path.Combine(Directory.GetCurrentDirectory(), "Sounds", soundFileName);
var player = new SoundPlayer(soundFilePath);
var numberOfBursts = 3;
var burstDurationMs = 1000;
var burstDurationMs = 100;
// Act
this.buzzer.Buzz(numberOfBursts, burstDurationMs, soundFileName);
// Assert
for (int i = 0; i < numberOfBursts; i++)
using (var stringWriter = new StringWriter())
{
player.PlaySync();
Thread.Sleep(burstDurationMs);
// Redirect the console output to the StringWriter
Console.SetOut(stringWriter);
// Act
this.buzzer.BuzzToConsole(numberOfBursts, burstDurationMs);
// Assert
var expectedOutput = string.Join(Environment.NewLine, Enumerable.Repeat("Buzz", numberOfBursts));
Assert.AreEqual(expectedOutput, stringWriter.ToString().Trim());
}
// Restore the console output
Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = true });
}
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment