public void Index() { SeedDataController controller = new SeedDataController(); ViewResult result = controller.Index() as ViewResult; Assert.NotNull(result); }
public async void Test_CreateDefaultUsers() { //arrange var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: "WorldCities") .Options; var storeOptions = Options.Create(new OperationalStoreOptions()); var mockEnv = new Mock <IWebHostEnvironment>().Object; ApplicationUser user_Admin = null; ApplicationUser user_User = null; ApplicationUser user_NotExisting = null; //act using (var context = new ApplicationDbContext(options, storeOptions)) { var roleStore = new RoleStore <IdentityRole> (context); // create a RoleManager instance var roleManager = IdentityHelper.GetRoleManager( new RoleStore <IdentityRole>(context)); var userStore = new UserStore <ApplicationUser>(context); var userManager = IdentityHelper.GetUserManager(userStore); var controller = new SeedDataController( context, mockEnv, roleManager, userManager ); await controller.CreateDefaultUsers(); user_Admin = await userManager.FindByEmailAsync("*****@*****.**"); user_User = await userManager.FindByEmailAsync("*****@*****.**"); user_NotExisting = await userManager.FindByEmailAsync("*****@*****.**"); } //assert Assert.NotNull(user_Admin); Assert.NotNull(user_User); Assert.Null(user_NotExisting); }
private void Awake() { // initialize mazePopulator = gameObject.AddComponent <MazePopulator>(); // Obtain seeds string seedDataFilePathBase = Application.streamingAssetsPath + "/SeedData/mazeDifficultySeeds"; string creatorName = ""; switch (mazeShape) { case 0: { creatorName = (new MazeFrameCreatorSquare3D(mazeSize)).GetType().FullName + "-" + mazeSize.ToString() + "-" + mazeScale.ToString(); break; } case 1: { creatorName = (new MazeFrameCreatorMeshIcosahedron(nDivisions)).GetType().FullName + "-" + nDivisions.ToString() + "-" + mazeScale.ToString(); break; } } if (nQuadrants != 0) { seedData = new SeedData[nQuadrants]; for (int i = 0; i < nQuadrants; i++) { string seedDataFilePath = seedDataFilePathBase + "-" + creatorName + "-" + "quadrant" + (i + 1) + "of" + nQuadrants + ".json"; seedData[i] = SeedDataController.LoadSeedData(seedDataFilePath); } } else { string seedDataFilePath = seedDataFilePathBase + "-" + creatorName + ".json"; seedData = new SeedData[1] { SeedDataController.LoadSeedData(seedDataFilePath) }; } for (int i = 0; i < seedData.Length; i++) { foreach (int diff in difficulties) { if (diff > (seedData[i].seeds.Length - 1)) { throw new System.Exception("Difficulty level not present in seeds"); } } } }
private IEnumerator CreateMazesFromSeeds() { // Parse difficulty float[,] difficultyBounds = new float[nDifficulties, 2]; float difficultyStartPad = difficultyLimits[0]; float difficultyEndPad = 1 - difficultyLimits[1]; float diffRange = 1 - (difficultyStartPad + difficultyEndPad); float currDiffSize = difficultySize * diffRange; float diffSpacing = (diffRange - (nDifficulties * currDiffSize)) / (nDifficulties - 1); if (diffSpacing < 0) { throw new System.Exception("Overlapping difficulties."); } for (int i = 0; i < (nDifficulties); i++) { difficultyBounds[i, 0] = difficultyStartPad + (currDiffSize + diffSpacing) * i; difficultyBounds[i, 1] = difficultyBounds[i, 0] + currDiffSize; } string boundsDisp = difficultyBounds[0, 0] + ">x<=" + difficultyBounds[0, 1]; for (int i = 1; i < nDifficulties; i++) { boundsDisp = boundsDisp + " | " + difficultyBounds[i, 0] + ">x<=" + difficultyBounds[i, 1]; } Debug.Log(boundsDisp); //seedList[0] = new List<int>(nMazes); // difficulty <=.20 //seedList[0] = new List<int>(nMazes); // difficulty >.20 <=.40 //seedList[0] = new List<int>(nMazes); // difficulty >.40 <=.60 //seedList[0] = new List<int>(nMazes); // difficulty >.60 <=80 //seedList[0] = new List<int>(nMazes); // difficulty >.80 <=1 // Set random seed int mainRandomSeed = System.Environment.TickCount; ConsistentRandom mainRandomGenenerator = new ConsistentRandom(mainRandomSeed); // Setup maze creators MazeFrameCreator mazeFrameCreator = null; switch (mazeShape) { case 0: { mazeFrameCreator = new MazeFrameCreatorSquare3D(mazeSize, nQuadrants); break; } case 1: { mazeFrameCreator = new MazeFrameCreatorMeshIcosahedron(divisions, nQuadrants); break; } } mazeFrameCreator.Scale = mazeScale; // Used in hunt and kill for determining when to hunt // Create level from new seeds int ittMax = 1; if (nQuadrants != 0) { ittMax = nQuadrants; } for (int iQuadrant = 0; iQuadrant < ittMax; iQuadrant++) { // Setup seed/difficulty list List <List <int> > seedList = new List <List <int> >(nDifficulties); for (int i = 0; i < nDifficulties; i++) { seedList.Add(new List <int>(nMazes)); } List <List <float> > difficultyList = new List <List <float> >(nDifficulties); for (int i = 0; i < nDifficulties; i++) { difficultyList.Add(new List <float>(nMazes)); } bool done = false; int count = 0; while (!done) { // set new seed int mazeSeed = mainRandomGenenerator.Next(); mazeFrameCreator.RandomSeed = mazeSeed; // get maze MazeFrame mazeFrame = mazeFrameCreator.GenerateEmptyMazeFrame(); if (nQuadrants != 0) { mazeFrame.SetActiveQuadrant(iQuadrant); } mazeFrameCreator.GenerateMaze(ref mazeFrame); // Save according to difficulty float difficulty; if (nQuadrants == 0) { difficulty = mazeFrame.GetDifficulty()[0]; } else { difficulty = mazeFrame.GetDifficulty(iQuadrant)[0]; } for (int i = 0; i < nDifficulties; i++) { if (difficulty > difficultyBounds[i, 0] && difficulty <= difficultyBounds[i, 1] && seedList[i].Count < nMazes) { seedList[i].Add(mazeSeed); difficultyList[i].Add(difficulty); } } // Check end condition done = true; for (int i = 0; i < nDifficulties; i++) { done = done && seedList[i].Count == nMazes; } // safety check count++; if (count == count * 100) { throw new System.Exception("Something went wrong."); } // Display progress string disp; if (nQuadrants == 0) { disp = count + ": " + seedList[0].Count; } else { disp = "quadrant" + (iQuadrant + 1) + "of" + nQuadrants + " | " + count + ": " + seedList[0].Count; } for (int i = 1; i < nDifficulties; i++) { disp = disp + ", " + seedList[i].Count; } Debug.Log(disp + " | d = " + difficulty.ToString("0.0000")); // Yield WaitForSecondsRealtime wait = null; if (wait == null) { wait = new WaitForSecondsRealtime(0.0001f); } if ((count % 10) == 0) { yield return(wait); } } // Convert to SeedData object if (nDifficulties == 5) { seedData = new SeedData(seedList[0].ToArray(), seedList[1].ToArray(), seedList[2].ToArray(), seedList[3].ToArray(), seedList[4].ToArray(), difficultyList[0].ToArray(), difficultyList[1].ToArray(), difficultyList[2].ToArray(), difficultyList[3].ToArray(), difficultyList[4].ToArray(), mazeSize, mazeFrameCreator.GetType().FullName); } else if (nDifficulties == 4) {// Convert to SeedData object seedData = new SeedData(seedList[0].ToArray(), seedList[1].ToArray(), seedList[2].ToArray(), seedList[3].ToArray(), difficultyList[0].ToArray(), difficultyList[1].ToArray(), difficultyList[2].ToArray(), difficultyList[3].ToArray(), mazeSize, mazeFrameCreator.GetType().FullName); } else if (nDifficulties == 3) {// Convert to SeedData object seedData = new SeedData(seedList[0].ToArray(), seedList[1].ToArray(), seedList[2].ToArray(), difficultyList[0].ToArray(), difficultyList[1].ToArray(), difficultyList[2].ToArray(), mazeSize, mazeFrameCreator.GetType().FullName); } else if (nDifficulties == 2) {// Convert to SeedData object seedData = new SeedData(seedList[0].ToArray(), seedList[1].ToArray(), difficultyList[0].ToArray(), difficultyList[1].ToArray(), mazeSize, mazeFrameCreator.GetType().FullName); } else { throw new System.Exception("Requested nDifficulty not implemented due to the stupid save part."); } // Save to disk string creatorName = ""; string filePath; switch (mazeShape) { case 0: { creatorName = mazeFrameCreator.GetType().FullName + "-" + mazeSize.ToString() + "-" + mazeScale.ToString(); break; } case 1: { creatorName = mazeFrameCreator.GetType().FullName + "-" + divisions.ToString() + "-" + mazeScale.ToString(); break; } } if (nQuadrants != 0) { filePath = filePathBase + "-" + creatorName + "-" + "quadrant" + (iQuadrant + 1) + "of" + nQuadrants + ".json"; } else { filePath = filePathBase + "-" + creatorName + ".json"; } SeedDataController.SaveSeedData(seedData, filePath); } Debug.Log("Done!"); Debug.Break(); #if UNITY_EDITOR UnityEditor.EditorApplication.isPlaying = false; #endif }