示例#1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            // Reset database and inject poe data
            using (var context = new PoeAppDbContext())
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();
            }

            var retriever = new Retriever();

            retriever.InitializeBaseItemTable();


            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints => { endpoints.MapControllers(); });
        }
示例#2
0
        public void AddBaseItemOneHandWeaponTest()
        {
            var connection = new SqliteConnection("Datasource=:memory:");

            connection.Open();

            var options = new DbContextOptionsBuilder <PoeAppDbContext>()
                          .UseSqlite(connection)
                          .Options;

            try
            {
                using (var context = new PoeAppDbContext(options))
                {
                    context.Database.EnsureCreated();
                }

                using (var context = new PoeAppDbContext(options))
                {
                    var baseItem = new BaseItem
                    {
                        Domain          = "item",
                        Key             = "Metadata/Items/Weapons/OneHandWeapons/OneHandSwords/OneHandSword1",
                        DropLevel       = 1,
                        InventoryHeight = 3,
                        InventoryWidth  = 1,
                        Name            = "Rusted Sword",
                        ReleaseState    = "released"
                    };

                    context.BaseItems.Add(baseItem);
                    context.SaveChanges();
                }

                using (var context = new PoeAppDbContext(options))
                {
                    Assert.AreEqual(1, context.BaseItems.Count());
                }
            }
            finally
            {
                connection.Close();
            }
        }
示例#3
0
        public void InitializeBaseItemTable(DbContextOptions options)
        {
            using var context = new PoeAppDbContext(options);
            using var client  = new WebClient();

            // todo: dont leave hardcoded url here
            const string address =
                "https://raw.githubusercontent.com/brather1ng/RePoE/master/RePoE/data/base_items.json";
            var jsonData = client.DownloadString(address);

            var deserializeObject = JsonConvert.DeserializeObject <JObject>(jsonData);

            foreach (var child in deserializeObject.Properties())
            {
                InsertBaseItem(context, child);
            }

            context.SaveChanges();
        }
示例#4
0
        public void BaseItemWithTagsNotEmptyOrNullTest()
        {
            var connection = new SqliteConnection("Datasource=:memory:");

            connection.Open();

            var options = new DbContextOptionsBuilder <PoeAppDbContext>()
                          .UseSqlite(connection)
                          .Options;

            try
            {
                using (var context = new PoeAppDbContext(options))
                {
                    context.Database.EnsureCreated();
                }

                var retriever = new Retriever();

                retriever.InitializeBaseItemTable(options);

                using (var context = new PoeAppDbContext(options))
                {
                    var data = context
                               .BaseItems
                               .Include(item => item.PoeTagsLink);

                    foreach (var baseItem in data)
                    {
                        Assert.IsNotNull(baseItem.PoeTagsLink);
                        Assert.IsNotEmpty(baseItem.PoeTagsLink);

                        Assert.IsNotNull(baseItem.PoeTagsLink.First());

                        Assert.IsTrue(baseItem.PoeTagsLink.First().ItemKey != "");
                    }
                }
            }
            finally
            {
                connection.Close();
            }
        }
示例#5
0
        public void AddWeaponWithTags()
        {
            var connection = new SqliteConnection("Datasource=:memory:");

            connection.Open();

            var options = new DbContextOptionsBuilder <PoeAppDbContext>()
                          .UseSqlite(connection)
                          .Options;

            try
            {
                using (var context = new PoeAppDbContext(options))
                {
                    context.Database.EnsureCreated();
                }

                using (var context = new PoeAppDbContext(options))
                {
                    var baseItem = new BaseItem
                    {
                        Domain          = "item",
                        Key             = "Metadata/Items/Weapons/OneHandWeapons/OneHandSwords/OneHandSword1",
                        DropLevel       = 1,
                        InventoryHeight = 3,
                        InventoryWidth  = 1,
                        Name            = "Rusted Sword",
                        ReleaseState    = "released"
                    };

                    var tag1 = new PoeTag
                    {
                        Tag = "sword"
                    };
                    var tag2 = new PoeTag
                    {
                        Tag = "one_hand_weapon"
                    };
                    var tag3 = new PoeTag
                    {
                        // ReSharper disable once StringLiteralTypo
                        Tag = "onehand"
                    };
                    var tag4 = new PoeTag
                    {
                        Tag = "weapon"
                    };
                    var tag5 = new PoeTag
                    {
                        Tag = "default"
                    };

                    baseItem.PoeTagsLink = new List <ItemTag>
                    {
                        new ItemTag
                        {
                            Item = baseItem,
                            Tag  = tag1
                        },
                        new ItemTag
                        {
                            Item = baseItem,
                            Tag  = tag2
                        },
                        new ItemTag
                        {
                            Item = baseItem,
                            Tag  = tag3
                        },
                        new ItemTag
                        {
                            Item = baseItem,
                            Tag  = tag4
                        },
                        new ItemTag
                        {
                            Item = baseItem,
                            Tag  = tag5
                        }
                    };


                    context.BaseItems.Add(baseItem);
                    context.SaveChanges();
                }

                using (var context = new PoeAppDbContext(options))
                {
                    Assert.AreEqual(1, context.BaseItems.Count());
                    Assert.AreEqual(5, context.PoeTags.Count());
                    Assert.AreEqual(5, context.ItemTags.Count());


                    var data = context.BaseItems.Include(sword => sword.PoeTagsLink);

                    Assert.AreEqual(5, data.Single().PoeTagsLink.Count);
                }
            }
            finally
            {
                connection.Close();
            }
        }
示例#6
0
        private void InsertBaseItem(PoeAppDbContext context, JProperty data)
        {
            var baseItem = CreateWithBasicData <BaseItem>(data);

            context.BaseItems.Add(baseItem);
        }
示例#7
0
 public IEnumerable <PoeTag> GetTags()
 {
     using var context = new PoeAppDbContext();
     return(context.PoeTags.ToList());
 }
示例#8
0
 public IEnumerable <BaseItem> GetAllOneHandedSwords()
 {
     using var context = new PoeAppDbContext();
     return(context.BaseItems.ToList());
 }