Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Assignment3
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SWT
Assignments
Assignment3
Commits
1eca6da5
Commit
1eca6da5
authored
1 year ago
by
Jonas Landsfeldt
Browse files
Options
Downloads
Patches
Plain Diff
New mock method for buzzer
parent
bd5c5486
No related branches found
Branches containing commit
No related tags found
Loading
Pipeline
#194396
passed
1 year ago
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Microwave.Classes/Boundary/Buzzer.cs
+8
-0
8 additions, 0 deletions
Microwave.Classes/Boundary/Buzzer.cs
Microwave.Test.Unit/BuzzerTest.cs
+18
-13
18 additions, 13 deletions
Microwave.Test.Unit/BuzzerTest.cs
with
26 additions
and
13 deletions
Microwave.Classes/Boundary/Buzzer.cs
+
8
−
0
View file @
1eca6da5
...
...
@@ -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
This diff is collapsed.
Click to expand it.
Microwave.Test.Unit/BuzzerTest.cs
+
18
−
13
View file @
1eca6da5
...
...
@@ -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
Buzz
ToConsole_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
=
100
0
;
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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment