Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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);
        }