-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented automated tests for ConnectionProfileViewModel
- Loading branch information
1 parent
8dc9a00
commit 0397e71
Showing
7 changed files
with
155 additions
and
16 deletions.
There are no files selected for viewing
100 changes: 100 additions & 0 deletions
100
MessageCommunicator.TestGui.Tests/ConnectionProfileViewTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Text; | ||
using FakeItEasy; | ||
using MessageCommunicator.TestGui.Data; | ||
using MessageCommunicator.TestGui.Logic; | ||
using MessageCommunicator.TestGui.Views; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace MessageCommunicator.TestGui.Tests | ||
{ | ||
[TestClass] | ||
public class ConnectionProfileViewTests | ||
{ | ||
[TestMethod] | ||
public void SendPlainMessage() | ||
{ | ||
var connParams = new ConnectionParameters(); | ||
var connProfile = this.BuildFakeConnectionProfile(connParams); | ||
|
||
// Catch outgoing message | ||
string? sentMessage = null; | ||
A.CallTo(connProfile) | ||
.Where((callInfo) => callInfo.Method.Name == nameof(IConnectionProfile.SendMessageAsync)) | ||
.Invokes((callInfo) => | ||
{ | ||
sentMessage = (string?)callInfo.Arguments[0]; | ||
}); | ||
|
||
var testObject = new ConnectionProfileViewModel(connProfile); | ||
testObject.SendFormattingMode = SendFormattingMode.Plain; | ||
testObject.Command_SendMessage.Execute("DummyMessage \\\\"); | ||
|
||
Assert.IsTrue(sentMessage == "DummyMessage \\\\"); | ||
} | ||
|
||
[TestMethod] | ||
public void SendEscapedMessage() | ||
{ | ||
var connParams = new ConnectionParameters(); | ||
var connProfile = this.BuildFakeConnectionProfile(connParams); | ||
|
||
// Catch outgoing message | ||
string? sentMessage = null; | ||
A.CallTo(connProfile) | ||
.Where((callInfo) => callInfo.Method.Name == nameof(IConnectionProfile.SendMessageAsync)) | ||
.Invokes((callInfo) => | ||
{ | ||
sentMessage = (string?)callInfo.Arguments[0]; | ||
}); | ||
|
||
var testObject = new ConnectionProfileViewModel(connProfile); | ||
testObject.SendFormattingMode = SendFormattingMode.Escaped; | ||
testObject.Command_SendMessage.Execute("DummyMessage \\\\"); | ||
|
||
Assert.IsTrue(sentMessage == "DummyMessage \\"); | ||
} | ||
|
||
[TestMethod] | ||
public void SendHexMessage() | ||
{ | ||
var connParams = new ConnectionParameters(); | ||
var connProfile = this.BuildFakeConnectionProfile(connParams); | ||
|
||
// Catch outgoing message | ||
string? sentMessage = null; | ||
A.CallTo(connProfile) | ||
.Where((callInfo) => callInfo.Method.Name == nameof(IConnectionProfile.SendMessageAsync)) | ||
.Invokes((callInfo) => | ||
{ | ||
sentMessage = (string?)callInfo.Arguments[0]; | ||
}); | ||
|
||
var testObject = new ConnectionProfileViewModel(connProfile); | ||
testObject.SendFormattingMode = SendFormattingMode.Hex; | ||
testObject.Command_SendMessage.Execute("DummyMessage \\\\"); | ||
|
||
Assert.IsTrue(sentMessage == "DummyMessage \\"); | ||
} | ||
|
||
private IConnectionProfile BuildFakeConnectionProfile(ConnectionParameters connParams) | ||
{ | ||
var loggingMessages = new ObservableCollection<LoggingMessageWrapper>(); | ||
var sendReceiveMessages = new ObservableCollection<LoggingMessageWrapper>(); | ||
|
||
var connProfile = A.Fake<IConnectionProfile>(); | ||
A.CallTo(() => connProfile.Name).Returns("Dummy"); | ||
A.CallTo(() => connProfile.IsRunning).Returns(true); | ||
A.CallTo(() => connProfile.DetailLogging).Returns(loggingMessages); | ||
A.CallTo(() => connProfile.Messages).Returns(sendReceiveMessages); | ||
A.CallTo(() => connProfile.Parameters).Returns(connParams); | ||
A.CallTo(() => connProfile.RemoteEndpointDescription).Returns("Dummy Remote"); | ||
A.CallTo(() => connProfile.State).Returns(ConnectionState.Connected); | ||
|
||
return connProfile; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using MessageCommunicator.TestGui.Data; | ||
|
||
namespace MessageCommunicator.TestGui.Logic | ||
{ | ||
public interface IConnectionProfile | ||
{ | ||
string Name { get; } | ||
|
||
ConnectionParameters Parameters { get; } | ||
|
||
ObservableCollection<LoggingMessageWrapper> DetailLogging { get; } | ||
|
||
ObservableCollection<LoggingMessageWrapper> Messages { get; } | ||
|
||
bool IsRunning { get; } | ||
|
||
ConnectionState State { get; } | ||
|
||
string RemoteEndpointDescription { get; } | ||
|
||
Task ChangeParametersAsync(ConnectionParameters newConnParameters); | ||
|
||
Task SendMessageAsync(string message); | ||
|
||
Task StartAsync(); | ||
|
||
Task StopAsync(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters