Example #1
0
        public async Task <IActionResult> OnPostAsync()
        {
            var task = await _context.Tasks.FindAsync(TaskId);

            if (SourceCodeFile == null || SourceCodeFile.Length == 0 || task.Contest.Status == Contest.ContestState.Completed)
            {
                return(RedirectToPage());
            }

            string sourceCode;

            using (var stream = SourceCodeFile.OpenReadStream())
                sourceCode = GetSourceCode(stream);

            var fileName  = Path.GetFileName(SourceCodeFile.FileName);
            var extension = Path.GetExtension(fileName).Substring(1);

            ProgrammingLanguage language;

            try
            {
                language = ProgrammingLanguageFactory.Get(extension);
            }
            catch
            {
                return(RedirectToPage());
            }

            var username = User.Identity.Name;
            var command  = CreateSolutionCommand.Create(sourceCode, language.LanguageCode, task.Id, username);
            await _createSolutionCommandHandler.HandleAsync(command);

            return(RedirectToPage());
        }
Example #2
0
        public void CreateSampleSolution_SolutionPresentInDatabase()
        {
            var givenSourceCode = "{...}";
            var givenTaskId     = SampleTask.Id;
            var givenLanguage   = "cpp";
            var givenUsername   = SampleUser.UserName;
            var command         = CreateSolutionCommand.Create(givenSourceCode, givenLanguage, givenTaskId, givenUsername);

            Sut.HandleAsync(command).Wait();
            var solutions = Context.Solutions
                            .Where(s => s.Task == SampleTask);

            solutions.Any(s => s.IdentityUser == SampleUser &&
                          s.SourceCode == givenSourceCode &&
                          s.Language == givenLanguage)
            .Should().BeTrue();
        }