Example #1
0
        private async Task <CharacterCreationResponseCode> RequestCharacterCreation(string name)
        {
            CharacterNameValidationResponse nameValidationResponse = await CharacterService.ValidateName(name);

            CharacterCreationResponseCode responseCode = CharacterCreationResponseCode.Success;

            if (!nameValidationResponse.isSuccessful)
            {
                if (Logger.IsInfoEnabled)
                {
                    Logger.Info($"Failed to validate name. Reason: {nameValidationResponse.ResultCode}");
                }

                responseCode = CharacterCreationResponseCode.NameUnavailableError;
            }
            else
            {
                //If it's valid, we can create it.
                CharacterCreationResponse creationResponse = await CharacterService.CreateCharacter(name);

                if (!creationResponse.isSuccessful)
                {
                    if (Logger.IsInfoEnabled)
                    {
                        Logger.Info($"Failed to create character. Reason: {creationResponse.ResultCode}");
                    }
                }

                responseCode = creationResponse.ResultCode;
            }

            return(responseCode);
        }
Example #2
0
        public async Task Test_Validate_Character_Name_Works_On_Empty_Characters(string name)
        {
            //arrange
            IServiceProvider    serviceProvider = BuildServiceProvider <CharacterController>("Test", 1);
            CharacterController controller      = serviceProvider.GetService <CharacterController>();

            //act
            CharacterNameValidationResponse result = ControllerTestsHelpers.GetActionResultObject <CharacterNameValidationResponse>(await controller.ValidateCharacterName(name));

            //assert
            Assert.True(result.isSuccessful);
            Assert.True(result.ResultCode == CharacterNameValidationResponseCode.Success);
        }
Example #3
0
        public async Task Test_Validate_Character_Name_Passes_On_AlreadyExisting_Character_If_The_Names_Are_Different(string name)
        {
            //arrange
            IServiceProvider    serviceProvider = BuildServiceProvider <CharacterController>("Test", 1);
            CharacterController controller      = serviceProvider.GetService <CharacterController>();

            //act
            await serviceProvider.GetService <ICharacterRepository>().TryCreateAsync(new CharacterEntryModel(1, $"{name}Z"));

            CharacterNameValidationResponse result = ControllerTestsHelpers.GetActionResultObject <CharacterNameValidationResponse>(await controller.ValidateCharacterName(name));

            //assert
            Assert.True(result.isSuccessful);
            Assert.True(result.ResultCode == CharacterNameValidationResponseCode.Success);
        }
Example #4
0
        public async Task Test_Validate_Character_Name_Fails_On_AlreadyExisting_Character(string name)
        {
            //arrange
            IServiceProvider    serviceProvider = BuildServiceProvider <CharacterController>("Test", 1);
            CharacterController controller      = serviceProvider.GetService <CharacterController>();

            //act
            await serviceProvider.GetService <ICharacterRepository>().TryCreateAsync(new CharacterEntryModel(1, name));

            CharacterNameValidationResponse result = ControllerTestsHelpers.GetActionResultObject <CharacterNameValidationResponse>(await controller.ValidateCharacterName(name));

            //assert
            Assert.False(result.isSuccessful, $"Response for name validation should be false when the name is taken.");
            Assert.True(result.ResultCode == CharacterNameValidationResponseCode.NameIsUnavailable);
        }