public async Task Test_Can_Get_Name_From_Character_Id([Range(1, 20)] int count) { //arrange IServiceProvider serviceProvider = BuildServiceProvider <CharacterController>("Test", 1); CharacterController controller = serviceProvider.GetService <CharacterController>(); List <string> names = await AddTestValuesToRepository(count, serviceProvider, 2); List <string> resultQueryNames = new List <string>(count); //assert for (int i = 1; i < count + 1; i++) { NameQueryResponse nameQueryResponse = ControllerTestsHelpers.GetActionResultObject <NameQueryResponse>(await controller.NameQuery(i)); Assert.True(nameQueryResponse.isSuccessful); Assert.NotNull(nameQueryResponse.EntityName); resultQueryNames.Add(nameQueryResponse.EntityName); } //Check that each inserted name is available in the total query results foreach (string s in names) { Assert.True(resultQueryNames.Contains(s)); } }
public async Task Test_Can_Create_Character(string name) { //arrange IServiceProvider serviceProvider = BuildServiceProvider <CharacterController>("Test", 1); CharacterController controller = serviceProvider.GetService <CharacterController>(); //act CharacterCreationResponse result = ControllerTestsHelpers.GetActionResultObject <CharacterCreationResponse>(await controller.CreateCharacter(name)); //assert Assert.True(result.isSuccessful); Assert.True(result.ResultCode == CharacterCreationResponseCode.Success); }
public async Task Test_Cannot_Create_Character_With_Duplicate_Name(string name) { //arrange IServiceProvider serviceProvider = BuildServiceProvider <CharacterController>("Test", 1); CharacterController controller = serviceProvider.GetService <CharacterController>(); //act await controller.CreateCharacter(name); CharacterCreationResponse result = ControllerTestsHelpers.GetActionResultObject <CharacterCreationResponse>(await controller.CreateCharacter(name)); //assert Assert.False(result.isSuccessful); Assert.AreEqual(CharacterCreationResponseCode.NameUnavailableError, result.ResultCode); }
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); }
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); }
public async Task Test_Can_Not_NameQuery_Unknown_Ids(int keyToCheck) { //arrange IServiceProvider serviceProvider = BuildServiceProvider <CharacterController>("Test", 1); CharacterController controller = serviceProvider.GetService <CharacterController>(); List <string> names = await AddTestValuesToRepository(20, serviceProvider, 2); //act NameQueryResponse result = ControllerTestsHelpers.GetActionResultObject <NameQueryResponse>(await controller.NameQuery(keyToCheck)); //assert Assert.False(result.isSuccessful); Assert.True(result.ResultCode == NameQueryResponseCode.UnknownIdError); Assert.True(String.IsNullOrWhiteSpace(result.EntityName)); }