Beispiel #1
0
        private async Task <SavedTestRunModel> SaveTestRunForAssignment(CreateTestRunModelBase model, Assignment assignment)
        {
            var testNames = model.Results.Select(testResult => testResult.TestName);

            if (IsLector())
            {
                await _assignmentService.LoadOrCreateTestsForAssignmentAsync(assignment, testNames);
            }
            else
            {
                await _assignmentService.LoadTestsForAssignmentAsync(assignment);
            }

            var testRun      = _testRunConverter.From(model.Results, model.SourceCode, GetUserId(), assignment);
            var savedTestRun = await _testRunService.RegisterRunAsync(testRun);

            var savedModel = _testRunConverter.ToTestRunModel(savedTestRun);

            return(savedModel);
        }
Beispiel #2
0
        private void TestPostAssignmentTestRun(Func <Task <IActionResult> > actFunction,
                                               CreateTestRunModelBase postedModel, Assignment existingAssignment)
        {
            var convertedTestRun = new TestRun();

            _testResultConverterMock
            .Setup(converter => converter.From(It.IsAny <IEnumerable <TestResultModel> >(), It.IsAny <string>(),
                                               It.IsAny <int>(), It.IsAny <Assignment>()))
            .Returns(convertedTestRun);

            var savedTestRun = new TestRun();

            _testRunServiceMock.Setup(repo => repo.RegisterRunAsync(It.IsAny <TestRun>())).ReturnsAsync(savedTestRun);

            var savedTestRunModel = new SavedTestRunModel
            {
                Id = _random.NextPositive()
            };

            _testResultConverterMock.Setup(converter => converter.ToTestRunModel(It.IsAny <TestRun>()))
            .Returns(savedTestRunModel);

            //Act
            var createdResult = actFunction.Invoke().Result as CreatedAtActionResult;

            //Assert
            Assert.That(createdResult, Is.Not.Null);
            _testResultConverterMock.Verify(
                converter => converter.From(postedModel.Results, postedModel.SourceCode, _userId, existingAssignment), Times.Once);

            _assignmentServiceMock.Verify(
                service => service.LoadOrCreateTestsForAssignmentAsync(existingAssignment,
                                                                       It.Is <IEnumerable <string> >(testNames => testNames.All(testName =>
                                                                                                                                postedModel.Results.Any(testResult => testResult.TestName == testName)))), Times.Once);
            _testRunServiceMock.Verify(repo => repo.RegisterRunAsync(convertedTestRun), Times.Once);
            _testResultConverterMock.Verify(converter => converter.ToTestRunModel(savedTestRun), Times.Once);
            Assert.That(createdResult.ActionName, Is.EqualTo(nameof(_controller.GetTestRun)));
            Assert.That(createdResult.RouteValues["id"], Is.EqualTo(savedTestRunModel.Id));
            Assert.That(createdResult.Value, Is.EqualTo(savedTestRunModel));
        }