public ModuleSessionDataServiceTests() { this.moduleSessionsRepository = new InMemoryRepository <ModuleSession, int>(); this.userAnswersRepository = new InMemoryRepository <UserAnswer, int>(); this.modulesRepository = new InMemoryRepository <Module, int>(); this.moduleSessionDataService = new ModuleSessionDataService( this.moduleSessionsRepository, this.userAnswersRepository, this.modulesRepository); var simpleModule = new Module { Id = 1 }; var fakeUser = new User { Id = "NEWXUSER" }; var simpleModuleSession = new ModuleSession { Id = 1, Module = simpleModule, User = fakeUser }; this.modulesRepository.Add(simpleModule); this.moduleSessionsRepository.Add(simpleModuleSession); }
public void FinishSession_ShouldFinishSessionIfValidIdIsGiven() { var testSession = new ModuleSession { Id = 3 }; this.moduleSessionsRepository.Add(testSession); this.moduleSessionDataService.FinishSession(3); Assert.True(testSession.IsFinised); // TODO: Mock DateTime.Now Assert.NotNull(testSession.FinishDate); }
public void NextQuestion_ShouldReturnNullIfModuleForSessionHasNoUnansweredQuestions() { var correctAnswer = new Answer { Id = 3, IsCorrect = true, QuestionId = 3 }; var simpleModule = new Module { Id = 3, Questions = new List <Question> { new Question { Id = 3, Answers = new List <Answer> { correctAnswer } } } }; var fakeUser = new User { Id = "NEWXUSER" }; var simpleModuleSession = new ModuleSession { Id = 3, Module = simpleModule, User = fakeUser }; var userAnswer = new UserAnswer("NEWXUSER", 3, 3) { Answer = correctAnswer }; this.userAnswersRepository.Add(userAnswer); this.moduleSessionsRepository.Add(simpleModuleSession); var result = this.moduleSessionDataService.NextQuestion(3, "NEWXUSER"); Assert.Null(result); Assert.True(simpleModuleSession.IsFinised); }
public async Task <ModuleSession> StartAnonymousSession(int moduleId) { var moduleExists = this.modulesRepository.All().Any(x => x.Id == moduleId); if (!moduleExists) { throw new InvalidOperationException("No such module exists"); } var newSession = new ModuleSession(moduleId) { StartedDate = DateTime.Now }; this.moduleSessionsRepository.Add(newSession); await this.moduleSessionsRepository.SaveChangesAsync(); return(newSession); }
internal string GetHtmlOutput(Contract.Page page, object instance, ModuleSession moduleSession) { if (this.theme == null) { this.Theme = "Default"; } if (this.template == null) { this.Template = "Default.html"; } string tmpTemplate = this.template; foreach (string Key in variables.Keys) { tmpTemplate = tmpTemplate.Replace("<!--{@" + Key + "}-->", variables[Key].ToString()).Replace("{@" + Key + "}", variables[Key].ToString()); } return(ThemeManager.Session.ParseTemplate(tmpTemplate, page, instance, moduleSession)); }
public void NextQuestion_ShouldReturnNextQuestionForSessionIfThereExistsANonANswerdQuestion() { var correctAnswer = new Answer { Id = 3, IsCorrect = true, QuestionId = 3 }; var simpleModule = new Module { Id = 3, Questions = new List <Question> { new Question { Id = 3, Answers = new List <Answer> { correctAnswer } } } }; var fakeUser = new User { Id = "NEWXUSER" }; var simpleModuleSession = new ModuleSession { Id = 3, Module = simpleModule, User = fakeUser }; this.moduleSessionsRepository.Add(simpleModuleSession); var result = this.moduleSessionDataService.NextQuestion(3, "NEWXUSER"); Assert.NotNull(result); Assert.Equal(result.Id, 3); }
public async Task <ModuleSession> StartUserSession(string userId, int moduleId) { if (userId.IsNullOrWhiteSpace()) { throw new ArgumentNullException(nameof(userId), "UserId must have a value"); } var moduleExists = this.modulesRepository.All().Any(x => x.Id == moduleId); if (!moduleExists) { throw new InvalidOperationException("No such module exists"); } var newSession = new ModuleSession(userId, moduleId) { StartedDate = DateTime.Now }; this.moduleSessionsRepository.Add(newSession); await this.moduleSessionsRepository.SaveChangesAsync(); return(newSession); }
public bool CompileClasses(out CompilerErrorCollection compilerErrorCollection, bool copyCompiledCode, params string[] definitions) { if (this.CompilerLanguage == "Html") { compilerErrorCollection = new CompilerErrorCollection(); return(true); } this.assembly = null; Debug.StartTimer("Page:" + this.ID + ":Compile()"); List <string> classCode = new List <string>(); foreach (PageClass pageClass in LatestReversion.Classes) { classCode.Add(pageClass.Data); } if (this.CompilerLanguage == null || this.CompilerLanguage == string.Empty) { this.CompilerLanguage = "CSharp"; } dynamic languageHandler = null; try { languageHandler = ModuleSession.Get(HttpContext.Current).GetLanguageHandler(this.CompilerLanguage); } catch (Exception e) { Debug.WriteLine("Could not fetch language handler for {0}, Exception: {1}", this.ID, e); compilerErrorCollection = new CompilerErrorCollection(); return(false); } if (languageHandler != null) { if (copyCompiledCode) { this.CompiledCode = languageHandler.CompileClasses(classCode.ToArray(), this.References.ToArray(), out compilerErrorCollection); } else { languageHandler.CompileClasses(classCode.ToArray(), this.References.ToArray(), out compilerErrorCollection); } return(true); } else { string[] references = this.References.ToArray(); for (int i = 0; i < references.Length; i++) { if (references[i].ToLower().EndsWith(".bmf")) { string moduleID = references[i].Substring(0, references[i].Length - 4); File.WriteAllBytes(HttpContext.Current.Server.MapPath("./Data/Temp/") + moduleID + ".bmf.dll", ModuleManager.Session.GetModuleByID(moduleID).CompiledCode); references[i] += ".dll"; } } CodeDomProvider codeDomProvider = CodeDomProvider.CreateProvider(this.CompilerLanguage); CompilerParameters codeParameters = new CompilerParameters(); codeParameters.IncludeDebugInformation = true; codeParameters.CompilerOptions = string.Format("{0}/lib:{1},{2},{3} /define:{4}", this.CompilerLanguage != "JScript" ? "/debug:pdbonly " : "", HttpContext.Current.Server.MapPath("./bin/"), HttpContext.Current.Server.MapPath("./bin/Libraries/"), HttpContext.Current.Server.MapPath("./Data/Temp/"), definitions.Length > 0 ? "WEBCORE;WEBCORE_2014;" + string.Join(";", definitions) : "WEBCORE;WEBCORE_2014"); codeParameters.GenerateInMemory = false; codeParameters.WarningLevel = 4; codeParameters.ReferencedAssemblies.AddRange(References.ToArray()); CompilerErrorCollection tmpCompilerErrorCollection = new CompilerErrorCollection(); CompilerResults compilerResults = codeDomProvider.CompileAssemblyFromSource(codeParameters, classCode.ToArray()); compilerErrorCollection = compilerResults.Errors; Debug.StopTimer("Page:" + this.ID + ":Compile()"); if (tmpCompilerErrorCollection.Count > 0) { compilerErrorCollection.AddRange(tmpCompilerErrorCollection); } if (compilerErrorCollection.HasErrors) { return(false); } FileInfo AssemblyFileInfo = new FileInfo(compilerResults.PathToAssembly); if (copyCompiledCode) { this.CompiledCode = File.ReadAllBytes(AssemblyFileInfo.FullName); if (File.Exists(AssemblyFileInfo.FullName.Replace(".dll", ".pdb"))) { this.CompiledCodeSymbols = File.ReadAllBytes(AssemblyFileInfo.FullName.Replace(".dll", ".pdb")); } } return(true); } }
public string GetTemplateAndParse(string templateKey, dynamic page) { string templateData = GetTemplate(templateKey); templateData = ThemeManager.Session.ParseTemplate(templateData, page.CorePage, page, ModuleSession.Get(HttpContext.Current)); return(templateData); }
public Enricher(ModuleSession moduleSession, ILogger <Enricher> logger) { this.moduleSession = moduleSession; this.logger = logger; }