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_Can_Create_Character(string name)
        {
            //arrange
            IServiceProvider serviceProvider = BuildServiceProvider <CharacterController>("Test", 1);
            Mock <IPlayfabCharacterClient>        playfabCharacterClientMock = CreatePlayFabCharacterClientMock();
            Mock <ICharacterAppearanceRepository> appearanceRepository       = new Mock <ICharacterAppearanceRepository>();
            Mock <ICharacterDataRepository>       dataRepository             = new Mock <ICharacterDataRepository>();
            CharacterController controller = serviceProvider.GetService <CharacterController>();

            //act
            CharacterCreationResponse result = ControllerTestsHelpers.GetActionResultObject <CharacterCreationResponse>(await controller.CreateCharacter(name, playfabCharacterClientMock.Object, appearanceRepository.Object, dataRepository.Object));

            //assert
            Assert.True(result.isSuccessful);
            Assert.True(result.ResultCode == CharacterCreationResponseCode.Success);
        }
Example #3
0
        public async Task Test_Cannot_Create_Character_With_Duplicate_Name(string name)
        {
            //arrange
            IServiceProvider                      serviceProvider            = BuildServiceProvider <CharacterController>("Test", 1);
            CharacterController                   controller                 = serviceProvider.GetService <CharacterController>();
            Mock <IPlayfabCharacterClient>        playfabCharacterClientMock = CreatePlayFabCharacterClientMock();
            Mock <ICharacterAppearanceRepository> appearanceRepository       = new Mock <ICharacterAppearanceRepository>();
            Mock <ICharacterDataRepository>       dataRepository             = new Mock <ICharacterDataRepository>();

            //act
            await controller.CreateCharacter(name, playfabCharacterClientMock.Object, appearanceRepository.Object, dataRepository.Object);

            CharacterCreationResponse result = ControllerTestsHelpers.GetActionResultObject <CharacterCreationResponse>(await controller.CreateCharacter(name, playfabCharacterClientMock.Object, appearanceRepository.Object, dataRepository.Object));

            //assert
            Assert.False(result.isSuccessful);
            Assert.AreEqual(CharacterCreationResponseCode.NameUnavailableError, result.ResultCode);
        }