Skip to content
This repository was archived by the owner on Jan 21, 2022. It is now read-only.

Commit a01c5ee

Browse files
authored
Merge pull request #64 from Standaard-boos/MergeSprint2
Merge sprint2 into main
2 parents 589ab88 + 87c8ad6 commit a01c5ee

145 files changed

Lines changed: 5520 additions & 991 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Gateway.Test/Gateway.Test.csproj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,13 @@
1717
<ProjectReference Include="..\Gateway\Gateway.csproj" />
1818
</ItemGroup>
1919

20+
<ItemGroup>
21+
<None Update="ReSharperTestRunner.dll.config">
22+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
23+
</None>
24+
<None Update="testhost.dll.config">
25+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
26+
</None>
27+
</ItemGroup>
28+
2029
</Project>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using NUnit.Framework;
2+
3+
namespace Gateway.Test
4+
{
5+
public class Gateway_AccountDataAccess_CheckIfAccountExists
6+
{
7+
[Test]
8+
public void CheckIfAccountExists_ExistingAccount_ReturnsTrue()
9+
{
10+
// Arrange
11+
const string email = "ThisAccountDoesExist@wafoe.nl";
12+
13+
// Act
14+
bool result = AccountDataAccess.CheckIfAccountExists(email);
15+
16+
// Assert
17+
Assert.IsTrue(result);
18+
}
19+
20+
[Test]
21+
public void CheckIfAccountExists_NonExistingAccount_ReturnsFalse()
22+
{
23+
// Arrange
24+
const string email = "ThisAccountDoesNotExist";
25+
26+
// Act
27+
bool result = AccountDataAccess.CheckIfAccountExists(email);
28+
29+
// Assert
30+
Assert.IsFalse(result);
31+
}
32+
}
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using NUnit.Framework;
2+
3+
namespace Gateway.Test
4+
{
5+
public class Gateway_AccountDataAccess_CheckIfAccountIsVerified
6+
{
7+
[Test]
8+
public void CheckIfAccountIsVerified_AccountVerified_ReturnsTrue()
9+
{
10+
// Arrange
11+
const string email = "ThisAccountDoesExist@wafoe.nl";
12+
13+
// Act
14+
bool result = AccountDataAccess.CheckIfAccountIsVerified(email);
15+
16+
// Assert
17+
Assert.IsTrue(result);
18+
}
19+
20+
[Test]
21+
public void CheckIfAccountIsVerified_AccountNotVerified_ReturnsFalse()
22+
{
23+
// Arrange
24+
const string email = "ThisUnverifiedAccountDoesExist@wafoe.nl";
25+
26+
// Act
27+
bool result = AccountDataAccess.CheckIfAccountIsVerified(email);
28+
29+
// Assert
30+
Assert.IsFalse(result);
31+
}
32+
}
33+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using NUnit.Framework;
2+
3+
namespace Gateway.Test
4+
{
5+
public class Gateway_AccountDataAccess_CheckIfVerificationCodeMatches
6+
{
7+
[Test]
8+
public void CheckIfVerificationCodeMatches_ValidVerificationCode_ReturnsTrue()
9+
{
10+
// Arrange
11+
const string email = "ThisAccountDoesExist@wafoe.nl";
12+
const string verificationCode = "123456";
13+
14+
// Act
15+
bool result = AccountDataAccess.CheckIfVerificationCodeMatches(verificationCode, email);
16+
17+
// Assert
18+
Assert.IsTrue(result);
19+
}
20+
21+
[Test]
22+
public void CheckIfVerificationCodeMatches_InvalidVerificationCode_ReturnsFalse()
23+
{
24+
// Arrange
25+
const string email = "ThisAccountDoesExist@wafoe.nl";
26+
const string verificationCode = "000000";
27+
28+
// Act
29+
bool result = AccountDataAccess.CheckIfVerificationCodeMatches(verificationCode, email);
30+
31+
// Assert
32+
Assert.IsFalse(result);
33+
}
34+
}
35+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using NUnit.Framework;
2+
using System;
3+
4+
namespace Gateway.Test
5+
{
6+
public class Gateway_AccountDataAccess_CreateAccount
7+
{
8+
[Test]
9+
public void CreateAccount_NonExistingAccount_ThrowsNoException()
10+
{
11+
// Arrange
12+
Random random = new Random((int)DateTime.UtcNow.Ticks); // Generate random email and password to basically ensure it does not exist already in the database
13+
14+
string email = random.Next().ToString() + random.Next().ToString();
15+
string password = random.Next().ToString() + random.Next().ToString();
16+
const string verificationCode = "123456";
17+
18+
// Act
19+
static void HasSuccessfullyRegistered(string email, string password)
20+
{
21+
try
22+
{
23+
AccountDataAccess.CreateAccount(email, password, verificationCode);
24+
AccountDataAccess.DeleteAccount(email); // Also tests the delete method to clean up garbage data from the database
25+
}
26+
catch (Exception)
27+
{
28+
throw;
29+
}
30+
}
31+
32+
// Assert
33+
Assert.DoesNotThrow(() => HasSuccessfullyRegistered(email, password));
34+
}
35+
}
36+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using NUnit.Framework;
2+
3+
namespace Gateway.Test
4+
{
5+
public class Gateway_AccountDataAccess_GetHashedPassswordFromAccount
6+
{
7+
/// <summary>
8+
/// This test should return a value starting with a dollar sign, because that is the first char in a hashed and salted string.
9+
/// </summary>
10+
[Test]
11+
public void GetHashedPassswordFromAccount_ExistingAccount_ReturnsValueStartingWithDollarSign()
12+
{
13+
// Arrange
14+
const string email = "ThisAccountDoesExist@wafoe.nl";
15+
16+
// Act
17+
string hashedPassword = AccountDataAccess.GetHashedPassswordFromAccount(email);
18+
bool startsWithDollarSign = hashedPassword[0] == '$';
19+
20+
// Assert
21+
Assert.IsTrue(startsWithDollarSign);
22+
}
23+
}
24+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using NUnit.Framework;
2+
using System;
3+
4+
namespace Gateway.Test
5+
{
6+
public class Gateway_AccountDataAccess_GetUserIDFromAccount
7+
{
8+
[Test]
9+
public void GetUserIDFromAccount_ExistingUserID_ReturnsCorrectID()
10+
{
11+
// Arrange
12+
const string email = "ThisAccountDoesExist@wafoe.nl";
13+
14+
// Act
15+
int userID = AccountDataAccess.GetUserIDFromAccount(email);
16+
17+
// Assert
18+
Assert.AreEqual(1, userID);
19+
}
20+
}
21+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using NUnit.Framework;
2+
3+
namespace Gateway.Test
4+
{
5+
public class Gateway_FiddleHelper_GetConnectionStringSql
6+
{
7+
[Test]
8+
public void GetConnectionStringSql_ValidString_ReturnsValue()
9+
{
10+
// Arrange
11+
const string connectionString = "StudentMatcherDB";
12+
13+
// Act
14+
string result = FiddleHelper.GetConnectionStringSql(connectionString);
15+
16+
// Assert
17+
Assert.IsNotEmpty(result);
18+
}
19+
}
20+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
using System;
2+
using NUnit.Framework;
3+
using System.Collections.Generic;
4+
5+
namespace Gateway.Test
6+
{
7+
public class Gateway_MatchDataAccess_AddLikeToUserIDs
8+
{
9+
static void CleanUp(int id1, int id2)
10+
{
11+
MatchDataAccess.RemoveMatchFromUser(id1, id2);
12+
}
13+
14+
[Test]
15+
public void AddLikeToUserIDs_NonExistingMatch_ThrowsNoError()
16+
{
17+
// Arrange
18+
const int userID1 = 1; // ThisAccountDoesExist@wafoe.nl
19+
const int userID2 = 12; // ThisUnverifiedAccountDoesExist@wafoe.nl
20+
21+
// Act
22+
void AddLike()
23+
{
24+
try
25+
{
26+
MatchDataAccess.AddLikeToUserIDs(userID1, userID2, 1); // Relation ship can be a random value - I chose 1
27+
}
28+
catch (Exception)
29+
{
30+
throw;
31+
}
32+
33+
}
34+
35+
// Assert
36+
Assert.DoesNotThrow(() => AddLike(), "AddLikeToUserIDs");
37+
Assert.DoesNotThrow(() => CleanUp(userID1, userID2), "RemoveMatchFromUser");
38+
}
39+
40+
[Test]
41+
public void AddLikeToUserIDs_ExistingMatch_ThrowsError()
42+
{
43+
// Arrange
44+
const int userID1 = 1; // ThisAccountDoesExist@wafoe.nl
45+
const int userID2 = 12; // ThisUnverifiedAccountDoesExist@wafoe.nl
46+
47+
// Act
48+
void AddLike()
49+
{
50+
try
51+
{
52+
MatchDataAccess.AddLikeToUserIDs(userID1, userID2, 1); // Relation ship can be a random value - I chose 1
53+
}
54+
catch (Exception)
55+
{
56+
throw;
57+
}
58+
59+
}
60+
61+
// Assert
62+
Assert.DoesNotThrow(() => AddLike(), "Should not throw exception");
63+
Assert.Throws<System.Data.SqlClient.SqlException>(() => AddLike(), "Should throw exception");
64+
Assert.DoesNotThrow(() => CleanUp(userID1, userID2), "RemoveMatchFromUser");
65+
}
66+
}
67+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
using System;
2+
using NUnit.Framework;
3+
using System.Collections.Generic;
4+
using Model;
5+
using System.Linq;
6+
7+
namespace Gateway.Test
8+
{
9+
public class Gateway_MatchDataAccess_CheckIfUserLiked
10+
{
11+
[Test]
12+
public void CheckIfUserLiked_DidLike_ReturnsTrue()
13+
{
14+
// Arrange
15+
const int userID1 = 1; // ThisAccountDoesExist@wafoe.nl
16+
const int userID2 = 12; // ThisUnverifiedAccountDoesExist@wafoe.nl
17+
bool? result = null;
18+
19+
// Act
20+
List<int> listOfMatches = MatchDataAccess.GetAllMatchesFromUser(userID1, MatchOrLike.Matched);
21+
22+
void CheckLike()
23+
{
24+
try
25+
{
26+
MatchDataAccess.AddLikeToUserIDs(userID1, userID2, 1); // First add the match to the database
27+
result = MatchDataAccess.CheckIfUserLiked(userID2, userID1); // Turn them around just to test
28+
}
29+
catch (Exception)
30+
{
31+
throw;
32+
}
33+
}
34+
35+
void CleanUp()
36+
{
37+
MatchDataAccess.RemoveMatchFromUser(userID1, userID2); // Clean up the match
38+
}
39+
40+
// Assert
41+
Assert.DoesNotThrow(() => CheckLike(), "CheckIfUserLiked");
42+
Assert.IsTrue(result, "Liked?");
43+
Assert.DoesNotThrow(() => CleanUp(), "Clean up");
44+
}
45+
46+
[Test]
47+
public void CheckIfUserLiked_DidNotLike_ReturnsFalse()
48+
{
49+
// Arrange
50+
const int userID1 = 1; // ThisAccountDoesExist@wafoe.nl
51+
const int userID2 = 12; // ThisUnverifiedAccountDoesExist@wafoe.nl
52+
bool? result = null;
53+
54+
// Act
55+
List<int> listOfMatches = MatchDataAccess.GetAllMatchesFromUser(userID1, MatchOrLike.Matched);
56+
57+
void CheckLike()
58+
{
59+
try
60+
{
61+
result = MatchDataAccess.CheckIfUserLiked(userID1, userID2);
62+
}
63+
catch (Exception)
64+
{
65+
throw;
66+
}
67+
}
68+
69+
// Assert
70+
Assert.DoesNotThrow(() => CheckLike(), "CheckIfUserLiked");
71+
Assert.IsFalse(result, "Liked?");
72+
}
73+
}
74+
}

0 commit comments

Comments
 (0)