예제 #1
0
        public async Task GetAllJsonsAsync_Should_Work_Correctly(string username, Dictionary <JsonModel, GetJsonResponseDto> jsonModelsDictionary)
        {
            _jsonService.GetAllDataAsync(username).Returns(info => jsonModelsDictionary.Keys);
            _mapper.Map <GetJsonResponseDto>(Arg.Any <JsonModel>())
            .Returns(x => jsonModelsDictionary.FirstOrDefault(d => d.Key.Id.Equals(((JsonModel)x[0]).Id)).Value);


            var response = await CreateJsonController(username).GetAllJsonsAsync();

            var objectResult = response as OkObjectResult;

            Assert.NotNull(objectResult);
            var responseObject = objectResult.Value as IEnumerable <GetJsonResponseDto>;

            Assert.NotNull(responseObject);
            for (var i = 0; i < jsonModelsDictionary.Count; i++)
            {
                var jsonModel = jsonModelsDictionary.Values.ElementAt(i);
                var el        = responseObject.ElementAt(i);
                Assert.AreEqual(jsonModel.Json, el.Json);
            }
        }
예제 #2
0
 public async Task <IActionResult> GetAllJsonsAsync()
 {
     return(Ok((await _jsonService.GetAllDataAsync(User.GetUsername()))
               .Select(x => _mapper.Map <GetJsonResponseDto>(x))));
 }