From b528f52b8bbdc366417e8dc921ef30ee1be580d2 Mon Sep 17 00:00:00 2001 From: Leo ecker Date: Fri, 5 Nov 2021 13:48:27 +0100 Subject: [PATCH] #75 --- .../Estimator.Tests/Pages/CreateRoomTests.cs | 56 ++++++++++++++++++- .../Estimator.Tests/Pages/JoinRoomTests.cs | 34 ++++++++++- Estimator/Estimator/Pages/CreateRoom.razor.cs | 12 +++- Estimator/Estimator/Pages/JoinRoom.razor.cs | 12 +++- 4 files changed, 108 insertions(+), 6 deletions(-) diff --git a/Estimator/Estimator.Tests/Pages/CreateRoomTests.cs b/Estimator/Estimator.Tests/Pages/CreateRoomTests.cs index 3715cac..fcd1ce9 100644 --- a/Estimator/Estimator.Tests/Pages/CreateRoomTests.cs +++ b/Estimator/Estimator.Tests/Pages/CreateRoomTests.cs @@ -1,6 +1,60 @@ -namespace Estimator.Tests.Pages +using Estimator.Pages; +using Xunit; + +namespace Estimator.Tests.Pages { public class CreateRoomTests { + [Theory] + [InlineData("Max Mustermann", false)] + [InlineData("", true)] + public void IsParameterEmptyTest(string userName, bool isUsernameEmpty) + { + #region Assign + + var creatRoom = new CreateRoom(); + + creatRoom.Username = userName; + + #endregion + + #region Act + + var result = creatRoom.IsUsernameEmpty(); + + #endregion + + #region Assert + + Assert.Equal(isUsernameEmpty, result); + + #endregion + } + + [Theory] + [InlineData("Fibonacci", 1)] + [InlineData("T-Shirt", 2)] + [InlineData("Test", 2)] + public void ConvertTypeTest(string type , int convertType) + { + #region Assign + + var creatRoom = new CreateRoom(); + + #endregion + + #region Act + + var result = creatRoom.ConvertType(type); + + #endregion + + #region Assert + + Assert.Equal(convertType, result); + + #endregion + } + } } diff --git a/Estimator/Estimator.Tests/Pages/JoinRoomTests.cs b/Estimator/Estimator.Tests/Pages/JoinRoomTests.cs index fa11c70..39a3963 100644 --- a/Estimator/Estimator.Tests/Pages/JoinRoomTests.cs +++ b/Estimator/Estimator.Tests/Pages/JoinRoomTests.cs @@ -1,6 +1,38 @@ -namespace Estimator.Tests.Pages +using System; +using Estimator.Data; +using Estimator.Pages; +using Xunit; + +namespace Estimator.Tests.Pages { public class JoinRoomTests { + [Theory] + [InlineData("12345", "Max Mustermann", false)] + [InlineData("", "", true)] + [InlineData("123456", "", true)] + public void IsParameterEmptyTest(string roomId, string userName, bool isParameterEmpty) + { + #region Assign + + var joinRoom = new JoinRoom(); + + joinRoom.RoomId = roomId; + joinRoom.Username = userName; + + #endregion + + #region Act + + var result = joinRoom.IsParameterEmpty(); + + #endregion + + #region Assert + + Assert.Equal(isParameterEmpty, result); + + #endregion + } } } diff --git a/Estimator/Estimator/Pages/CreateRoom.razor.cs b/Estimator/Estimator/Pages/CreateRoom.razor.cs index c31c0af..616be60 100644 --- a/Estimator/Estimator/Pages/CreateRoom.razor.cs +++ b/Estimator/Estimator/Pages/CreateRoom.razor.cs @@ -2,9 +2,12 @@ using Microsoft.JSInterop; using System; using System.Diagnostics; +using System.Runtime.CompilerServices; using System.Threading.Tasks; using Estimator.Data.Interface; +[assembly: InternalsVisibleTo("Estimator.Tests.Pages")] + namespace Estimator.Pages { public partial class CreateRoom @@ -20,7 +23,7 @@ public partial class CreateRoom private async void CreateNewRoom() { - if (this.Username == string.Empty) + if (this.IsUsernameEmpty()) { await this.Alert("Please enter a username!"); return; @@ -41,7 +44,12 @@ private async void CreateNewRoom() } } - private int ConvertType(string type) + internal bool IsUsernameEmpty() + { + return this.Username == String.Empty; + } + + internal int ConvertType(string type) { return type == "Fibonacci" ? 1 : 2; } diff --git a/Estimator/Estimator/Pages/JoinRoom.razor.cs b/Estimator/Estimator/Pages/JoinRoom.razor.cs index 043bbb7..09efd82 100644 --- a/Estimator/Estimator/Pages/JoinRoom.razor.cs +++ b/Estimator/Estimator/Pages/JoinRoom.razor.cs @@ -2,8 +2,11 @@ using Microsoft.AspNetCore.Components; using Microsoft.JSInterop; using System; +using System.Runtime.CompilerServices; using System.Threading.Tasks; +[assembly: InternalsVisibleTo("Estimator.Tests.Pages")] + namespace Estimator.Pages { public partial class JoinRoom @@ -13,9 +16,10 @@ public partial class JoinRoom private async void JoinRoomById() { - if (this.Username.Equals(string.Empty) || this.RoomId.Equals(string.Empty)) + + if(this.IsParameterEmpty()) { - await this.Alert("Username or RoomId is empty!"); + await Alert("Username or RoomId is empty!"); return; } @@ -37,6 +41,10 @@ private async void JoinRoomById() await this.Alert("Something went wrong!"); } } + internal bool IsParameterEmpty() + { + return this.Username.Equals(string.Empty) || this.RoomId.Equals(string.Empty); + } private async Task Alert(string alertMessage) {