Esempio n. 1
0
        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));
            }
        }
        /// <inheritdoc />
        public async Task <string> RetrieveAsync(int id)
        {
            NameQueryResponse queryResponse = await CharacterService.NameQuery(id)
                                              .ConfigureAwait(false);

            if (!queryResponse.isSuccessful)
            {
                throw new KeyNotFoundException($"Failed to retrieve Key: {id} from {nameof(INameQueryService)}. Error: {queryResponse.ResultCode}");
            }

            return(queryResponse.EntityName);
        }
Esempio n. 3
0
        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));
        }