-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
40 changed files
with
1,271 additions
and
52 deletions.
There are no files selected for viewing
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,111 @@ | ||
using EduCATS.Constants; | ||
using EduCATS.Demo; | ||
using System.Reflection; | ||
using NUnit.Framework; | ||
using Nyxbull.Plugins.CrossLocalization; | ||
using EduCATS.Fonts; | ||
using System.Net; | ||
using System; | ||
|
||
namespace EduCATS.UnitTests | ||
{ | ||
[TestFixture] | ||
public class AppDemoTests | ||
{ | ||
const string _demoString = "demo"; | ||
const string _demoWithUpperCasedLetterString = "Demo"; | ||
const string _invalidDemoString = "invalid_demo"; | ||
|
||
[Test] | ||
public void CheckDemoAccountTest() | ||
{ | ||
var validCredentialsResult = AppDemo.Instance.CheckDemoAccount(_demoString, _demoString); | ||
Assert.IsTrue(validCredentialsResult); | ||
var invalidUsernameResult = AppDemo.Instance.CheckDemoAccount(_invalidDemoString, _demoString); | ||
Assert.IsFalse(invalidUsernameResult); | ||
var invalidPasswordResult = AppDemo.Instance.CheckDemoAccount(_demoString, _invalidDemoString); | ||
Assert.IsFalse(invalidPasswordResult); | ||
var upperCasedUsernameResult = AppDemo.Instance.CheckDemoAccount(_demoWithUpperCasedLetterString, _demoString); | ||
Assert.IsTrue(upperCasedUsernameResult); | ||
var upperCasedPasswordResult = AppDemo.Instance.CheckDemoAccount(_demoString, _demoWithUpperCasedLetterString); | ||
Assert.IsFalse(upperCasedPasswordResult); | ||
var invalidCredentialsResult = AppDemo.Instance.CheckDemoAccount(_invalidDemoString, _invalidDemoString); | ||
Assert.IsFalse(invalidCredentialsResult); | ||
var invalidUsernameCredentialsResult = AppDemo.Instance.CheckDemoAccount(_invalidDemoString, _demoString); | ||
Assert.IsFalse(invalidUsernameCredentialsResult); | ||
var invalidPasswordCredentialsResult = AppDemo.Instance.CheckDemoAccount(_demoString, _invalidDemoString); | ||
Assert.IsFalse(invalidPasswordCredentialsResult); | ||
var nullCredentialsResult = AppDemo.Instance.CheckDemoAccount(null, null); | ||
Assert.IsFalse(nullCredentialsResult); | ||
var emptyCredentialsResult = AppDemo.Instance.CheckDemoAccount("", ""); | ||
Assert.IsFalse(emptyCredentialsResult); | ||
} | ||
|
||
[Test] | ||
public void IsDemoAccountTest() | ||
{ | ||
AppDemo.Instance.IsDemoAccount = true; | ||
Assert.IsTrue(AppDemo.Instance.IsDemoAccount); | ||
AppDemo.Instance.IsDemoAccount = false; | ||
Assert.IsFalse(AppDemo.Instance.IsDemoAccount); | ||
} | ||
|
||
[Test] | ||
public void GetInvalidResponseTest() | ||
{ | ||
var response = AppDemo.Instance.GetInvalidResponse(); | ||
Assert.IsEmpty(response.Key); | ||
Assert.AreEqual(response.Value, HttpStatusCode.BadRequest); | ||
} | ||
|
||
[Test] | ||
public void GetDemoResponseTest() | ||
{ | ||
var availableTestsResponse = AppDemo.Instance.GetDemoResponse(AppDemoType.AvailableTests); | ||
Assert.AreEqual(availableTestsResponse.Value, HttpStatusCode.OK); | ||
var conceptTreeResponse = AppDemo.Instance.GetDemoResponse(AppDemoType.ConceptTree); | ||
Assert.AreEqual(conceptTreeResponse.Value, HttpStatusCode.OK); | ||
var filesResponse = AppDemo.Instance.GetDemoResponse(AppDemoType.Files); | ||
Assert.AreEqual(filesResponse.Value, HttpStatusCode.OK); | ||
var infoLecturersResponse = AppDemo.Instance.GetDemoResponse(AppDemoType.InfoLecturers); | ||
Assert.AreEqual(infoLecturersResponse.Value, HttpStatusCode.OK); | ||
var labsResponse = AppDemo.Instance.GetDemoResponse(AppDemoType.Labs); | ||
Assert.AreEqual(labsResponse.Value, HttpStatusCode.OK); | ||
var labsResultsResponse = AppDemo.Instance.GetDemoResponse(AppDemoType.LabsResults); | ||
Assert.AreEqual(labsResultsResponse.Value, HttpStatusCode.OK); | ||
var loginResponse = AppDemo.Instance.GetDemoResponse(AppDemoType.Login); | ||
Assert.AreEqual(loginResponse.Value, HttpStatusCode.OK); | ||
var newsResponse = AppDemo.Instance.GetDemoResponse(AppDemoType.News); | ||
Assert.AreEqual(newsResponse.Value, HttpStatusCode.OK); | ||
var ptsResponse = AppDemo.Instance.GetDemoResponse(AppDemoType.PracticalTestStatistics); | ||
Assert.AreEqual(ptsResponse.Value, HttpStatusCode.OK); | ||
var profileInfoResponse = AppDemo.Instance.GetDemoResponse(AppDemoType.ProfileInfo); | ||
Assert.AreEqual(profileInfoResponse.Value, HttpStatusCode.OK); | ||
var profileInfoSubjectsResponse = AppDemo.Instance.GetDemoResponse(AppDemoType.ProfileInfoSubjects); | ||
Assert.AreEqual(profileInfoSubjectsResponse.Value, HttpStatusCode.OK); | ||
var recommendationsResponse = AppDemo.Instance.GetDemoResponse(AppDemoType.Recommendations); | ||
Assert.AreEqual(recommendationsResponse.Value, HttpStatusCode.OK); | ||
var rootConceptsResponse = AppDemo.Instance.GetDemoResponse(AppDemoType.RootConcepts); | ||
Assert.AreEqual(rootConceptsResponse.Value, HttpStatusCode.OK); | ||
var statisticsResponse = AppDemo.Instance.GetDemoResponse(AppDemoType.Statistics); | ||
Assert.AreEqual(statisticsResponse.Value, HttpStatusCode.OK); | ||
var testResponse = AppDemo.Instance.GetDemoResponse(AppDemoType.Test); | ||
Assert.AreEqual(testResponse.Value, HttpStatusCode.OK); | ||
var testAnswerAndGetNextResponse = AppDemo.Instance.GetDemoResponse(AppDemoType.TestAnswerAndGetNext); | ||
Assert.AreEqual(testAnswerAndGetNextResponse.Value, HttpStatusCode.OK); | ||
var testNextQuestionResponse = AppDemo.Instance.GetDemoResponse(AppDemoType.TestNextQuestion); | ||
Assert.AreEqual(testNextQuestionResponse.Value, HttpStatusCode.OK); | ||
var testUserAnswersResponse = AppDemo.Instance.GetDemoResponse(AppDemoType.TestUserAnswers); | ||
Assert.AreEqual(testUserAnswersResponse.Value, HttpStatusCode.OK); | ||
var noneResponse = AppDemo.Instance.GetDemoResponse(AppDemoType.None); | ||
Assert.AreEqual(noneResponse.Value, HttpStatusCode.BadRequest); | ||
var profileInfoCalendarResponse = AppDemo.Instance.GetDemoResponse(AppDemoType.ProfileInfoCalendar); | ||
var todayDate = DateTime.Today; | ||
var todayDateString = todayDate.ToString("yyyy-MM-dd"); | ||
var tomorrowDateString = todayDate.AddDays(1).ToString("yyyy-MM-dd"); | ||
Assert.AreEqual(profileInfoCalendarResponse.Value, HttpStatusCode.OK); | ||
StringAssert.Contains(todayDateString, profileInfoCalendarResponse.Key); | ||
StringAssert.Contains(tomorrowDateString, profileInfoCalendarResponse.Key); | ||
} | ||
} | ||
} |
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,107 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Net; | ||
using System.Text; | ||
using EduCATS.Helpers.Files; | ||
|
||
namespace EduCATS.Demo | ||
{ | ||
/// <summary> | ||
/// Helper class for handling demo account state. | ||
/// </summary> | ||
public class AppDemo | ||
{ | ||
/// <summary> | ||
/// Shared instance of <c>AppDemo</c>. | ||
/// </summary> | ||
public static AppDemo Instance; | ||
|
||
const string demoUsername = "demo"; | ||
const string demoPassword = "demo"; | ||
|
||
static AppDemo() | ||
{ | ||
Instance = new AppDemo(); | ||
} | ||
|
||
bool _isDemoAccount; | ||
|
||
/// <summary> | ||
/// Property for checking whether is account demo or not. | ||
/// </summary> | ||
public bool IsDemoAccount { | ||
get { | ||
return _isDemoAccount; | ||
} | ||
set { | ||
_isDemoAccount = value; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Check if account is demo or not. | ||
/// </summary> | ||
/// <param name="username">Username.</param> | ||
/// <param name="password">Password.</param> | ||
/// <returns>Demo account or not.</returns> | ||
public bool CheckDemoAccount(string username, string password) | ||
{ | ||
if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password)) { | ||
return false; | ||
} | ||
|
||
var isDemoAccount = username.ToLower().Equals(demoUsername.ToLower()) && password.Equals(demoPassword); | ||
IsDemoAccount = isDemoAccount; | ||
return isDemoAccount; | ||
} | ||
|
||
/// <summary> | ||
/// Get demo response string and status code. | ||
/// </summary> | ||
/// <param name="type">Demo resource type to retrieve.</param> | ||
/// <returns>Demo response string and status code.</returns> | ||
public KeyValuePair<string, HttpStatusCode> GetDemoResponse(AppDemoType type) | ||
{ | ||
if (type == AppDemoType.None) { | ||
return GetInvalidResponse(); | ||
} | ||
|
||
var resource = $"demo{type.ToString()}"; | ||
var extension = "json"; | ||
|
||
switch (type) { | ||
case AppDemoType.TestAnswerAndGetNext: | ||
extension = "txt"; | ||
break; | ||
default: | ||
extension = "json"; | ||
break; | ||
} | ||
|
||
var manager = new FileManager(); | ||
var contents = manager.ReadDemoEmbeddedResource(resource, extension); | ||
|
||
if (type == AppDemoType.ProfileInfoCalendar) { | ||
var today = DateTime.Today; | ||
var format = "yyyy-MM-dd"; | ||
var todayString = today.ToString(format); | ||
var tomorrowString = today.AddDays(1).ToString(format); | ||
var builder = new StringBuilder(contents); | ||
builder.Replace("$dateToday", todayString); | ||
builder.Replace("$dateTomorrow", tomorrowString); | ||
contents = builder.ToString(); | ||
} | ||
|
||
return new KeyValuePair<string, HttpStatusCode>(contents, HttpStatusCode.OK); | ||
} | ||
|
||
/// <summary> | ||
/// Generate invalid response with <c>BadRequest</c> status code. | ||
/// </summary> | ||
/// <returns>Invalid response with empty string and <c>BadRequest</c> status code.</returns> | ||
public KeyValuePair<string, HttpStatusCode> GetInvalidResponse() | ||
{ | ||
return new KeyValuePair<string, HttpStatusCode>("", HttpStatusCode.BadRequest); | ||
} | ||
} | ||
} |
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,28 @@ | ||
using System; | ||
|
||
namespace EduCATS.Demo | ||
{ | ||
public enum AppDemoType | ||
{ | ||
None, | ||
AvailableTests, | ||
ConceptTree, | ||
Files, | ||
InfoLecturers, | ||
Labs, | ||
LabsResults, | ||
Login, | ||
News, | ||
PracticalTestStatistics, | ||
ProfileInfo, | ||
ProfileInfoCalendar, | ||
ProfileInfoSubjects, | ||
Recommendations, | ||
RootConcepts, | ||
Statistics, | ||
Test, | ||
TestAnswerAndGetNext, | ||
TestNextQuestion, | ||
TestUserAnswers | ||
} | ||
} |
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,14 @@ | ||
[ | ||
{ | ||
"Id": 1, | ||
"Title": "Демонстрационный тест #1", | ||
"Description": "Демонстрационное описание", | ||
"ForSelfStudy": true | ||
}, | ||
{ | ||
"Id": 2, | ||
"Title": "Демонстрационный тест #2", | ||
"Description": null, | ||
"ForSelfStudy": true | ||
} | ||
] |
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,82 @@ | ||
{ | ||
"Container": null, | ||
"FilePath": null, | ||
"HasData": false, | ||
"Id": 1, | ||
"IsGroup": true, | ||
"Name": "Демонстрационный ЭУМК", | ||
"Next": null, | ||
"ParentId": 0, | ||
"Prev": null, | ||
"Published": true, | ||
"ReadOnly": false, | ||
"ShortName": "Демо ЭУМК", | ||
"SubjectName": "Предмет #1", | ||
"children": [ | ||
{ | ||
"Container": "Container", | ||
"FilePath": "\/UploadedFiles\/Id\/Id.pdf", | ||
"HasData": true, | ||
"Id": 2, | ||
"IsGroup": false, | ||
"Name": "Документ #1", | ||
"Next": 3, | ||
"ParentId": 1, | ||
"Prev": null, | ||
"Published": true, | ||
"ReadOnly": true, | ||
"ShortName": "Документ #1", | ||
"SubjectName": "Предмет #1", | ||
"children": [] | ||
}, | ||
{ | ||
"Container": "Container", | ||
"FilePath": "\/UploadedFiles\/Id\/Id.pdf", | ||
"HasData": true, | ||
"Id": 3, | ||
"IsGroup": false, | ||
"Name": "Документ #2", | ||
"Next": 4, | ||
"ParentId": 1, | ||
"Prev": 2, | ||
"Published": true, | ||
"ReadOnly": true, | ||
"ShortName": "Документ #2", | ||
"SubjectName": "Предмет #1", | ||
"children": [] | ||
}, | ||
{ | ||
"Container": null, | ||
"FilePath": null, | ||
"HasData": false, | ||
"Id": 4, | ||
"IsGroup": true, | ||
"Name": "Демонстрационный раздел", | ||
"Next": null, | ||
"ParentId": 1, | ||
"Prev": 3, | ||
"Published": false, | ||
"ReadOnly": true, | ||
"ShortName": "Демонстрационный раздел", | ||
"SubjectName": "Предмет #1", | ||
"children": [ | ||
{ | ||
"Container": "Container", | ||
"FilePath": "\/UploadedFiles\/Id\/Id.pdf", | ||
"HasData": true, | ||
"Id": 5, | ||
"IsGroup": false, | ||
"Name": "Документ #3", | ||
"Next": null, | ||
"ParentId": 4, | ||
"Prev": null, | ||
"Published": true, | ||
"ReadOnly": true, | ||
"ShortName": "Документ #3", | ||
"SubjectName": "Предмет #1", | ||
"children": [] | ||
} | ||
] | ||
} | ||
] | ||
} |
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,22 @@ | ||
{ | ||
"Lectures": [ | ||
{ | ||
"Name": "Демонстрационный файл #1", | ||
"FileName": "Демонстрационный файл #1.docx", | ||
"PathName": "Path", | ||
"AttachmentType": 2, | ||
"Id": 1, | ||
"IsNew": false | ||
}, | ||
{ | ||
"Name": "Демонстрационный файл #2", | ||
"FileName": "Демонстрационный файл #2.pdf", | ||
"PathName": "Path", | ||
"AttachmentType": 2, | ||
"Id": 1, | ||
"IsNew": false | ||
} | ||
], | ||
"Labs": [], | ||
"Practicals": [] | ||
} |
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 @@ | ||
{ } |
Oops, something went wrong.