/// <summary>
 /// Initializes a new instance of the <see cref="DecklistService"/> class.
 /// </summary>
 /// <param name="db">The database.</param>
 /// <param name="banlistService">The banlist service.</param>
 /// <exception cref="ArgumentNullException">
 /// db
 /// or
 /// banlistService
 /// </exception>
 public DecklistService(
     YgoProAnalyticsDatabase db,
     IBanlistService banlistService)
 {
     _db             = db ?? throw new ArgumentNullException(nameof(db));
     _banlistService = banlistService ?? throw new ArgumentNullException(nameof(banlistService));
 }
Beispiel #2
0
        public async Task GetArchetypeOfDecklist_DeckHasDefaultArchetype_DeckGetsDefaultArchetype()
        {
            using (var dbInMemory = new YgoProAnalyticsDatabase(_getOptionsForSqlInMemoryTesting <YgoProAnalyticsDatabase>()))
            {
                dbInMemory.Database.EnsureCreated();
                var archetype = new Archetype(Archetype.Default, true);
                nekrozOfBrionac = _NekrozofBrionac(archetype);
                nekrozMirror    = _NekrozMirror(archetype);
                herald          = _Herald(archetype);
                bookstone       = _ImpcantationBookStone(archetype);
                dbInMemory.Cards.AddRange(nekrozOfBrionac, nekrozMirror, herald, bookstone);
                await dbInMemory.SaveChangesAsync();

                var decklist = new Decklist(new List <Card> {
                    nekrozOfBrionac, nekrozOfBrionac, nekrozOfBrionac, bookstone, bookstone, bookstone
                }, new List <Card> {
                    herald, herald
                }, new List <Card>());

                _analyzer = new ArchetypeAndDecklistAnalyzer(dbInMemory);
                _analyzer.GetArchetypeOfTheDecklistWithStatistics(decklist, DateTime.Now);

                Assert.AreEqual(Archetype.Default, decklist.Archetype.Name);
            }
        }
Beispiel #3
0
        public async Task SetUp()
        {
            _db = new YgoProAnalyticsDatabase(SqlInMemoryHelper.SqlLiteOptions <YgoProAnalyticsDatabase>());
            await _db.Database.EnsureCreatedAsync();

            _analyzer = new ServerActivityAnalyzer(_db);
        }
        public async Task DeckContainsBetaCard_OfficialIDAppears_ConvertCardToOfficial()
        {
            using (var dbInMemory = new YgoProAnalyticsDatabase(_getOptionsForSqlInMemoryTesting <YgoProAnalyticsDatabase>()))
            {
                dbInMemory.Database.EnsureCreated();
                _addPSYFrameDriver(dbInMemory);
                _addMokeyMokeyKing(dbInMemory);
                _addChecksumDragon(dbInMemory);
                _addPankratops(dbInMemory);
                var banlist = new Banlist("2019.10 TCG", 1);
                banlist.ForbiddenCards.Add(_checksumDragon);
                dbInMemory.Banlists.Add(banlist);
                await dbInMemory.SaveChangesAsync();

                var decklist = _converterMock.Object.Convert(GetProperYDKString());
                decklist.Name      = "Lunalight";
                decklist.Archetype = _defaultArchetype;
                dbInMemory.Decklists.Add(decklist);

                await dbInMemory.SaveChangesAsync();

                IBetaCardToOfficialConverter _converter = new BetaCardToOfficialConverter(dbInMemory, _adminConfigMock.Object, _downloaderMock.Object);
                await _converter.UpdateCardsFromBetaToOfficial();

                var decklistFromDb = dbInMemory.Decklists.First();

                Assert.Multiple(() =>
                {
                    //tests if a beta card (Cheksum dragon with betaid:100336006) is converted to 94136469
                    Assert.IsNotNull(decklistFromDb.MainDeck.FirstOrDefault(x => x.PassCode == 94136469));
                    Assert.IsNull(decklistFromDb.MainDeck.FirstOrDefault(x => x.PassCode == 100336006));
                });
            }
        }
Beispiel #5
0
        public async Task GetArchetypeOfDecklist_DeckHas1MainArchetype_DeckGets1Archetype()
        {
            using (var dbInMemory = new YgoProAnalyticsDatabase(_getOptionsForSqlInMemoryTesting <YgoProAnalyticsDatabase>()))
            {
                dbInMemory.Database.EnsureCreated();
                var archetypeNekroz = new Archetype("Nekroz", true);
                var archetypeHerald = new Archetype("Herald", true);
                nekrozOfBrionac = _NekrozofBrionac(archetypeNekroz);
                nekrozMirror    = _NekrozMirror(archetypeNekroz);
                herald          = _Herald(archetypeHerald);
                dbInMemory.Cards.AddRange(nekrozOfBrionac, nekrozMirror, herald);
                await dbInMemory.SaveChangesAsync();

                var decklist = new Decklist(new List <Card> {
                    nekrozOfBrionac, nekrozOfBrionac, nekrozOfBrionac, nekrozOfBrionac, nekrozOfBrionac, nekrozOfBrionac, nekrozOfBrionac, nekrozOfBrionac, nekrozOfBrionac, nekrozMirror
                }, new List <Card> {
                    herald, herald
                }, new List <Card> {
                    herald
                });

                _analyzer = new ArchetypeAndDecklistAnalyzer(dbInMemory);
                _analyzer.GetArchetypeOfTheDecklistWithStatistics(decklist, DateTime.Now);

                Assert.AreEqual("Nekroz", decklist.Archetype.Name);
            }
        }
        public async Task GetProperYDKString_ReturnDecklistWithFilledFieldsAsync()
        {
            using (var dbInMemory = new YgoProAnalyticsDatabase(_getOptionsForSqlInMemoryTesting <YgoProAnalyticsDatabase>()))
            {
                dbInMemory.Database.EnsureCreated();
                var archetype = new Archetype(Archetype.Default, true);
                _addPSYFrameDriver(dbInMemory, archetype);
                _addMokeyMokeyKing(dbInMemory, archetype);
                _addChecksumDragon(dbInMemory, archetype);
                _addPankratops(dbInMemory, archetype);
                await dbInMemory.SaveChangesAsync();

                _converter = new YDKToDecklistConverter(dbInMemory, _downloaderMock.Object, _adminConfigMock.Object);
                var decklist = _converter.Convert(GetProperYDKString());
                decklist.Name      = "Test";
                decklist.Archetype = new Archetype(Archetype.Default, true);
                dbInMemory.Decklists.Add(decklist);
                await dbInMemory.SaveChangesAsync();

                var decklistFromDb = dbInMemory.Decklists.First();

                Assert.Multiple(() =>
                {
                    //tests if a beta card (Cheksum dragon with betaid:100336006) is converted to 94136469
                    Assert.IsNotNull(decklistFromDb.MainDeck.FirstOrDefault(x => x.PassCode == 94136469));
                    Assert.AreEqual(decklistFromDb.MainDeck, decklist.MainDeck);
                    Assert.AreEqual(decklistFromDb.ExtraDeck, decklist.ExtraDeck);
                    Assert.AreEqual(decklistFromDb.SideDeck, decklist.SideDeck);
                });
            }
        }
        public async Task UpdateBanlists_SourcesShouldBeAvailable_DbInMemoryIsUpdated()
        {
            var connection = new SqliteConnection("DataSource=:memory:");

            connection.Open();
            var dbContextSqliteOptions =
                new DbContextOptionsBuilder <YgoProAnalyticsDatabase>()
                .UseSqlite(connection)
                .ConfigureWarnings(x => x.Ignore(RelationalEventId.QueryClientEvaluationWarning))
                .Options;

            using (var db = new YgoProAnalyticsDatabase(dbContextSqliteOptions))
            {
                db.Database.EnsureCreated();

                var _updater = new CardsDataToCardsAndArchetypesUpdater(new CardsDataDownloader(), new CardBuilder(), db);
                await _updater.UpdateCardsAndArchetypes("https://db.ygoprodeck.com/api/v3/cardinfo.php");


                var updater     = new BanlistDataToBanlistUpdater(db, new BanlistDataDownloader());
                var newBanlists = await updater.UpdateBanlists("https://raw.githubusercontent.com/szefo09/updateYGOPro2/master/lflist.conf");

                Assert.Greater(newBanlists.Count(), 0);
            }
        }
        public async Task UpdateBanlist_SourcesGiveUsValidData_DbContainValidNumberOfForbiddenAndLimitedAndSemiLimitedCards()
        {
            var connection = new SqliteConnection("DataSource=:memory:");

            connection.Open();
            var dbContextSqliteOptions =
                new DbContextOptionsBuilder <YgoProAnalyticsDatabase>()
                .UseSqlite(connection)
                .ConfigureWarnings(x => x.Ignore(RelationalEventId.QueryClientEvaluationWarning))
                .Options;

            using (var db = new YgoProAnalyticsDatabase(dbContextSqliteOptions))
            {
                db.Database.EnsureCreated();
                var archetype = new Archetype(Archetype.Default, true);
                _addChangeOfHeart(db, archetype);
                _addChickenGame(db, archetype);
                _addTerraforming(db, archetype);
                await db.SaveChangesAsync();

                var updater = new BanlistDataToBanlistUpdater(db, _banlistDataDownloaderMock.Object);
                await updater.UpdateBanlists("https://raw.githubusercontent.com/szefo09/updateYGOPro2/master/lflist.conf");

                await _verifyForTCGBanlist(db);
                await _verifyForOCGBanlist(db);
            }
        }
Beispiel #9
0
 public void SetUp()
 {
     _db = new YgoProAnalyticsDatabase(_getOptionsForSqlInMemoryTesting <YgoProAnalyticsDatabase>());
     _db.Database.EnsureCreated();
     _adminConfigMock  = new Mock <IAdminConfig>();
     _duelLogConverter = new Mock <IDuelLogConverter>();
     _analyzer         = new DuelLogNameAnalyzer(_db, _adminConfigMock.Object, _duelLogConverter.Object);
 }
 public void SetUp()
 {
     _db = new YgoProAnalyticsDatabase(SqlInMemoryHelper.SqlLiteOptions <YgoProAnalyticsDatabase>());
     _db.Database.EnsureCreated();
     _cacheMock      = new Mock <IMemoryCache>();
     _configMock     = new Mock <IAdminConfig>();
     _banlistService = new BanlistService(_db, _cacheMock.Object, _configMock.Object);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="CardsDataToCardsAndArchetypesUpdater"/> class.
 /// </summary>
 /// <param name="cardsDataDownloader">The cards data downloader.</param>
 /// <param name="cardBuilder">The card builder.</param>
 /// <param name="db">The database.</param>
 public CardsDataToCardsAndArchetypesUpdater(
     ICardsDataDownloader cardsDataDownloader,
     ICardBuilder cardBuilder,
     YgoProAnalyticsDatabase db)
 {
     _cardsDataDownloader = cardsDataDownloader;
     _cardBuilder         = cardBuilder;
     _db = db;
 }
Beispiel #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BanlistService"/> class.
 /// </summary>
 /// <param name="db">The database.</param>
 /// <param name="cache">The cache.</param>
 /// <param name="config">The configuration.</param>
 /// <exception cref="ArgumentNullException">
 /// db
 /// or
 /// cache
 /// or
 /// config
 /// </exception>
 public BanlistService(
     YgoProAnalyticsDatabase db,
     IMemoryCache cache,
     IAdminConfig config)
 {
     _db     = db ?? throw new ArgumentNullException(nameof(db));
     _cache  = cache ?? throw new ArgumentNullException(nameof(cache));
     _config = config ?? throw new ArgumentNullException(nameof(config));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="DuelLogNameAnalyzer"/> class.
 /// </summary>
 /// <param name="db">The database.</param>
 /// <param name="config">The configuration.</param>
 public DuelLogNameAnalyzer(
     YgoProAnalyticsDatabase db,
     IAdminConfig config,
     IDuelLogConverter converter)
 {
     _banlists  = db.Banlists.Include(x => x.Statistics).ToList();
     _config    = config;
     _converter = converter;
 }
Beispiel #14
0
        public void DatabaseExists_ReturnsTrue()
        {
            var optionsBuilder = new DbContextOptionsBuilder <YgoProAnalyticsDatabase>();

            optionsBuilder.UseSqlServer(YgoProAnalyticsDatabase.ConnectionString(_adminConfig.DBUser, _adminConfig.DBPassword));
            using (YgoProAnalyticsDatabase db = new YgoProAnalyticsDatabase(optionsBuilder.Options))
            {
                Assert.IsTrue((db.Database.GetService <IDatabaseCreator>() as RelationalDatabaseCreator).Exists());
            }
        }
        public async Task UpdateCardsAndArchetypes_SourceAreAvailable_CardsAndArchetypesTablesUpdated()
        {
            using (var db = new YgoProAnalyticsDatabase(_dbContextSqliteOptions))
            {
                db.Database.EnsureCreated();
                _updater = new CardsDataToCardsAndArchetypesUpdater(new CardsDataDownloader(), new CardBuilder(), db);
                await _updater.UpdateCardsAndArchetypes("https://db.ygoprodeck.com/api/v3/cardinfo.php");

                Assert.NotZero(db.Cards.Count());
            }
        }
Beispiel #16
0
 public void SetUp()
 {
     _db = new YgoProAnalyticsDatabase(SqlInMemoryHelper.SqlLiteOptions <YgoProAnalyticsDatabase>());
     _db.Database.EnsureCreated();
     _decklistToDtoConverter = new Mock <IDecklistToDecklistDtoConverter>();
     _decklistService        = new Mock <IDecklistService>();
     _adminConfigMock        = new Mock <IAdminConfig>();
     _mapperMock             = new Mock <IMapper>();
     _decklistBrowserQueryParamsValidator = new Mock <IDecklistBrowserQueryParametersDtoValidator>();
     _numberOfResultsHelper = new Mock <INumberOfResultsHelper>();
 }
        public async Task UpdateCardsAndArchetypes_WeGetCardsDataAsJSon_CardsAndArchetypesTablesUpdated()
        {
            using (var db = new YgoProAnalyticsDatabase(_dbContextSqliteOptions))
            {
                db.Database.EnsureCreated();

                _updater = new CardsDataToCardsAndArchetypesUpdater(_downloaderMock.Object, _cardBuilderMock.Object, db);
                await _updater.UpdateCardsAndArchetypes("https://db.ygoprodeck.com/api/v3/cardinfo.php");

                Assert.NotZero(db.Cards.Count(), "Cards table should not be empty.");
                Assert.NotZero(db.Archetypes.Count(), "Archetypes table should not be empty.");
            }
        }
Beispiel #18
0
        public void GetBanlist_DuelLogNameContainInfoAboutBanlistButBanlistIsNotKnown_WeGetUnnownBanlistException(
            string duelLogName,
            string duelLogDate)
        {
            using (var db = new YgoProAnalyticsDatabase(_getOptionsForSqlInMemoryTesting <YgoProAnalyticsDatabase>()))
            {
                db.Database.EnsureCreated();
                _analyzer = new DuelLogNameAnalyzer(db, _adminConfigMock.Object, _duelLogConverter.Object);

                Assert.Throws <UnknownBanlistException>(() => _analyzer.GetBanlist(
                                                            duelLogName,
                                                            _convertDuelLogTimeToDateTime(duelLogDate)));
            }
        }
        private static async Task _verifyForOCGBanlist(YgoProAnalyticsDatabase db)
        {
            var banlistOCG = await db
                             .Banlists
                             .Where(x => x.Name == "2019.01 OCG")
                             .Include(Banlist.IncludeWithForbiddenCards)
                             .Include(Banlist.IncludeWithLimitedCards)
                             .Include(Banlist.IncludeWithSemiLimitedCards)
                             .FirstAsync();

            Assert.AreEqual(0, banlistOCG.ForbiddenCardsJoin.Count());
            Assert.AreEqual(0, banlistOCG.LimitedCardsJoin.Count());
            Assert.AreEqual(0, banlistOCG.SemiLimitedCardsJoin.Count());
        }
 private static void _addMokeyMokeyKing(YgoProAnalyticsDatabase db, Archetype archetype)
 {
     db.Cards.Add(
         Card.Create(
             13803864,
             "Mokey Mokey King",
             "Description: Mokey Mokey King",
             "Fusion Monster Card",
             "normal",
             null,
             null,
             archetype
             )
         );
 }
 private static void _addPankratops(YgoProAnalyticsDatabase db, Archetype archetype)
 {
     db.Cards.Add(
         Card.Create(
             82385847,
             "Dinowrestler Pankratops",
             "Description: Dinowrestler Pankratops",
             "Effect Monster Card",
             "normal",
             null,
             null,
             archetype
             )
         );
 }
 private static void _addPSYFrameDriver(YgoProAnalyticsDatabase db, Archetype archetype)
 {
     db.Cards.Add(
         Card.Create(
             49036338,
             "PSY-Frame Driver",
             "Description: PSY-Frame Driver",
             "Monster Card",
             "normal",
             null,
             null,
             archetype
             )
         );
 }
 private static void _addChangeOfHeart(YgoProAnalyticsDatabase db, Archetype archetype)
 {
     db.Cards.Add(
         Card.Create(
             4031928,
             "Change of Heart",
             "Description: Change of Heart",
             "Spell Card",
             "normal",
             null,
             null,
             archetype
             )
         );
 }
 private static void _addChickenGame(YgoProAnalyticsDatabase db, Archetype archetype)
 {
     db.Cards.Add(
         Card.Create(
             67616300,
             "Chicken Game",
             "Chicken Game",
             "Spell Card",
             "normal",
             null,
             null,
             archetype
             )
         );
 }
 private static void _addTerraforming(YgoProAnalyticsDatabase db, Archetype archetype)
 {
     db.Cards.Add(
         Card.Create(
             73628505,
             "Terraforming",
             "Terraforming",
             "Spell Card",
             "normal",
             null,
             null,
             archetype
             )
         );
 }
 private static void _addChecksumDragon(YgoProAnalyticsDatabase db, Archetype archetype)
 {
     db.Cards.Add(
         Card.Create(
             94136469,
             "Checksum Dragon",
             "Description: Checksum Dragon",
             "Monster Card",
             "normal",
             null,
             null,
             archetype
             )
         );
 }
 public YgoProAnalysisBasedOnDataFromYgoProServer(
     IDuelLogNameAnalyzer duelLogNameAnalyzer,
     YgoProAnalyticsDatabase db,
     IArchetypeAndDecklistAnalyzer archetypeAndDecklistAnalyzer,
     IYDKToDecklistConverter yDKToDecklistConverter,
     IBanlistService banlistService,
     IDecklistService decklistService)
 {
     _duelLogNameAnalyzer = duelLogNameAnalyzer;
     _db = db;
     _archetypeAndDecklistAnalyzer = archetypeAndDecklistAnalyzer;
     _yDKToDecklistConverter       = yDKToDecklistConverter;
     _banlistService  = banlistService;
     _decklistService = decklistService;
 }
Beispiel #28
0
 public YgoProServerDataRetriever(
     IFTPDownloader fTPDownloader,
     IAdminConfig adminConfig,
     IFileUnzipper unzipper,
     IDuelLogConverter duelLogConverter,
     IMediator mediator,
     YgoProAnalyticsDatabase db)
 {
     _fTPDownloader    = fTPDownloader;
     _adminConfig      = adminConfig;
     _unzipper         = unzipper;
     _duelLogConverter = duelLogConverter;
     _mediator         = mediator;
     _db = db;
 }
Beispiel #29
0
 public DecklistController(
     YgoProAnalyticsDatabase db,
     IDecklistToDecklistDtoConverter decklistToDtoConverter,
     IDecklistService decklistService,
     IAdminConfig config,
     IMapper mapper,
     IDecklistBrowserQueryParametersDtoValidator decklistBrowserQueryParamsValidator,
     INumberOfResultsHelper numberOfResultsHelper)
 {
     _db = db ?? throw new ArgumentNullException(nameof(db));
     _decklistToDtoConverter = decklistToDtoConverter ?? throw new ArgumentNullException(nameof(decklistToDtoConverter));
     _decklistService        = decklistService ?? throw new ArgumentNullException(nameof(decklistService));
     _config = config ?? throw new ArgumentNullException(nameof(config));
     _mapper = mapper ?? throw new ArgumentNullException(nameof(mapper));
     _decklistBrowserQueryParamsValidator = decklistBrowserQueryParamsValidator
                                            ?? throw new ArgumentNullException(nameof(decklistBrowserQueryParamsValidator));
     _numberOfResultsHelper = numberOfResultsHelper ?? throw new ArgumentNullException(nameof(numberOfResultsHelper));
 }
Beispiel #30
0
        public async Task GetPureArchetypeListWithIdsAndNamesAsNoTrackingFromCache_WeHaveOnePureArchetypeInDb_WeGetOneValidDTO()
        {
            var cacheMock  = new Mock <IMemoryCache>();
            var configMock = new Mock <IAdminConfig>();

            using (var db = new YgoProAnalyticsDatabase(SqlInMemoryHelper.SqlLiteOptions <YgoProAnalyticsDatabase>()))
            {
                await db.Database.EnsureCreatedAsync();

                db.Archetypes.Add(new Archetype(Archetype.Default, true));
                await db.SaveChangesAsync();

                var archetypeService = new ArchetypeService(db, cacheMock.Object, configMock.Object);

                var resultDto = (await archetypeService.GetPureArchetypeListWithIdsAndNamesAsNoTrackingFromCache(true))
                                .First();

                Assert.IsTrue(resultDto.Name == Archetype.Default);
            }
        }