-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathConferenceTests.cs
82 lines (69 loc) · 2.32 KB
/
ConferenceTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System;
using System.Collections.Generic;
using NUnit.Framework;
namespace HelloWorld.Tests
{
[TestFixture]
public class ConferenceTests
{
[Test]
public void AddSpeaker_ShouldAddSpeakerToConference()
{
// Arrange
var conference = new Conference("Test Conference", "Test Location", "Test Date");
var speaker = new Speaker("Test Speaker", "Test Language", 30);
// Act
conference.AddSpeaker(speaker);
// Assert
Assert.Contains(speaker, conference.Speakers);
}
[Test]
public void RemoveSpeaker_ShouldRemoveSpeakerFromConference()
{
// Arrange
var conference = new Conference("Test Conference", "Test Location", "Test Date");
var speaker = new Speaker("Test Speaker", "Test Language", 30);
conference.AddSpeaker(speaker);
// Act
conference.RemoveSpeaker(speaker);
// Assert
Assert.DoesNotContain(speaker, conference.Speakers);
}
[Test]
public void PrintConferenceDetails_ShouldPrintCorrectDetails()
{
// Arrange
var conference = new Conference("Test Conference", "Test Location", "Test Date");
// Act
using (var consoleOutput = new ConsoleOutput())
{
conference.PrintConferenceDetails();
var output = consoleOutput.GetOuput();
// Assert
Assert.IsTrue(output.Contains("Conference Name: Test Conference"));
Assert.IsTrue(output.Contains("Conference Location: Test Location"));
Assert.IsTrue(output.Contains("Conference Date: Test Date"));
}
}
}
public class ConsoleOutput : IDisposable
{
private StringWriter stringWriter;
private TextWriter originalOutput;
public ConsoleOutput()
{
stringWriter = new StringWriter();
originalOutput = Console.Out;
Console.SetOut(stringWriter);
}
public string GetOuput()
{
return stringWriter.ToString();
}
public void Dispose()
{
Console.SetOut(originalOutput);
stringWriter.Dispose();
}
}
}