public void Save_SavesCreateKillStat() { //arrange using var contextFactory = new Project2ContextFactory(); using Project2Context arrangeActContext = contextFactory.CreateContext(); Player insertedPlayer = CreatePlayer(null); LootTable insertedLootTable = CreateLootTable(); arrangeActContext.Players.Add(insertedPlayer); arrangeActContext.LootTables.Add(insertedLootTable); arrangeActContext.SaveChanges(); Mob insertedMob = CreateMob(insertedLootTable.Id); arrangeActContext.Mobs.Add(insertedMob); arrangeActContext.SaveChanges(); var repo = new PlayerRepository(arrangeActContext); repo.UpdateKillStat(insertedPlayer.Id, insertedMob.Id); //act repo.Save(); //assert using var assertContext = contextFactory.CreateContext(); KillStat killStat = assertContext.KillStats.Single(k => k.PlayerId == insertedPlayer.Id && k.MobId == insertedMob.Id); Assert.InRange(killStat.Id, 1, 10000); Assert.Equal(insertedPlayer.Id, killStat.PlayerId); Assert.Equal(insertedMob.Id, killStat.MobId); Assert.Equal(1, killStat.Quantity); }
public void UpdateKillStat_CreatesNewKillStat() { //arrange using var contextFactory = new Project2ContextFactory(); using Project2Context context = contextFactory.CreateContext(); Player insertedPlayer = CreatePlayer(null); LootTable insertedLootTable = CreateLootTable(); context.Players.Add(insertedPlayer); context.LootTables.Add(insertedLootTable); context.SaveChanges(); Mob insertedMob = CreateMob(insertedLootTable.Id); context.Mobs.Add(insertedMob); context.SaveChanges(); var repo = new PlayerRepository(context); //act repo.UpdateKillStat(insertedPlayer.Id, insertedMob.Id); //assert KillStat killStat = context.KillStats.Local.Single(k => k.PlayerId == insertedPlayer.Id && k.MobId == insertedMob.Id); Assert.Equal(insertedPlayer.Id, killStat.PlayerId); Assert.Equal(insertedMob.Id, killStat.MobId); Assert.Equal(1, killStat.Quantity); }
public void GetCharacterStats_GetsExistingCharacterStats() { //arrange using var contextFactory = new Project2ContextFactory(); using Project2Context context = contextFactory.CreateContext(); Character insertedCharacter = CreateCharacter(); context.Characters.Add(insertedCharacter); context.SaveChanges(); Player insertedPlayer = CreatePlayer(insertedCharacter.Id); context.Players.Add(insertedPlayer); context.SaveChanges(); var repo = new PlayerRepository(context); //act Business.Model.Character character = repo.GetCharacterStats(insertedPlayer.Id); //assert Assert.Equal(insertedCharacter.Id, character.Id); Assert.Equal(insertedCharacter.CharacterName, character.CharacterName); Assert.Equal(insertedCharacter.Exp, character.Exp); Assert.Equal(insertedCharacter.Health, character.Health); Assert.Equal(insertedCharacter.Attack, character.Attack); Assert.Equal(insertedCharacter.Mana, character.Mana); }
public void GetLoot_GetsRandomPossibleLoot() { // arrange using var contextFactory = new Project2ContextFactory(); using Project2Context context = contextFactory.CreateContext(); var insertedLootTable = CreateLootTable(); context.LootTables.Add(insertedLootTable); var insertedWeapon1 = CreateWeapon("AK-47"); var insertedWeapon2 = CreateWeapon("Katana"); context.Weapons.Add(insertedWeapon1); context.Weapons.Add(insertedWeapon2); context.SaveChanges(); var insertedMob = CreateMob(insertedLootTable.Id); context.Mobs.Add(insertedMob); var insertedLootLine1 = CreateLootLine(insertedLootTable.Id, insertedWeapon1.Id); var insertedLootLine2 = CreateLootLine(insertedLootTable.Id, insertedWeapon2.Id); context.SaveChanges(); context.Lootlines.Add(insertedLootLine1); context.Lootlines.Add(insertedLootLine2); context.SaveChanges(); var repo = new MobRepository(context); // act Business.Model.Weapon weapon = repo.GetLoot(insertedMob.Id - 1); // assert Assert.IsType <Business.Model.Weapon>(weapon); }
public void GetAllMobs_GetsAllMobs() { // arrange using var contextFactory = new Project2ContextFactory(); using Project2Context context = contextFactory.CreateContext(); var insertedLootTable1 = CreateLootTable(); var insertedLootTable2 = CreateLootTable(); context.LootTables.Add(insertedLootTable1); context.LootTables.Add(insertedLootTable2); context.SaveChanges(); var insertedMob1 = CreateMob(insertedLootTable1.Id); var insertedMob2 = CreateMob(insertedLootTable2.Id); context.Mobs.Add(insertedMob1); context.SaveChanges(); context.Mobs.Add(insertedMob2); context.SaveChanges(); var repo = new MobRepository(context); // act List <Business.Model.Mob> mob = repo.GetAllMobs().ToList(); // assert Assert.Equal(insertedMob1.Id, mob[0].Id); Assert.Equal(insertedMob1.Name, mob[0].Name); Assert.Equal(insertedMob1.LootTableId, mob[0].LootTableId); Assert.Equal(insertedMob1.Health, mob[0].Health); Assert.Equal(insertedMob1.Exp, mob[0].Exp); Assert.Equal(insertedMob1.Attack, mob[0].Attack); Assert.Equal(insertedMob1.Defense, mob[0].Defense); Assert.Equal(insertedMob1.Speed, mob[0].Speed); Assert.Equal(insertedMob2.Id, mob[1].Id); }
public void GetKillStats_GetsExistingKillStats() { //arrange using var contextFactory = new Project2ContextFactory(); using Project2Context context = contextFactory.CreateContext(); Player insertedPlayer = CreatePlayer(null); LootTable insertedLootTable = CreateLootTable(); context.Players.Add(insertedPlayer); context.LootTables.Add(insertedLootTable); context.SaveChanges(); Mob insertedMob = CreateMob(insertedLootTable.Id); context.Mobs.Add(insertedMob); context.SaveChanges(); KillStat insertedKillStat = CreateKillStat(insertedPlayer.Id, insertedMob.Id, 10); context.KillStats.Add(insertedKillStat); context.SaveChanges(); var repo = new PlayerRepository(context); //act List <Business.Model.KillStat> killStats = repo.GetKillStats(insertedPlayer.Id).ToList(); //assert Assert.Equal(insertedKillStat.Id, killStats[0].Id); Assert.Equal(insertedKillStat.PlayerId, killStats[0].PlayerId); Assert.Equal(insertedKillStat.MobId, killStats[0].MobId); Assert.Equal(insertedKillStat.Quantity, killStats[0].Quantity); }
public Business.Model.Player CreatePlayer(Business.Model.Player player, string characterName) { var newCharacter = new Character { CharacterName = characterName }; _context.Characters.Add(newCharacter); _context.SaveChanges(); var newPlayer = new Player { CharacterId = newCharacter.Id, Username = player.Username, Password = player.Password }; _context.Players.Add(newPlayer); _context.SaveChanges(); return(new Business.Model.Player { Id = newPlayer.Id, CharacterId = newPlayer.CharacterId, Username = newPlayer.Username, Password = newPlayer.Password }); }
/// <summary> /// Adds a Genre to the database /// </summary> /// <param name="genre">The Genre</param> public void Add(Genre genre) { var entity = new Model.Genre { GenreName = genre.GenreName }; _context.Genre.Add(entity); _context.SaveChanges(); }
/// <summary> /// Adds a MediaType to the database /// </summary> /// <param name="mediatype">The MediaType</param> public void Add(MediaType mediatype) { var entity = new MediaTypes { MediaTypesName = mediatype.Name }; _context.MediaTypes.Add(entity); _context.SaveChanges(); }
public ActionResult Create([Bind(Include = "MissionID,MissionName,MissionPresident,MissionAddress,MissionLanguage,MissionClimate,DominantReligion,FlagSource")] Missions missions) { if (ModelState.IsValid) { db.Missions.Add(missions); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(missions)); }
public ActionResult Create([Bind(Include = "MissionQuestionID,MissionID,UserID,Question,Answer")] MissionQuestions missionQuestions) { if (ModelState.IsValid) { db.MissionQuestions.Add(missionQuestions); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(missionQuestions)); }
public ActionResult Create([Bind(Include = "UserID,UserEmail,UserPassword,UserFirstName,UserLastName")] Users users) { if (ModelState.IsValid) { db.Users.Add(users); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(users)); }
public ActionResult Create([Bind(Include = "missionquestionID,question,answer,missionID")] MissionQuestions missionQuestions) { if (ModelState.IsValid) { db.MissionQuestions.Add(missionQuestions); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.missionID = new SelectList(db.Missions, "missionID", "missionName", missionQuestions.missionID); return(View(missionQuestions)); }
/// <summary> /// Create a Comment in the database /// </summary> /// <param name="comment">The Comment</param> public int Add(Comment comment) { var entity = new Comments { Content = comment.Content, ReviewId = comment.ReviewId, UserId = comment.UserId, CommentDate = DateTime.Now }; _context.Comments.Add(entity); _context.SaveChanges(); return(entity.CommentId); }
/// <summary> /// Creates a review in the database /// </summary> /// <param name="review">The Review</param> public int Add(Review review) { var entity = new Reviews { ReviewDate = review.ReviewDate, Rating = review.Rating, MediaId = review.MediaId, UserId = review.UserId, Content = review.Content }; _context.Reviews.Add(entity); _context.SaveChanges(); return(entity.ReviewId); }
public void GetAllWeapons_GetsAllWeapons() { // arrange using var contextFactory = new Project2ContextFactory(); using Project2Context context = contextFactory.CreateContext(); var insertedWeapon1 = CreateWeapon("AK-47"); var insertedWeapon2 = CreateWeapon("Katana"); context.Weapons.Add(insertedWeapon1); context.Weapons.Add(insertedWeapon2); context.SaveChanges(); var repo = new ItemRepository(context); // act List <Business.Model.Weapon> weapon = repo.GetAllWeapons().ToList(); // assert Assert.Equal(insertedWeapon1.Id, weapon[0].Id); Assert.Equal(insertedWeapon1.Name, weapon[0].Name); Assert.Equal(insertedWeapon1.Description, weapon[0].Description); Assert.Equal(insertedWeapon1.Damage, weapon[0].Damage); Assert.Equal(insertedWeapon1.AttackSpeed, weapon[0].AttackSpeed); Assert.Equal(insertedWeapon1.LevelRequirement, weapon[0].LevelRequirement); Assert.Equal(insertedWeapon1.Rarity, weapon[0].Rarity); Assert.Equal(insertedWeapon2.Id, weapon[1].Id); Assert.Equal(insertedWeapon2.Name, weapon[1].Name); }
public void GetAllConsumables_GetsAllConsumables() { // arrange using var contextFactory = new Project2ContextFactory(); using Project2Context context = contextFactory.CreateContext(); var insertedConsumable1 = CreateConsumable("Health Potion"); var insertedConsumable2 = CreateConsumable("Mana Potion"); context.Consumables.Add(insertedConsumable1); context.Consumables.Add(insertedConsumable2); context.SaveChanges(); var repo = new ItemRepository(context); // act List <Business.Model.Consumable> consumable = repo.GetAllConsumables().ToList(); // assert Assert.Equal(insertedConsumable1.Id, consumable[0].Id); Assert.Equal(insertedConsumable1.ItemName, consumable[0].ItemName); Assert.Equal(insertedConsumable1.Description, consumable[0].Description); Assert.Equal(insertedConsumable1.Duration, consumable[0].Duration); Assert.Equal(insertedConsumable1.Strength, consumable[0].Strength); Assert.Equal(insertedConsumable1.Type, consumable[0].Type); Assert.Equal(insertedConsumable2.Id, consumable[1].Id); Assert.Equal(insertedConsumable2.ItemName, consumable[1].ItemName); }
/// <summary> /// Creates a new Notification in the database /// </summary> /// <param name="notification">The Notification</param> public void Add(Notification notification) { var entity = new Notifications { NotificationId = notification.NotificationId, PostId = notification.ReviewId, ReciverId = notification.ReceiverId, SenderId = notification.SenderId, NotificationType = notification.Type, NotificationDate = notification.Date, Status = notification.Status }; _context.Notifications.Add(entity); _context.SaveChanges(); }
/// <summary> /// Creates a new Media in the database /// </summary> /// <param name="media">The Media</param> public void Add(Media media) { var entity = new Model.Media { Rating = media.Rating, MediaName = media.MediaName, Composer = media.Composer, Description = media.Description, MediaTypesId = media.MediaTypeId, MediaUrl = media.MediaUrl, GenreId = media.GenreId, Approved = media.Approved }; _context.Media.Add(entity); _context.SaveChanges(); }
/// <summary> /// Adds a user to the database /// </summary> /// <param name="user">The user</param> public void Add(User user) { var entity = new Users { FirstName = user.FirstName, LastName = user.LastName, UserName = user.UserName, Password = user.Password, Bio = user.Bio, Picture = user.Picture, Email = user.Email, AdminUser = user.AdminUser }; _context.Users.Add(entity); _context.SaveChanges(); }
public void UpdateCharacterStats_UpdatesCharacterStats() { //arrange using var contextFactory = new Project2ContextFactory(); using Project2Context context = contextFactory.CreateContext(); Character characterBeforeUpdate = CreateCharacter(); Character insertedCharacter = new Character { Id = characterBeforeUpdate.Id, CharacterName = characterBeforeUpdate.CharacterName, Exp = characterBeforeUpdate.Exp, Health = characterBeforeUpdate.Health, Attack = characterBeforeUpdate.Attack, Defense = characterBeforeUpdate.Defense, Mana = characterBeforeUpdate.Mana }; context.Characters.Add(insertedCharacter); context.SaveChanges(); characterBeforeUpdate.Id = insertedCharacter.Id; var characterUpdated = new Business.Model.Character { Id = insertedCharacter.Id, CharacterName = insertedCharacter.CharacterName, Exp = 15, Health = 12, Attack = 8, Defense = 6, Mana = 18 }; var repo = new PlayerRepository(context); //act repo.UpdateCharacterStats(characterUpdated); //assert Character character = context.Characters.Local.Single(c => c.Id == characterUpdated.Id); Assert.Equal(characterUpdated.Id, character.Id); Assert.Equal(characterUpdated.CharacterName, character.CharacterName); Assert.Equal(characterUpdated.Exp, character.Exp); Assert.Equal(characterUpdated.Health, character.Health); Assert.Equal(characterUpdated.Attack, character.Attack); Assert.Equal(characterUpdated.Mana, character.Mana); Assert.Equal(characterBeforeUpdate.Id, character.Id); Assert.Equal(characterBeforeUpdate.CharacterName, character.CharacterName); Assert.NotEqual(characterBeforeUpdate.Exp, character.Exp); Assert.NotEqual(characterBeforeUpdate.Health, character.Health); Assert.NotEqual(characterBeforeUpdate.Attack, character.Attack); Assert.NotEqual(characterBeforeUpdate.Mana, character.Mana); }
public void GetPlayer_GetsExistingPlayer() { //arrange using var contextFactory = new Project2ContextFactory(); using Project2Context context = contextFactory.CreateContext(); Character insertedCharacter = CreateCharacter(); context.Characters.Add(insertedCharacter); context.SaveChanges(); Player insertedPlayer = CreatePlayer(insertedCharacter.Id); context.Players.Add(insertedPlayer); context.SaveChanges(); var repo = new PlayerRepository(context); //act Business.Model.Player player = repo.GetPlayer(insertedPlayer.Username, insertedPlayer.Password); //assert Assert.Equal(insertedPlayer.Id, player.Id); Assert.Equal(insertedPlayer.CharacterId, player.CharacterId); Assert.Equal(insertedPlayer.Username, player.Username); Assert.Equal(insertedPlayer.Password, player.Password); }
public void GetMobSpawn_GetsAllMobSpawns() { // arrange using var contextFactory = new Project2ContextFactory(); using Project2Context context = contextFactory.CreateContext(); var insertedLootTable1 = CreateLootTable(); var insertedLootTable2 = CreateLootTable(); context.LootTables.Add(insertedLootTable1); context.LootTables.Add(insertedLootTable2); context.SaveChanges(); var insertedMob1 = CreateMob(insertedLootTable1.Id); var insertedMob2 = CreateMob(insertedLootTable2.Id); context.Mobs.Add(insertedMob1); context.Mobs.Add(insertedMob2); context.SaveChanges(); var insertedMobSpawn1 = CreateMobSpawn(insertedMob1.Id); var insertedMobSpawn2 = CreateMobSpawn(insertedMob2.Id); context.MobSpawns.Add(insertedMobSpawn1); context.SaveChanges(); context.MobSpawns.Add(insertedMobSpawn2); context.SaveChanges(); var repo = new MobRepository(context); // act List <Business.Model.MobSpawn> mobSpawns = repo.GetMobSpawns().ToList(); // assert Assert.Equal(insertedMobSpawn1.Id, mobSpawns[0].Id); Assert.Equal(insertedMobSpawn1.ModId, mobSpawns[0].ModId); Assert.Equal(insertedMobSpawn1.SpawnX, mobSpawns[0].SpawnX); Assert.Equal(insertedMobSpawn1.SpawnY, mobSpawns[0].SpawnY); Assert.Equal(insertedMobSpawn2.Id, mobSpawns[1].Id); }
public ActionResult Register([Bind(Include = "userEmail, password, firstName, lastName")] Users users) { if (ModelState.IsValid) { string email = users.userEmail; bool rememberMe = false; db.User.Add(users); db.SaveChanges(); FormsAuthentication.SetAuthCookie(email, rememberMe); return(RedirectToAction("Index", "Home")); } return(View(users)); }
public void GetConsumable_Gets1ConsumableById() { // arrange using var contextFactory = new Project2ContextFactory(); using Project2Context context = contextFactory.CreateContext(); var insertedConsumable = CreateConsumable("Health Potion"); context.Consumables.Add(insertedConsumable); context.SaveChanges(); var repo = new ItemRepository(context); // act Business.Model.Consumable consumable = repo.GetConsumable(insertedConsumable.Id); // assert Assert.Equal(insertedConsumable.Id, consumable.Id); Assert.Equal(insertedConsumable.ItemName, consumable.ItemName); Assert.Equal(insertedConsumable.Description, consumable.Description); Assert.Equal(insertedConsumable.Duration, consumable.Duration); Assert.Equal(insertedConsumable.Strength, consumable.Strength); Assert.Equal(insertedConsumable.Type, consumable.Type); }
public async Task UpdateCharacterExpAsync_UpdatesCharacterExp() { //arrange using var contextFactory = new Project2ContextFactory(); using Project2Context context = contextFactory.CreateContext(); Character characterBeforeUpdate = CreateCharacter(); Character insertedCharacter = new Character { Id = characterBeforeUpdate.Id, CharacterName = characterBeforeUpdate.CharacterName, Exp = characterBeforeUpdate.Exp, Health = characterBeforeUpdate.Health, Attack = characterBeforeUpdate.Attack, Defense = characterBeforeUpdate.Defense, Mana = characterBeforeUpdate.Mana }; context.Characters.Add(insertedCharacter); context.SaveChanges(); characterBeforeUpdate.Id = insertedCharacter.Id; var repo = new PlayerRepository(context); //act await repo.UpdateCharacterExpAsync(insertedCharacter.Id, 20); //assert Character character = context.Characters.Local.Single(c => c.Id == insertedCharacter.Id); Assert.Equal(insertedCharacter.Id, character.Id); Assert.Equal(insertedCharacter.CharacterName, character.CharacterName); Assert.Equal(characterBeforeUpdate.Exp + 20, character.Exp); Assert.Equal(insertedCharacter.Health, character.Health); Assert.Equal(insertedCharacter.Attack, character.Attack); Assert.Equal(insertedCharacter.Mana, character.Mana); Assert.Equal(characterBeforeUpdate.Id, character.Id); Assert.Equal(characterBeforeUpdate.CharacterName, character.CharacterName); Assert.NotEqual(characterBeforeUpdate.Exp, character.Exp); }
public void GetWeapon_Gets1ExistingWeaponById() { // arrange using var contextFactory = new Project2ContextFactory(); using Project2Context context = contextFactory.CreateContext(); var insertedWeapon = CreateWeapon("AK-47"); context.Weapons.Add(insertedWeapon); context.SaveChanges(); var repo = new ItemRepository(context); // act Business.Model.Weapon weapon = repo.GetWeapon(insertedWeapon.Id); // assert Assert.Equal(insertedWeapon.Id, weapon.Id); Assert.Equal(insertedWeapon.Name, weapon.Name); Assert.Equal(insertedWeapon.Description, weapon.Description); Assert.Equal(insertedWeapon.Damage, weapon.Damage); Assert.Equal(insertedWeapon.AttackSpeed, weapon.AttackSpeed); Assert.Equal(insertedWeapon.LevelRequirement, weapon.LevelRequirement); Assert.Equal(insertedWeapon.Rarity, weapon.Rarity); }
public void GetLeaderboard_GetsTop10Characters() { //arrange using var contextFactory = new Project2ContextFactory(); using Project2Context context = contextFactory.CreateContext(); List <Character> insertedCharacters = Create10Characters(); foreach (var character in insertedCharacters) { context.Characters.Add(character); } context.SaveChanges(); var repo = new PlayerRepository(context); //act List <Business.Model.Character> characters = repo.GetLeaderboard().ToList(); //assert Assert.Equal(11, characters[0].Exp); Assert.Equal(10, characters[1].Exp); Assert.Equal(3, characters[8].Exp); Assert.Equal(2, characters[9].Exp); }