Example #1
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));
        }
Example #2
0
        public void GetTestRun_ShouldRetrieveItFromTheServiceAndReturnAModel()
        {
            //Arrange
            var storedTestRun = new TestRun
            {
                Id = _random.NextPositive()
            };

            var convertedTestRunModel = new SavedTestRunModel();

            _testRunServiceMock.Setup(repo => repo.GetTestRunAsync(It.IsAny <int>())).ReturnsAsync(storedTestRun);
            _testResultConverterMock.Setup(converter => converter.ToTestRunModel(It.IsAny <TestRun>()))
            .Returns(convertedTestRunModel);

            //Act
            var okResult = _controller.GetTestRun(storedTestRun.Id).Result as OkObjectResult;

            //Assert
            Assert.That(okResult, Is.Not.Null);
            _testRunServiceMock.Verify(repo => repo.GetTestRunAsync(storedTestRun.Id), Times.Once);
            _testResultConverterMock.Verify(converter => converter.ToTestRunModel(storedTestRun), Times.Once);
            Assert.That(okResult.Value, Is.EqualTo(convertedTestRunModel));
        }
Example #3
0
        public SavedTestRunModel ToTestRunModel(TestRun testRun)
        {
            var model = new SavedTestRunModel
            {
                Id          = testRun.Id,
                ExerciseId  = testRun.AssignmentId,
                TestResults = new List <SavedTestResultModel>()
            };

            testRun.TestResults = testRun.TestResults ?? new List <TestResult>();

            foreach (var testResult in testRun.TestResults)
            {
                var testResultModel = new SavedTestResultModel
                {
                    Id     = testResult.Id,
                    Passed = testResult.Passed
                };
                model.TestResults.Add(testResultModel);
            }

            return(model);
        }