Example #1
0
        public async Task <IList <ApiSummaryModel> > GetAllSummary(string ownerPublicKey)
        {
            var ownerKey = await _keyManager.GetByPublicKey(ownerPublicKey);

            var list = await _apiData.GetAll(ownerKey.Id);

            var result = new List <ApiSummaryModel>(list.Count);

            foreach (var a in list)
            {
                var api = new ApiSummaryModel(a)
                {
                    ActiveRoleCount   = await _roleData.CountByApi(a.OwnerKeyId, a.Id, false),
                    DisabledRoleCount = await _roleData.CountByApi(a.OwnerKeyId, a.Id, true)
                };

                result.Add(api);
            }

            return(result);
        }
Example #2
0
        public async Task ApiDataProcessorServiceGetReturnsSuccess()
        {
            // arrange
            var expectedResult = new ApiSummaryModel
            {
                Url         = new Uri("https://somewhere.com"),
                Title       = "a-name",
                Published   = DateTime.Now,
                CreatedDate = DateTime.Now,
            };
            var jsonResponse = JsonConvert.SerializeObject(expectedResult);

            A.CallTo(() => fakeApiService.GetAsync(A <HttpClient> .Ignored, A <Uri> .Ignored, A <string> .Ignored)).Returns(jsonResponse);

            var apiDataProcessorService = new ApiDataProcessorService(fakeApiService);

            // act
            var result = await apiDataProcessorService.GetAsync <ApiSummaryModel>(A.Fake <HttpClient>(), new Uri("https://somewhere.com")).ConfigureAwait(false);

            // assert
            A.CallTo(() => fakeApiService.GetAsync(A <HttpClient> .Ignored, A <Uri> .Ignored, A <string> .Ignored)).MustHaveHappenedOnceExactly();
            A.Equals(result, expectedResult);
        }