Ejemplo n.º 1
0
        public async Task Should_Return_Ok_And_AllData()
        {
            //Arrange
            var cancellationToken = new CancellationToken();
            var platform          = "android";
            var rootDTO           = new RootDTO();
            var rootView          = new RootView();

            var logger      = new Mock <ILogger <GamesController> >();
            var mapper      = new Mock <IMapper>();
            var rootService = new Mock <IRootService>();

            rootService.Setup(s =>
                              s.GetRootAsync(platform, cancellationToken)).ReturnsAsync(rootDTO);
            mapper.Setup(m => m.Map <RootView>(rootDTO)).Returns(rootView);

            var controller =
                new GamesController(logger.Object, mapper.Object, rootService.Object)
            {
                Platform = platform
            };
            //Act
            var result = await controller.GetAllData(cancellationToken);

            //Assert
            rootService.Verify(s => s.GetRootAsync(platform, cancellationToken), Times.Once);
            mapper.Verify(m => m.Map <RootView>(rootDTO), Times.Once);
            var view = Assert.IsType <OkObjectResult>(result.Result);

            Assert.Equal(rootView, view.Value);
        }