Skip to content

Commit

Permalink
Merge branch 'development' into samlFramework
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderHansson4225 committed Sep 28, 2023
2 parents fb2724d + 46beeae commit 83b8234
Show file tree
Hide file tree
Showing 80 changed files with 103,573 additions and 94 deletions.
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,21 @@
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs

# Secrets, such as password or key files
# Notification configuration file - includes keys, tokens, etc
google-services.json

# Service account key - includes keys, tokens, etc
serviceAccountKey.json

# Mono auto generated files
mono_crash.*

# Project secrets
secrets.json
*firebase-adminsdk-*.json


# Build results
[Dd]ebug/
[Dd]ebugPublic/
Expand Down
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
"ASPNETCORE_ENVIRONMENT": "Production"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
Expand Down
2 changes: 1 addition & 1 deletion Nexpo.Tests/Controllers/CompaniesControllerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public async Task GetMe()
Assert.True(responseObject.DaysAtArkad.Contains(DateTime.Parse("2023-01-01")), "Wrong, Received: " + responseObject.DaysAtArkad[0]);
Assert.True(responseObject.DaysAtArkad.Contains(DateTime.Parse("2023-02-02")), "Wrong, Received: " + responseObject.DaysAtArkad[1]);
Assert.True(responseObject.DaysAtArkad.Contains(DateTime.Parse("2023-03-03")), "Wrong, Received: " + responseObject.DaysAtArkad[2]);

}

[Fact]
Expand Down
1 change: 0 additions & 1 deletion Nexpo.Tests/Controllers/EventsControllerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public async Task GetAllAsAdmin()
Assert.True(response.StatusCode.Equals(HttpStatusCode.OK), "Wrong status code. Expected: OK. Received: " + response.StatusCode.ToString());

var responseList = JsonConvert.DeserializeObject<List<TicketInfoDTO>>(await response.Content.ReadAsStringAsync());
Assert.True(responseList.Count == 3, "Wrong number of tickets. Expected: 3. Received: " + responseList.Count);

var firstTicket = responseList.Find(r => r.ticket.Id == -1);
var thirdTicket = responseList.Find(r => r.ticket.Id == -3);
Expand Down
85 changes: 78 additions & 7 deletions Nexpo.Tests/Controllers/FAQControllerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,16 @@ public async Task GetAllAsAdmin()

//Verify all FAQs
Assert.True(question1.Question.Equals("Frequent Asked Question 1"), "Wrong question Expected: Frequent Asked Question 1. Received: " + question1.Question);
Assert.True(question1.Answer.Equals("Gooooddd answerrr!!!"), "Wrong question Expected: Gooooddd answerrr!!!. Received: " + question1.Answer);

Assert.True(question2.Question.Equals("Frequent Asked Question 2"), "Wrong question Expected: Frequent Asked Question 2. Received: " + question2.Question);
Assert.True(question2.Answer.Equals("Ye probably"), "Wrong question Expected: Ye probably. Received: " + question3.Answer);

Assert.True(question3.Question.Equals("Frequent Asked Question 3"), "Wrong question Expected: Frequent Asked Question 3. Received: " + question3.Question);
Assert.True(question3.Answer.Equals("Hehe nop"), "Wrong question Expected: Hehe nop. Received: " + question4.Answer);

Assert.True(question4.Question.Equals("Frequent Asked Question 4"), "Wrong question Expected: Frequent Asked Question 4. Received: " + question4.Question);
Assert.True(question4.Answer.Equals("ChatGPT says: What is the meaning of life?"), "Wrong question Expected: ChatGPT says: What is the meaning of life?. Received: " + question4.Answer);

Assert.True(question1.Id == -1, "Wrong Id. Expected: -1. Received: " + question1.Id);
Assert.True(question2.Id == -2, "Wrong Id. Expected: -2. Received: " + question2.Id);
Expand Down Expand Up @@ -73,9 +80,16 @@ public async Task GetAllAsVolunteer()

//Verify all FAQs
Assert.True(question1.Question.Equals("Frequent Asked Question 1"), "Wrong question Expected: Frequent Asked Question 1. Received: " + question1.Question);
Assert.True(question1.Answer.Equals("Gooooddd answerrr!!!"), "Wrong question Expected: Gooooddd answerrr!!!. Received: " + question1.Answer);

Assert.True(question2.Question.Equals("Frequent Asked Question 2"), "Wrong question Expected: Frequent Asked Question 2. Received: " + question2.Question);
Assert.True(question2.Answer.Equals("Ye probably"), "Wrong question Expected: Ye probably. Received: " + question3.Answer);

Assert.True(question3.Question.Equals("Frequent Asked Question 3"), "Wrong question Expected: Frequent Asked Question 3. Received: " + question3.Question);
Assert.True(question3.Answer.Equals("Hehe nop"), "Wrong question Expected: Hehe nop. Received: " + question4.Answer);

Assert.True(question4.Question.Equals("Frequent Asked Question 4"), "Wrong question Expected: Frequent Asked Question 4. Received: " + question4.Question);
Assert.True(question4.Answer.Equals("ChatGPT says: What is the meaning of life?"), "Wrong question Expected: ChatGPT says: What is the meaning of life?. Received: " + question4.Answer);

Assert.True(question1.Id == -1, "Wrong Id. Expected: -1. Received: " + question1.Id);
Assert.True(question2.Id == -2, "Wrong Id. Expected: -2. Received: " + question2.Id);
Expand Down Expand Up @@ -143,6 +157,8 @@ public async Task GetAsVolunteer()

Assert.True(faq.Id == -1, "Wrong question id. Expected: -1. Received: " + faq.Id.ToString());
Assert.True(faq.Question.Equals("Frequent Asked Question 1"), "Wrong question. Expected: Frequent Asked Question 1 Received: " + faq.Question.ToString());
Assert.True(faq.Answer.Equals("Gooooddd answerrr!!!"), "Wrong question Expected: Gooooddd answerrr!!!. Received: " + faq.Answer);

}

[Fact]
Expand Down Expand Up @@ -191,7 +207,8 @@ public async Task PutAsAdmin()

var updateFAQDto = new UpdateFAQDTO
{
Question = "New Question"
Question = "New Question",
Answer = "New Answer"
};

var json = JsonConvert.SerializeObject(updateFAQDto);
Expand All @@ -203,10 +220,53 @@ public async Task PutAsAdmin()
var faq = JsonConvert.DeserializeObject<FrequentAskedQuestion>(await response.Content.ReadAsStringAsync());

Assert.True(faq.Question.Equals("New Question"), "Wrong Question Expected: New Question. Received: " + faq.Question.ToString());
Assert.True(faq.Answer.Equals("New Answer"), "Wrong Question Expected: New Answer. Received: " + faq.Answer.ToString());


updateFAQDto = new UpdateFAQDTO
{
Question = "Frequent Asked Question 1",
Answer = "Gooooddd answerrr!!!"
};

json = JsonConvert.SerializeObject(updateFAQDto);
payload = new StringContent(json, UnicodeEncoding.UTF8, "application/json");
response = await client.PutAsync("api/faq/-1", payload);

Assert.True(response.StatusCode.Equals(HttpStatusCode.OK),"Wrong status code. Expected: OK. Received: " + response.StatusCode.ToString());

faq = JsonConvert.DeserializeObject<FrequentAskedQuestion>(await response.Content.ReadAsStringAsync());

Assert.True(faq.Question.Equals("Frequent Asked Question 1"), "Wrong Question. Expected: Frequent Asked Question 1. Received: " + faq.Question.ToString());
Assert.True(faq.Answer.Equals("Gooooddd answerrr!!!"), "Wrong question Expected: Gooooddd answerrr!!!. Received: " + faq.Answer);
}

[Fact]
public async Task PutPartAsAdmin()
{
//Setup
var client = await TestUtils.Login("admin");

var updateFAQDto = new UpdateFAQDTO
{
Answer = "New Answer"
};

var json = JsonConvert.SerializeObject(updateFAQDto);
var payload = new StringContent(json.ToString(), Encoding.UTF8, "application/json");
var response = await client.PutAsync("api/faq/-1", payload);

Assert.True(response.StatusCode.Equals(HttpStatusCode.OK),"Wrong status code. Expected: OK. Received: " + response.StatusCode.ToString());

var faq = JsonConvert.DeserializeObject<FrequentAskedQuestion>(await response.Content.ReadAsStringAsync());

Assert.True(faq.Question.Equals("Frequent Asked Question 1"), "Wrong Question. Expected: Frequent Asked Question 1. Received: " + faq.Question.ToString());
Assert.True(faq.Answer.Equals("New Answer"), "Wrong Question Expected: New Answer. Received: " + faq.Answer.ToString());


updateFAQDto = new UpdateFAQDTO
{
Question = "Frequent Asked Question 1"
Answer = "Gooooddd answerrr!!!"
};

json = JsonConvert.SerializeObject(updateFAQDto);
Expand All @@ -218,6 +278,7 @@ public async Task PutAsAdmin()
faq = JsonConvert.DeserializeObject<FrequentAskedQuestion>(await response.Content.ReadAsStringAsync());

Assert.True(faq.Question.Equals("Frequent Asked Question 1"), "Wrong Question. Expected: Frequent Asked Question 1. Received: " + faq.Question.ToString());
Assert.True(faq.Answer.Equals("Gooooddd answerrr!!!"), "Wrong question Expected: Gooooddd answerrr!!!. Received: " + faq.Answer.ToString());
}

[Fact]
Expand All @@ -229,7 +290,8 @@ public async Task PutAsStudent()
//Create DTO
var updateFAQDto = new UpdateFAQDTO
{
Question = "New Question"
Question = "New Question",
Answer = "New Answer"
};

//Serialize DTO
Expand All @@ -251,7 +313,8 @@ public async Task PutLoggedIn()
//Create DTO
var updateFAQDto = new UpdateFAQDTO
{
Question = "New Question"
Question = "New Question",
Answer = "New Answer"
};

//Serialize DTO
Expand All @@ -272,7 +335,8 @@ public async Task PutNonExisting()
//Create DTO
var updateFAQDto = new UpdateFAQDTO
{
Question = "New Question"
Question = "New Question",
Answer = "New Answer"
};

//Serialize DTO
Expand All @@ -299,6 +363,7 @@ public async Task PostAndDeleteAsAdmin()
{
Id = -5,
Question = "Frequent Asked Question 5",
Answer = "Answer 5"
};

//Get nbr of FAQ
Expand All @@ -319,6 +384,7 @@ public async Task PostAndDeleteAsAdmin()

Assert.True(faq.Id == -5, "Wrong Id. Expected: -5. Received: " + faq.Id);
Assert.True(faq.Question.Equals("Frequent Asked Question 5"), "Wrong Question. Expected: Frequent Asked Question 5. Received: " + faq.Question);
Assert.True(faq.Answer.Equals("Answer 5"), "Wrong Answer. Expected: Answer 5. Received: " + faq.Answer);

//Check that the nbr of FAQ has increased
response = await client.GetAsync("/api/faq/");
Expand Down Expand Up @@ -377,6 +443,7 @@ public async Task PostAndDeleteNotLoggedIn()
{
Id = -5,
Question = "Frequent Asked Question 5",
Answer = "Answer 5"
};

//Serialize DTO
Expand All @@ -386,7 +453,7 @@ public async Task PostAndDeleteNotLoggedIn()
//Try to post FAQ
var response = await client.PostAsync("/api/faq/add", payload);
Assert.True(response.StatusCode.Equals(HttpStatusCode.Unauthorized), "Wrong Status Code. Expected: Unauthorized. Received: " + response.StatusCode.ToString());

//Try to delete FAQ
response = await client.DeleteAsync("/api/faq/-1");
Assert.True(response.StatusCode.Equals(HttpStatusCode.Unauthorized), "Wrong Status Code. Expected: Unauthorized. Received: " + response.StatusCode.ToString());
Expand Down Expand Up @@ -425,6 +492,7 @@ public async Task PostExistingId()
{
Id = -1,
Question = " ",
Answer = " "
};

//Get nbr of FAQ
Expand All @@ -445,7 +513,7 @@ public async Task PostExistingId()
allFAQ = JsonConvert.DeserializeObject<List<FrequentAskedQuestion>>(await response.Content.ReadAsStringAsync());

Assert.True(allFAQ.Count == numberOfFAQ, "Wrong number of faq. Expected: " + numberOfFAQ + ". Received: " + allFAQ.Count);

//Check that the FAQ with id -1 is unchanged
response = await client.GetAsync("/api/faq/-1");
Assert.True(response.StatusCode.Equals(HttpStatusCode.OK), "Wrong Status Code. Expected: OK. Received: " + response.StatusCode.ToString());
Expand All @@ -454,6 +522,9 @@ public async Task PostExistingId()

Assert.True(faq.Id == -1, "Wrong question id. Expected: -1. Received: " + faq.Id.ToString());
Assert.True(faq.Question.Equals("Frequent Asked Question 1"), "Wrong question. Expected: Frequent Asked Question 1 Received: " + faq.Question.ToString());
Assert.True(faq.Answer.Equals("Gooooddd answerrr!!!"), "Wrong question Expected: Gooooddd answerrr!!!. Received: " + faq.Answer);
}


}
}
Loading

0 comments on commit 83b8234

Please sign in to comment.