Esempio n. 1
0
        public void PostProjectTestRun_ShouldReturnBadRequestIfPostedModelIsInvalid()
        {
            //Arrange
            var errorKey     = Guid.NewGuid().ToString();
            var errorMessage = Guid.NewGuid().ToString();

            _controller.ModelState.AddModelError(errorKey, errorMessage);

            var projectComponentDto = new ProjectComponentDtoBuilder().Build();
            var postedModel         = new CreateProjectTestRunModelBuilder().WithProjectComponent(projectComponentDto).Build();

            //Act
            var badRequestResult = _controller.PostProjectTestRun(postedModel).Result as BadRequestObjectResult;

            //Assert
            Assert.That(badRequestResult, Is.Not.Null);
            Assert.That(badRequestResult.Value, Has.One.Matches((KeyValuePair <string, object> kv) => kv.Key == errorKey));
            _testResultConverterMock.Verify(converter => converter.From(It.IsAny <IEnumerable <TestResultModel> >(), It.IsAny <string>(), It.IsAny <int>(), It.IsAny <Exercise>()), Times.Never);
            _testRunServiceMock.Verify(repo => repo.RegisterRunAsync(It.IsAny <TestRun>()), Times.Never);
        }
Esempio n. 2
0
        public void PostProjectTestRun_ShouldSaveItInTheRepository()
        {
            //Arrange
            var component = new ProjectComponent
            {
                Id   = _random.NextPositive(),
                Code = _random.NextPositive().ToString()
            };

            _assignmentServiceMock.Setup(service => service.GetOrCreateProjectComponentAsync(It.IsAny <ProjectComponentDto>()))
            .ReturnsAsync(component);

            var projectComponentDto = new ProjectComponentDtoBuilder().WithComponentCode(component.Code).Build();
            var postedModel         = new CreateProjectTestRunModelBuilder()
                                      .WithProjectComponent(projectComponentDto)
                                      .WithSourceCode()
                                      .Build();

            TestPostAssignmentTestRun(() => _controller.PostProjectTestRun(postedModel), postedModel, component);

            _assignmentServiceMock.Verify(service => service.GetOrCreateProjectComponentAsync(postedModel.ProjectComponent), Times.Once);
        }