public async Task IsSubmissionValid()
        {
            //arrange
            var createSubmissionViewModel = new CreateSubmissionViewModel()
            {
                FirstName    = "Thomas",
                SurName      = "Petersen",
                Email        = "*****@*****.**",
                Age          = 26,
                SerialNumber = 232145
            };
            var serialNumber = new SerialNumber()
            {
                Id        = Guid.NewGuid().ToString(),
                SerialKey = 232145,
                TimesUsed = 0
            };
            var submission = new Submission()
            {
                FirstName    = "Thomas",
                SurName      = "Petersen",
                Email        = "*****@*****.**",
                Age          = 26,
                SerialNumber = 232145
            };

            mockRepo.Setup(x => x.ValidSubmissionSerialNumber(createSubmissionViewModel.SerialNumber))
            .ReturnsAsync(serialNumber);
            mockMapper.Setup(x => x.Map <Submission>(createSubmissionViewModel)).Returns(submission);
            //act
            await sut.CreateSubmission(createSubmissionViewModel);

            //assert
            Assert.Equal(1, serialNumber.TimesUsed);
        }
        public HttpResponseMessage CreateSubmission(SubmissionCreateRequest submission)
        {
            ItemResponse <int> response = new ItemResponse <int>();

            response.Item = SubmissionService.CreateSubmission(submission);
            return(Request.CreateResponse(HttpStatusCode.OK, response));
        }
Example #3
0
        public HttpResponse Create(string problemId, string code)
        {
            if (!IsUserSignedIn())
            {
                return(Redirect("/Users/Login"));
            }

            var submission = new SubmissionCreateInputModel
            {
                Code = code
            };

            var validation = ValidationHelper.IsValid(submission);

            if (!validation.result)
            {
                return(Error(validation.errorMessage));
            }

            _submissionService.CreateSubmission(GetUserId(), problemId, submission);

            return(Redirect("/"));
        }