public async Task DoesUserHaveActiveGatherTasks()
        {
            var context      = ApplicationDbContextInMemoryFactory.InitializeContext();
            var tasksService = this.GetTasksService(context);

            var seeder = new UsersSeeder();
            await seeder.SeedUsers(context);

            var userDoentHaveActiveTask = context.Users.First(x => x.UserName == "User1");
            var userHasActiveTask       = context.Users.First(x => x.UserName == "User2");

            await context.TasksGather.AddAsync(new TaskGather
            {
                Id         = Guid.NewGuid().ToString(),
                UserId     = userDoentHaveActiveTask.Id,
                IsComplete = true,
            });

            await context.TasksGather.AddAsync(new TaskGather
            {
                Id         = Guid.NewGuid().ToString(),
                UserId     = userHasActiveTask.Id,
                IsComplete = false,
            });

            await context.SaveChangesAsync();

            var returnsFalse = tasksService.HasActiveTask(userDoentHaveActiveTask.Id, "Gather");
            var returnsTrue  = tasksService.HasActiveTask(userHasActiveTask.Id, "Gather");

            Assert.True(returnsFalse == false, $"User has an active task.");
            Assert.True(returnsTrue == true, $"User doen't have an active task.");
        }
Exemplo n.º 2
0
        public async Task CreateCraftableModelReturnsValidModel()
        {
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();
            var service = GetBlacksmithService(context);

            var usersSeeder = new UsersSeeder();
            await usersSeeder.SeedUsers(context);

            var result = service.CreateCraftableModel("Chest", "Id1");

            Assert.True(result.Title == "Chest", "Model doesn't have correct title.");
            Assert.True(result.PartialName == "_BlacksmithArmors", "Model doesn't have correct partial name.");
        }
        public async Task GenerateGatheringTaskShouldAddTaskToDb()
        {
            var context      = ApplicationDbContextInMemoryFactory.InitializeContext();
            var tasksService = this.GetTasksService(context);

            var seeder = new UsersSeeder();
            await seeder.SeedUsers(context);

            await tasksService.GenerateGatheringTask(MaterialType.Metal.ToString(), AdventureDifficulties.Hard.ToString(), "Id1");

            var result = context.TasksGather.Any(x => x.UserId == "Id1");

            Assert.True(result == true, "User doesn't have generated gathering task.");
        }
Exemplo n.º 4
0
        public async Task UserSeedsCorrectAmountOfMaterialsOnRegister()
        {
            var context     = ApplicationDbContextInMemoryFactory.InitializeContext();
            var userService = this.GetUserService(context);

            var seeder = new UsersSeeder();
            await seeder.SeedUsers(context);

            var user = context.Users.First(x => x.UserName == "User1");

            await userService.SeedDatabaseOnSuccessfulRegister(user.Id);

            var result = context.Materials.Where(x => x.UserId == user.Id).Count();

            Assert.True(result == 10, $"User has incorrect amount of rescources. {result}");
        }
Exemplo n.º 5
0
        public async Task OpponendShouldWinWhenBothPlayersHaveNoItems_Tie()
        {
            var context      = ApplicationDbContextInMemoryFactory.InitializeContext();
            var arenaService = this.GetArenaService(context);

            var seederUsers = new UsersSeeder();
            await seederUsers.SeedUsers(context);

            var seederCoins = new UsersCoinsSeeder();
            await seederCoins.SeedUsersWithCoins(context);

            var battleReportId = await arenaService.AttackOpponent("User1", "User2");

            var battleResult = context.BattleReports.Where(x => x.Id == battleReportId).SingleOrDefault().ReportString;

            var result = battleResult.Split(".\r\n");

            Assert.True(result[result.Count() - 2] == "User2 defended his glory and gold", $"Defendant doen't die, but still lost.");
        }
Exemplo n.º 6
0
        public async Task DoesAddArmorItemToUserMethodAddItem()
        {
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();
            var service = GetBlacksmithService(context);

            var usersSeeder = new UsersSeeder();
            await usersSeeder.SeedUsers(context);

            var itemsSeeder = new CraftableArmorsSeeder();
            await itemsSeeder.SeedCraftableArmors(context);

            var materialsSeeder = new UsersMaterialSeeder();
            await materialsSeeder.SeedUserWithMaterials(context, "Id1");

            await service.AddArmorItemToUser("Id1", "Id1");

            var result = context.Armors.Where(x => x.Name == "Test armor 1" && x.UserId == "Id1");

            Assert.True(result != null, "User doesn't have added armor");
        }
Exemplo n.º 7
0
        public async Task AttackerShouldWinWhenOpponentIsKilledAndShouldTakeHalfHisGold()
        {
            var context      = ApplicationDbContextInMemoryFactory.InitializeContext();
            var arenaService = this.GetArenaService(context);

            var seederUsers = new UsersSeeder();
            await seederUsers.SeedUsers(context);

            var seederCoins = new UsersCoinsSeeder();
            await seederCoins.SeedUsersWithCoins(context);

            var arenaSeeder = new ArenaSeeder();
            await arenaSeeder.SeedAttackerWithKillingWeapon(context);

            var battleReportId = await arenaService.AttackOpponent("User1", "User2");

            var battleResult = context.BattleReports.Where(x => x.Id == battleReportId).SingleOrDefault().ReportString;

            var result = battleResult.Split(".\r\n");

            Assert.True(result[result.Count() - 2] == "User1 took 250 gold from User2", $"Defendant dies, but still ties.");
        }
Exemplo n.º 8
0
        public async Task DefendantShouldKillAttacker()
        {
            var context      = ApplicationDbContextInMemoryFactory.InitializeContext();
            var arenaService = this.GetArenaService(context);

            var seederUsers = new UsersSeeder();
            await seederUsers.SeedUsers(context);

            var seederCoins = new UsersCoinsSeeder();
            await seederCoins.SeedUsersWithCoins(context);

            var arenaSeeder = new ArenaSeeder();
            await arenaSeeder.SeedDefendantWithKillingWeapon(context);

            var battleReportId = await arenaService.AttackOpponent("User1", "User2");

            var battleResult = context.BattleReports.Where(x => x.Id == battleReportId).SingleOrDefault().ReportString;

            var result = battleResult.Split(".\r\n");

            Assert.True(result[result.Count() - 2] == "User2 defended his glory and gold", $"Defendant lives, but still looses.");
            Assert.True(result[result.Count() - 3] == "User1 died", $"Attacker doen't die when hit with killing blow.");
        }
        public async Task CheckIfActiveTaskIsComplete()
        {
            var context      = ApplicationDbContextInMemoryFactory.InitializeContext();
            var tasksService = this.GetTasksService(context);

            var seeder = new UsersSeeder();
            await seeder.SeedUsers(context);

            var user1 = context.Users.First(x => x.UserName == "User1");
            var user2 = context.Users.First(x => x.UserName == "User2");

            await context.TasksGather.AddAsync(new TaskGather
            {
                Id         = Guid.NewGuid().ToString(),
                UserId     = user1.Id,
                IsComplete = false,
                EndTime    = DateTime.UtcNow.AddDays(-1),
            });

            await context.TasksGather.AddAsync(new TaskGather
            {
                Id         = Guid.NewGuid().ToString(),
                UserId     = user2.Id,
                IsComplete = false,
                EndTime    = DateTime.UtcNow.AddDays(1)
            });

            await context.SaveChangesAsync();

            var returnsTrue = await tasksService.CheckGatheringTaskCompletion(user1.Id);

            var returnsFalse = await tasksService.CheckGatheringTaskCompletion(user2.Id);

            Assert.True(returnsTrue == true, $"User didn't complete his task.");
            Assert.True(returnsFalse == false, $"User completed his task when he shouldn't have.");
        }