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 UsersSeederShouldWork()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "UsersSeederShouldWork").Options;
            var dbContext = new ApplicationDbContext(options);

            var imagesRepository = new EfDeletableEntityRepository <Image>(dbContext);
            var userManager      = this.GetUserManager(dbContext);
            await userManager.CreateAsync(new ApplicationUser()
            {
                UserName = "******"
            });

            await userManager.CreateAsync(new ApplicationUser()
            {
                UserName = "******"
            });

            var serviceProvider = new Mock <IServiceProvider>();

            serviceProvider
            .Setup(x => x.GetService(typeof(UserManager <ApplicationUser>)))
            .Returns(userManager);

            var seeder = new UsersSeeder();
            await seeder.SeedAsync(dbContext, serviceProvider.Object);

            Assert.NotEmpty(dbContext.Users);
        }
Exemplo n.º 3
0
        public async Task UsersSeederDoesntAffectFilledDb()
        {
            // Arrange
            var roles = new List <CinemaRole>
            {
                new CinemaRole {
                    Name = "Admin", NormalizedName = "ADMIN", Role = RoleType.Admin
                }
            }.AsQueryable();
            var users = new List <CinemaUser> {
                new CinemaUser()
            }.AsQueryable();
            var usersRoles = new List <IdentityUserRole <string> >().AsQueryable();

            var rolesMockSet = new Mock <DbSet <CinemaRole> >();

            rolesMockSet.As <IQueryable <CinemaRole> >().Setup(m => m.Provider).Returns(roles.Provider);
            rolesMockSet.As <IQueryable <CinemaRole> >().Setup(m => m.Expression).Returns(roles.Expression);
            rolesMockSet.As <IQueryable <CinemaRole> >().Setup(m => m.ElementType).Returns(roles.ElementType);
            rolesMockSet.As <IQueryable <CinemaRole> >().Setup(m => m.GetEnumerator()).Returns(roles.GetEnumerator());

            var usersMockSet = new Mock <DbSet <CinemaUser> >();

            usersMockSet.As <IQueryable <CinemaUser> >().Setup(m => m.Provider).Returns(users.Provider);
            usersMockSet.As <IQueryable <CinemaUser> >().Setup(m => m.Expression).Returns(users.Expression);
            usersMockSet.As <IQueryable <CinemaUser> >().Setup(m => m.ElementType).Returns(users.ElementType);
            usersMockSet.As <IQueryable <CinemaUser> >().Setup(m => m.GetEnumerator()).Returns(users.GetEnumerator());

            var usersRolesMockSet = new Mock <DbSet <IdentityUserRole <string> > >();

            usersRolesMockSet.As <IQueryable <IdentityUserRole <string> > >().Setup(m => m.Provider).Returns(usersRoles.Provider);
            usersRolesMockSet.As <IQueryable <IdentityUserRole <string> > >().Setup(m => m.Expression).Returns(usersRoles.Expression);
            usersRolesMockSet.As <IQueryable <IdentityUserRole <string> > >().Setup(m => m.ElementType).Returns(usersRoles.ElementType);
            usersRolesMockSet.As <IQueryable <IdentityUserRole <string> > >().Setup(m => m.GetEnumerator()).Returns(usersRoles.GetEnumerator());

            var mockContext = new Mock <CinemaDbContext>();

            mockContext.Setup(c => c.Roles).Returns(rolesMockSet.Object);
            mockContext.Setup(c => c.Users).Returns(usersMockSet.Object);
            mockContext.Setup(c => c.UserRoles).Returns(usersRolesMockSet.Object);

            mockContext.Setup(m => m.AddAsync(It.IsAny <CinemaUser>(), It.IsAny <CancellationToken>())).
            Returns(new ValueTask <EntityEntry <CinemaUser> >(Task.FromResult((EntityEntry <CinemaUser>)null)));
            mockContext.Setup(m => m.AddAsync(It.IsAny <CinemaRole>(), It.IsAny <CancellationToken>())).
            Returns(new ValueTask <EntityEntry <CinemaRole> >(Task.FromResult((EntityEntry <CinemaRole>)null)));
            mockContext.Setup(m => m.AddAsync(It.IsAny <IdentityUserRole <string> >(), It.IsAny <CancellationToken>())).
            Returns(new ValueTask <EntityEntry <IdentityUserRole <string> > >(Task.FromResult((EntityEntry <IdentityUserRole <string> >)null)));

            var seeder = new UsersSeeder();

            // Act
            await seeder.SeedAsync(mockContext.Object);

            // Assert
            mockContext.Verify(x => x.Users.AddAsync(It.IsAny <CinemaUser>(), It.IsAny <CancellationToken>()), Times.Never);
            mockContext.Verify(x => x.SaveChangesAsync(It.IsAny <CancellationToken>()), Times.Never);
        }
Exemplo n.º 4
0
        protected override void Seed(SqlConfidenceContext context)
        {
            var dataSourceSeeder = new DataSourceSeeder();
            var usersSeeder      = new UsersSeeder();
            var multipleChoiceQuestionsSeeder = new MultipleChoiceQuestionsSeeder();
            var userActionTypesSeeder         = new UserActionTypesSeeder();

            dataSourceSeeder.Seed(context);
            usersSeeder.Seed(context);
            multipleChoiceQuestionsSeeder.Seed(context);
            userActionTypesSeeder.Seed(context);
        }
Exemplo n.º 5
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.º 7
0
    // TODO: Move this code when seed data is implemented in EF 7

    /// <summary>
    /// This is a workaround for missing seed data functionality in EF 7.0-rc1
    /// More info: https://github.com/aspnet/EntityFramework/issues/629
    /// </summary>
    /// <param name="app">
    /// An instance that provides the mechanisms to get instance of the database context.
    /// </param>
    public static void SeedData(this IApplicationBuilder app)
    {
        var context = app.ApplicationServices.GetService <SqlConfidenceContext>();

        var dataSourceSeeder              = new DataSourceSeeder();
        var usersSeeder                   = new UsersSeeder();
        var queryQuestionsSeeder          = new QueryQuestionsSeeder();
        var multipleChoiceQuestionsSeeder = new MultipleChoiceQuestionsSeeder();
        var userActionTypesSeeder         = new UserActionTypesSeeder();

        dataSourceSeeder.Seed(context);
        usersSeeder.Seed(context);
        queryQuestionsSeeder.Seed(context);
        multipleChoiceQuestionsSeeder.Seed(context);
        userActionTypesSeeder.Seed(context);
    }
Exemplo n.º 8
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}");
        }
        private static IEnumerable <ApplicationUser> SeedUsers(ModelBuilder b)
        {
            var users = UsersSeeder.GetUsers();

            b.Entity <Admin>().HasData(users.Item1);
            b.Entity <Athlete>().HasData(users.Item2);
            b.Entity <Coach>().HasData(users.Item3);
            b.Entity <SoloAthlete>().HasData(users.Item4);

            return(new List <ApplicationUser>()
            {
                users.Item1,
                users.Item2,
                users.Item3,
                users.Item4
            });
        }
        public static void EnsureSeedDataForContext(this EshopDbContext context)
        {
            // first, clear the database.  This ensures we can always start
            context.Database.EnsureDeleted();
            context.Database.EnsureCreated();

            RolesSeeder.Seed(context);
            UsersSeeder.Seed(context);

            VendorSeeder.Seed(context);

            CategorySeeder.Seed(context);

            ProductStateSeeder.Seed(context);
            ProductSeeder.Seed(context);

            OrderStateSeeder.Seed(context);
        }
Exemplo n.º 11
0
        public Startup(
            ApplyMigration applyMigration,
            ProductionSeeder productionSeeder,
            IOptions <SeedingOptions> options,
            UsersSeeder usersSeeder,
            CompaniesSeeder companiesSeeder,
            OrgUnitsSeeder orgUnitsSeeder,
            OrgUnitsMOLSeeder orgUnitsMOLSeeder)
        {
            _applyMigration   = applyMigration;
            _productionSeeder = productionSeeder;
            _options          = options;
            _usersSeeder      = usersSeeder;
            _companiesSeeder  = companiesSeeder;

            _orgUnitsSeeder    = orgUnitsSeeder;
            _orgUnitsMOLSeeder = orgUnitsMOLSeeder;
        }
Exemplo n.º 12
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.º 13
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.º 14
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.º 15
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.");
        }