示例#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);
        }
示例#2
0
        public async Task <RootDTO> GetRootAsync(string platformType, CancellationToken cancellationToken)
        {
            var games = (await _gameRepository.GetAllAsync(cancellationToken))
                        .Where(game => game.PlatformTypes.Contains(platformType));
            var providers = (await _providerRepository.GetAllAsync(cancellationToken))
                            .Where(provider => provider.PlatformTypes.Contains(platformType));
            var categories = (await _categoryRepository.GetAllAsync(cancellationToken))
                             .Where(category => category.PlatformTypes.Contains(platformType));
            var tags = await _tagRepository.GetAllAsync(cancellationToken);

            var root = new RootDTO
            {
                Games      = _mapper.Map <List <GameDTO> >(games),
                Categories = _mapper.Map <List <CategoryDTO> >(categories),
                Providers  = _mapper.Map <List <ProviderDTO> >(providers),
                Tags       = _mapper.Map <List <TagDTO> >(tags)
            };

            return(root);
        }
示例#3
0
 public void Save()
 {
     try
     {
         lock (lockObject)
         {
             DataAccess.CreateIfNotExists();
             foreach (var item in RootObject.Results)
             {
                 RootDTO tmp = new RootDTO();
                 tmp.Name      = item?.Name?.First + item?.Name?.Last;
                 tmp.Direccion = item?.Location?.Street;
                 tmp.Imagen    = item?.Picture?.Medium.ToString();
                 DataAccess.SaveRootDTO(tmp);
                 tmp = null;
             }
         }
         UpdateRootDTOList();
     }
     catch (Exception ex)
     {
         //TODO: LOG
     }
 }
        public static string SaveRootDTO(RootDTO rootDTO)
        {
            string result = string.Empty;

            using (var db = new SQLite.SQLiteConnection(DBPath))
            {
                try
                {
                    var existingCustomer = (db.Table <RootDTO>().Where(
                                                c => c.Name == rootDTO.Name)).SingleOrDefault();

                    if (existingCustomer != null)
                    {
                        existingCustomer.Name      = rootDTO.Name;
                        existingCustomer.Direccion = rootDTO.Direccion;
                        existingCustomer.Imagen    = rootDTO.Imagen;
                        int success = db.Update(existingCustomer);
                    }
                    else
                    {
                        int success = db.Insert(new RootDTO()
                        {
                            Name      = rootDTO.Name,
                            Direccion = rootDTO.Direccion,
                            Imagen    = rootDTO.Imagen
                        });
                    }
                    result = "Guardado con Exito";
                }
                catch (Exception ex)
                {
                    result = $"Fallo el guardado. Exception: {ex} ";
                }
            }
            return(result);
        }