Beispiel #1
0
        public async Task Setup()
        {
            context = await TestDatabase.GetDatabaseContext();

            mockDifficultiesService = new MockDifficultiesService(context);
            mockAppsService         = new MockAppsService(context);

            baseRequest = new BaseRequest();

            updateDifficultyRequest = new UpdateDifficultyRequest()
            {
                Id          = 1,
                Name        = "Test Difficulty",
                License     = TestObjects.GetLicense(),
                RequestorId = 1,
                Paginator   = new Paginator()
            };

            createDifficultyRequest = new CreateDifficultyRequest()
            {
                Name            = "Test Difficulty",
                DifficultyLevel = DifficultyLevel.TEST,
                License         = TestObjects.GetLicense(),
                RequestorId     = 1,
                Paginator       = new Paginator()
            };

            sutSuccess = new DifficultiesController(
                mockDifficultiesService.DifficultiesServiceSuccessfulRequest.Object,
                mockAppsService.AppsServiceSuccessfulRequest.Object);

            sutFailure = new DifficultiesController(
                mockDifficultiesService.DifficultiesServiceFailedRequest.Object,
                mockAppsService.AppsServiceSuccessfulRequest.Object);
        }
Beispiel #2
0
        public async Task <IActionResult> UpdateDifficulty(int id,
                                                           [FromBody] UpdateDifficultyRequest request)
        {
            if (await appsService.IsRequestValidOnThisLicense(
                    request.AppId,
                    request.License,
                    request.RequestorId))
            {
                if (id != request.Id)
                {
                    return(BadRequest(ControllerMessages.IdIncorrectMessage));
                }

                var result = await difficultiesService.UpdateDifficulty(id, request);

                if (result.Success)
                {
                    result.Message = ControllerMessages.StatusCode200(result.Message);

                    return(Ok(result));
                }
                else
                {
                    result.Message = ControllerMessages.StatusCode404(result.Message);

                    return(NotFound(result));
                }
            }
            else
            {
                return(BadRequest(ControllerMessages.InvalidLicenseRequestMessage));
            }
        }
        public async Task UpdateADifficulty()
        {
            // Arrange
            var updateDifficultyRequest = new UpdateDifficultyRequest()
            {
                Id          = 1,
                Name        = "Null UPDATED!",
                License     = license,
                RequestorId = 1,
                Paginator   = new Paginator()
            };

            // Act
            var result = await sut.UpdateDifficulty(1, updateDifficultyRequest);

            var updatedDifficulty = context.Difficulties
                                    .FirstOrDefault(difficulty => difficulty.Id == 1);

            // Assert
            Assert.That(result.Success, Is.True);
            Assert.That(result.Message, Is.EqualTo("Difficulty Updated"));
            Assert.That(updatedDifficulty.Name, Is.EqualTo("Null"));
        }