Exemplo n.º 1
0
        public async Task GetMessages_success()
        {
            //Act
            var fakeUserId    = Guid.NewGuid();
            var fakePageIndex = 0;
            var fakePageSize  = 10;
            var fakeCount     = 1;

            var fakeMessageApiModel = new PaginatedItemsApiModel <MessageApiModel>(fakePageIndex, fakePageSize, fakeCount, new List <MessageApiModel>());

            _messagingServiceMock.Setup(w => w.GetMessages(It.IsAny <Guid>(), It.IsAny <int>(), It.IsAny <int>()))
            .Returns(Task.FromResult(fakeMessageApiModel));

            //Arrenge
            var controller   = CreateDefaultController();
            var actionResult = await controller.GetMessages(fakeUserId) as OkObjectResult;

            //Assert
            Assert.Equal(actionResult.StatusCode, (int)System.Net.HttpStatusCode.OK);
            Assert.Equal((actionResult.Value as PaginatedItemsApiModel <MessageApiModel>), fakeMessageApiModel);
        }
        public async Task GetMessages_returns_same_data()
        {
            //Act
            var fakeUserId         = Guid.NewGuid();
            var fakePageIndex      = 0;
            var fakePageSize       = 10;
            var fakeTotalItems     = 1;
            var fakeMessageApiList = new List <MessageApiModel>();

            var fakeMessageApiModel = new PaginatedItemsApiModel <MessageApiModel>(fakePageIndex, fakePageSize, fakeTotalItems, fakeMessageApiList);

            _repositoryMock.Setup(w => w.ListAsync(It.IsAny <ISpecification <Message> >(), It.IsAny <CancellationToken>())).Returns(Task.FromResult(default(List <Message>)));
            _repositoryMock.Setup(w => w.CountAsync(It.IsAny <ISpecification <Message> >(), It.IsAny <CancellationToken>())).Returns(Task.FromResult(fakeTotalItems));

            //Arrenge
            var service = CreateService();
            var result  = await service.GetMessages(fakeUserId, fakePageIndex, fakePageSize);

            //Assert
            Assert.Equal(result.Data, fakeMessageApiModel.Data);
        }
Exemplo n.º 3
0
        public async Task <PaginatedItemsApiModel <GetMyMessagesApiModel> > GetMessages(Guid userId, int pageIndex, int pageSize)
        {
            var uri = UrlsConfig.Messaging.GetMessages(_remoteServiceBaseUrl, userId, pageSize, pageIndex);

            var innerResponse = await _httpClient.GetAsync(uri);

            await innerResponse.EnsureSuccessStatusCodeCustom();

            var responseString = await innerResponse.Content.ReadAsStringAsync();

            //changed to newtonsoft
            var internalResponse = JsonConvert.DeserializeObject <PaginatedItemsApiModel <MessageInternalApiModel> >(responseString);

            var response = new PaginatedItemsApiModel <GetMyMessagesApiModel>(internalResponse.PageIndex,
                                                                              internalResponse.PageSize, internalResponse.Count, new List <GetMyMessagesApiModel>());

            foreach (var item in internalResponse.Data)
            {
                response.Data.Add(new GetMyMessagesApiModel(item));
            }

            return(response);
        }