Example #1
0
        public async Task PlayerRepo()
        {
            var connection = new SqliteConnection("DataSource=:memory:");

            connection.Open();

            try
            {
                var options = new DbContextOptionsBuilder <CookingQuestContext>()
                              .UseSqlite(connection)
                              .Options;

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

                using (var context = new CookingQuestContext(options))
                {
                    context.Player.Add(new Player
                    {
                        Gold     = 10,
                        Name     = "Test",
                        PlayerId = 1,
                    });
                    context.SaveChanges();
                    context.Account.Add(new Account
                    {
                        AccountId = 1,
                        IsAdmin   = true,
                        Password  = "******",
                        PlayerId  = 1,
                        Username  = "******",
                    });
                    context.SaveChanges();
                    context.Equipment.Add(new Equipment
                    {
                        Difficulty  = 8,
                        EquipmentId = 1,
                        Modifier    = 5,
                        Name        = "TestE",
                        Price       = 45,
                        Type        = "Dungeon",
                    });
                    context.SaveChanges();
                    context.PlayerEquipment.Add(new PlayerEquipment
                    {
                        EquipmentId       = 1,
                        PlayerId          = 1,
                        PlayerEquipmentId = 1,
                    });
                    context.SaveChanges();
                    context.Location.Add(new Location
                    {
                        Description = "Testl",
                        Difficulty  = 1,
                        LocationId  = 1,
                        Name        = "TestNl",
                    });
                    context.SaveChanges();
                    context.Loot.Add(new Loot
                    {
                        Description = "a",
                        LootId      = 1,
                        Name        = "l",
                        Price       = 44,
                    });
                    context.SaveChanges();
                    context.PlayerLoot.Add(new PlayerLoot {
                        LootId       = 1,
                        PlayerId     = 1,
                        PlayerLootId = 1,
                    });
                    context.Flavor.Add(new Flavor
                    {
                        FlavorId    = 1,
                        Description = "v",
                        Name        = "ad"
                    });
                    context.SaveChanges();
                    context.FlavorLoot.Add(new FlavorLoot
                    {
                        FlavorId = 1,
                        LootId   = 1,
                    });
                    context.SaveChanges();
                    var testRepo = new PlayerRepo(context);
                    var players  = await testRepo.GetAllPlayers();

                    var player = await testRepo.GetPlayerById(1);

                    var playerEmail = await testRepo.GetPlayerByEmail("paul");

                    var playerEqp = await testRepo.GetPlayerEquipment(1);

                    var locationUnl = await testRepo.GetUnlockedLocations(1);

                    var loot = await testRepo.GetLoot(1);

                    var editP = await testRepo.EditPlayer(player);

                    var editPLoot = await testRepo.EditPlayerLoot(loot.ElementAt(0));

                    var editPEqp = await testRepo.EditPlayerEquipment(playerEqp.ElementAt(0));

                    var deletePQqp = await testRepo.DeletePlayerEquipment(playerEqp.ElementAt(0).PlayerEquipmentId);

                    var deletPLoot = await testRepo.DeletePlayerLoot(loot.ElementAt(0).PlayerLootId);

                    Assert.NotEmpty(players);
                    Assert.NotNull(player);
                    Assert.Equal("Test", player.Name);
                    Assert.NotNull(playerEmail);
                    Assert.Equal("Test", player.Name);
                    Assert.NotEmpty(playerEqp);
                    Assert.NotEmpty(locationUnl);
                    Assert.NotEmpty(loot);
                    Assert.True(editP);
                    Assert.True(editPLoot);
                    Assert.True(editPEqp);
                    Assert.True(deletePQqp);
                    Assert.True(deletPLoot);
                    testRepo.Dispose();
                }
            }
            finally
            {
                connection.Close();
            }
        }
Example #2
0
        public async Task PlayerRepoEquipment()
        {
            var connection = new SqliteConnection("DataSource=:memory:");

            connection.Open();

            try
            {
                var options = new DbContextOptionsBuilder <CookingQuestContext>()
                              .UseSqlite(connection)
                              .Options;

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

                using (var context = new CookingQuestContext(options))
                {
                    context.Player.Add(new Player
                    {
                        Gold     = 10,
                        Name     = "Test",
                        PlayerId = 1,
                    });
                    context.SaveChanges();

                    context.Equipment.Add(new Equipment
                    {
                        Difficulty  = 8,
                        EquipmentId = 1,
                        Modifier    = 5,
                        Name        = "TestE",
                        Price       = 45,
                        Type        = "Dungeon",
                    });
                    context.Equipment.Add(new Equipment
                    {
                        Difficulty  = 8,
                        EquipmentId = 2,
                        Modifier    = 5,
                        Name        = "TestE2",
                        Price       = 45,
                        Type        = "Cooking",
                    });
                    context.SaveChanges();
                    context.PlayerEquipment.Add(new PlayerEquipment
                    {
                        EquipmentId       = 1,
                        PlayerId          = 1,
                        PlayerEquipmentId = 1,
                    });
                    context.PlayerEquipment.Add(new PlayerEquipment
                    {
                        EquipmentId       = 2,
                        PlayerId          = 1,
                        PlayerEquipmentId = 2,
                    });
                    context.SaveChanges();

                    var testRepo = new PlayerRepo(context);

                    var playerEqp = await testRepo.GetPlayerEquipment(1);

                    var name = playerEqp.ElementAt(0).Name;

                    var equip = playerEqp.ElementAt(0);
                    equip.Name = "Change";

                    var editPEqp = await testRepo.EditPlayerEquipment(equip);

                    var deletePQqp = await testRepo.DeletePlayerEquipment(playerEqp.ElementAt(0).PlayerEquipmentId);

                    var count = await testRepo.GetPlayerEquipment(1);

                    Assert.True(playerEqp.Count() == 2);
                    Assert.True(count.Count() == 1);
                    Assert.Equal("TestE", name);
                    Assert.Equal("Change", equip.Name);
                    Assert.Equal("TestE2", (await testRepo.GetPlayerEquipment(1)).ElementAt(0).Name);
                    testRepo.Dispose();
                }
            }
            finally
            {
                connection.Close();
            }
        }