public async Task NoFileAndNoDb() { LocalDbApi.StopAndDelete("TestDbContext_EfNoFileAndNoDb"); var directory = DirectoryFinder.Find("TestDbContext_EfNoFileAndNoDb"); if (Directory.Exists(directory)) { Directory.Delete(directory, true); } var instance = new SqlInstance <TestDbContext>( constructInstance: builder => new TestDbContext(builder.Options), instanceSuffix: "EfNoFileAndNoDb"); var entity = new TestEntity { Property = "prop" }; using (var database = await instance.Build(new List <object> { entity })) { Assert.NotNull(database.Context.TestEntities.FindAsync(entity.Id)); } }
public SqlInstance( string name, Func <SqlConnection, Task> buildTemplate, string?directory = null, DateTime?timestamp = null, ushort templateSize = 3) { Guard.AgainstNull(nameof(buildTemplate), buildTemplate); Guard.AgainstWhiteSpace(nameof(directory), directory); Guard.AgainstNullWhiteSpace(nameof(name), name); if (directory == null) { directory = DirectoryFinder.Find(name); } DateTime resultTimestamp; if (timestamp == null) { var callingAssembly = Assembly.GetCallingAssembly(); resultTimestamp = Timestamp.LastModified(callingAssembly); } else { resultTimestamp = timestamp.Value; } wrapper = new Wrapper(name, directory, templateSize); wrapper.Start(resultTimestamp, buildTemplate); }
public async Task RecreateWithOpenConnection() { var name = "RecreateWithOpenConnection"; LocalDbApi.StopAndDelete(name); DirectoryFinder.Delete(name); Wrapper wrapper = new(s => new SqlConnection(s), name, DirectoryFinder.Find(name)); wrapper.Start(timestamp, TestDbBuilder.CreateTable); var connectionString = await wrapper.CreateDatabaseFromTemplate("Simple"); await using (SqlConnection connection = new(connectionString)) { await connection.OpenAsync(); wrapper = new(s => new SqlConnection(s), name, DirectoryFinder.Find(name)); wrapper.Start(timestamp, TestDbBuilder.CreateTable); await wrapper.CreateDatabaseFromTemplate("Simple"); } await Verifier.Verify(wrapper.ReadDatabaseState("Simple")); LocalDbApi.StopInstance(name); }
public async Task NoFileAndWithInstanceAndNamedDb() { var instanceName = "NoFileAndWithInstanceAndNamedDb"; LocalDbApi.StopAndDelete(instanceName); LocalDbApi.CreateInstance(instanceName); DirectoryFinder.Delete(instanceName); Wrapper wrapper = new(s => new SqlConnection(s), instanceName, DirectoryFinder.Find(instanceName)); wrapper.Start(timestamp, TestDbBuilder.CreateTable); await wrapper.AwaitStart(); await wrapper.CreateDatabaseFromTemplate("Simple"); Thread.Sleep(3000); DirectoryFinder.Delete(instanceName); wrapper = new(s => new SqlConnection(s), instanceName, DirectoryFinder.Find(instanceName)); wrapper.Start(timestamp, TestDbBuilder.CreateTable); await wrapper.AwaitStart(); await wrapper.CreateDatabaseFromTemplate("Simple"); await Verifier.Verify(wrapper.ReadDatabaseState("Simple")); }
public Task WithRebuild() { var instance2 = new Wrapper(s => new SqlConnection(s), "WrapperTests", DirectoryFinder.Find("WrapperTests")); instance2.Start(timestamp, connection => throw new Exception()); return(instance2.AwaitStart()); }
public async Task RecreateWithOpenConnectionAfterStartup() { /* * could be supported by running the following in wrapper CreateDatabaseFromTemplate * but it is fairly unlikely to happen and not doing the offline saves time in tests * * if db_id('{name}') is not null * begin * alter database [{name}] set single_user with rollback immediate; * alter database [{name}] set multi_user; * alter database [{name}] set offline; * end; */ LocalDbApi.StopAndDelete("RecreateWithOpenConnectionAfterStartup"); DirectoryFinder.Delete("RecreateWithOpenConnectionAfterStartup"); var wrapper = new Wrapper("RecreateWithOpenConnectionAfterStartup", DirectoryFinder.Find("RecreateWithOpenConnectionAfterStartup")); wrapper.Start(timestamp, TestDbBuilder.CreateTable); var connectionString = await wrapper.CreateDatabaseFromTemplate("Simple"); using (var connection = new SqlConnection(connectionString)) { await connection.OpenAsync(); await wrapper.CreateDatabaseFromTemplate("Simple"); wrapper = new Wrapper("RecreateWithOpenConnectionAfterStartup", DirectoryFinder.Find("RecreateWithOpenConnection")); wrapper.Start(timestamp, TestDbBuilder.CreateTable); await wrapper.CreateDatabaseFromTemplate("Simple"); } ObjectApprover.Verify(await wrapper.ReadDatabaseState("Simple")); LocalDbApi.StopInstance("RecreateWithOpenConnectionAfterStartup"); }
static WrapperTests() { LocalDbApi.StopAndDelete("WrapperTests"); instance = new Wrapper(s => new SqlConnection(s), "WrapperTests", DirectoryFinder.Find("WrapperTests")); instance.Start(timestamp, TestDbBuilder.CreateTable); instance.AwaitStart().GetAwaiter().GetResult(); }
public void Run() { LocalDbApi.StopAndDelete("DanglingLogWrapperTests"); var instance = new Wrapper(s => new SqlConnection(s), "WrapperTests", DirectoryFinder.Find("DanglingLogWrapperTests")); base.Dispose(); instance.Start(DateTime.Now, TestDbBuilder.CreateTable); }
public void Run() { var name = "DanglingLogWrapperTests"; LocalDbApi.StopAndDelete(name); Wrapper instance = new(s => new SqlConnection(s), name, DirectoryFinder.Find(name)); instance.Start(DateTime.Now, TestDbBuilder.CreateTable); }
public async Task DefinedTimestamp() { var instance2 = new Wrapper(s => new SqlConnection(s), "DefinedTimestamp", DirectoryFinder.Find("DefinedTimestamp")); var dateTime = DateTime.Now; instance2.Start(dateTime, connection => Task.CompletedTask); await instance2.AwaitStart(); Assert.Equal(dateTime, File.GetCreationTime(instance2.TemplateDataFile)); }
public async Task WithRebuild() { Wrapper instance2 = new(s => new SqlConnection(s), "WrapperTests", DirectoryFinder.Find("WrapperTests")); SqlRecording.StartRecording(); instance2.Start(timestamp, _ => throw new()); await instance2.AwaitStart(); var entries = SqlRecording.FinishRecording(); await Verifier.Verify(entries); }
public async Task DefinedTimestamp() { var name = "DefinedTimestamp"; Wrapper instance2 = new(s => new SqlConnection(s), name, DirectoryFinder.Find(name)); var dateTime = DateTime.Now; instance2.Start(dateTime, _ => Task.CompletedTask); await instance2.AwaitStart(); Assert.Equal(dateTime, File.GetCreationTime(instance2.DataFile)); }
public SqlInstance( Func <SqlConnection, DbContextOptionsBuilder <TDbContext>, Task> buildTemplate, Func <DbContextOptionsBuilder <TDbContext>, TDbContext> constructInstance, string?instanceSuffix = null, DateTime?timestamp = null, ushort templateSize = 3) { var instanceName = GetInstanceName(instanceSuffix); var directory = DirectoryFinder.Find(instanceName); Init(buildTemplate, constructInstance, instanceName, directory, timestamp, templateSize); }
public async Task NoFileAndNoInstance() { LocalDbApi.StopAndDelete("NoFileAndNoInstance"); DirectoryFinder.Delete("NoFileAndNoInstance"); var wrapper = new Wrapper("NoFileAndNoInstance", DirectoryFinder.Find("NoFileAndNoInstance")); wrapper.Start(timestamp, TestDbBuilder.CreateTable); await wrapper.CreateDatabaseFromTemplate("Simple"); ObjectApprover.Verify(await wrapper.ReadDatabaseState("Simple")); LocalDbApi.StopInstance("NoFileAndNoInstance"); }
public async Task WithFileAndNoInstance() { var wrapper = new Wrapper(s => new SqlConnection(s), "WithFileAndNoInstance", DirectoryFinder.Find("WithFileAndNoInstance")); wrapper.Start(timestamp, TestDbBuilder.CreateTable); await wrapper.AwaitStart(); wrapper.DeleteInstance(); wrapper = new Wrapper(s => new SqlConnection(s), "WithFileAndNoInstance", DirectoryFinder.Find("WithFileAndNoInstance")); wrapper.Start(timestamp, TestDbBuilder.CreateTable); await wrapper.CreateDatabaseFromTemplate("Simple"); await Verify(await wrapper.ReadDatabaseState("Simple")); LocalDbApi.StopInstance("WithFileAndNoInstance"); }
public SqlInstance( Func <DbContextOptionsBuilder <TDbContext>, TDbContext> constructInstance, Func <TDbContext, Task>?buildTemplate = null, string?instanceSuffix = null, DateTime?timestamp = null, ushort templateSize = 3) { Guard.AgainstWhiteSpace(nameof(instanceSuffix), instanceSuffix); Guard.AgainstNull(nameof(constructInstance), constructInstance); var instanceName = GetInstanceName(instanceSuffix); var directory = DirectoryFinder.Find(instanceName); var convertedBuildTemplate = BuildTemplateConverter.Convert(constructInstance, buildTemplate); Init(convertedBuildTemplate, constructInstance, instanceName, directory, timestamp, templateSize); }
public async Task NoFileAndNoInstance() { var name = "NoFileAndNoInstance"; LocalDbApi.StopAndDelete(name); DirectoryFinder.Delete(name); Wrapper wrapper = new(s => new SqlConnection(s), name, DirectoryFinder.Find(name)); wrapper.Start(timestamp, TestDbBuilder.CreateTable); await wrapper.CreateDatabaseFromTemplate("Simple"); await Verifier.Verify(wrapper.ReadDatabaseState("Simple")); LocalDbApi.StopInstance(name); }
public SqlInstance( string name, Func <DbConnection, Task> buildTemplate, string?directory = null, DateTime?timestamp = null, ushort templateSize = 3) { Guard.AgainstNull(nameof(buildTemplate), buildTemplate); Guard.AgainstWhiteSpace(nameof(directory), directory); Guard.AgainstNullWhiteSpace(nameof(name), name); directory = DirectoryFinder.Find(name); DirectoryCleaner.CleanInstance(directory); var callingAssembly = Assembly.GetCallingAssembly(); var resultTimestamp = GetTimestamp(timestamp, buildTemplate, callingAssembly); Wrapper = new Wrapper(s => new SqlConnection(s), name, directory, templateSize); Wrapper.Start(resultTimestamp, buildTemplate); }
public SqlInstance( string name, Action <SqlConnection> buildTemplate, string directory = null, DateTime?timestamp = null, ushort templateSize = 3) { Guard.AgainstNull(nameof(buildTemplate), buildTemplate); Guard.AgainstWhiteSpace(nameof(directory), directory); Guard.AgainstNullWhiteSpace(nameof(name), name); if (directory == null) { directory = DirectoryFinder.Find(name); } wrapper = new Wrapper(name, directory, templateSize); wrapper.Start(timestamp.GetValueOrDefault(DateTime.Now), buildTemplate); }
public async Task Callback() { var name = "WrapperTests_Callback"; var callbackCalled = false; Wrapper wrapper = new( s => new SqlConnection(s), name, DirectoryFinder.Find(name), callback : _ => { callbackCalled = true; return(Task.CompletedTask); }); wrapper.Start(timestamp, TestDbBuilder.CreateTable); await wrapper.CreateDatabaseFromTemplate("Simple"); Assert.True(callbackCalled); LocalDbApi.StopAndDelete(name); }
public async Task RecreateWithOpenConnection() { LocalDbApi.StopAndDelete("RecreateWithOpenConnection"); DirectoryFinder.Delete("RecreateWithOpenConnection"); var wrapper = new Wrapper("RecreateWithOpenConnection", DirectoryFinder.Find("RecreateWithOpenConnection")); wrapper.Start(timestamp, TestDbBuilder.CreateTable); var connectionString = await wrapper.CreateDatabaseFromTemplate("Simple"); using (var connection = new SqlConnection(connectionString)) { await connection.OpenAsync(); wrapper = new Wrapper("RecreateWithOpenConnection", DirectoryFinder.Find("RecreateWithOpenConnection")); wrapper.Start(timestamp, TestDbBuilder.CreateTable); await wrapper.CreateDatabaseFromTemplate("Simple"); } ObjectApprover.Verify(await wrapper.ReadDatabaseState("Simple")); LocalDbApi.StopInstance("RecreateWithOpenConnection"); }
/// <summary> /// It process the search of the drives. The paths and names are saved. /// </summary> private void ProcessDrives() { // It delete all trail of the previous search. _drivesPath.Clear(); _drivesName.Clear(); // It checks if the game is executed on Windows. if (Application.platform == RuntimePlatform.WindowsPlayer || Application.platform == RuntimePlatform.WindowsEditor) { // It gets all the Windows drives. string[] allDrives = Environment.GetLogicalDrives(); // The array is traversed on search of the necessary. foreach (string drive in allDrives) { _drivesPath.Add(drive.Trim()); _drivesName.Add(drive.Trim()); } // It checks if the game is executed on Mac OS X. } else if (Application.platform == RuntimePlatform.OSXPlayer || Application.platform == RuntimePlatform.OSXEditor) { // Drives as subdirectories of "/Volumes" are wanted. DirectoryFinder finder = new DirectoryFinder("/Volumes".Trim()); finder.Find(); // It gets the directories found. foreach (string path in finder.FoldersPathFound) _drivesPath.Add(path); foreach (string name in finder.FoldersNameFound) _drivesName.Add(name); // It checks if the game is executed on Linux. } else if (Application.platform == RuntimePlatform.LinuxPlayer) { /* // It gets all the Linux drives. DriveInfo[] allDrives = DriveInfo.GetDrives(); // The array is traversed on search of the necessary. foreach (DriveInfo drive in allDrives) { // It checks that can work with the drive. if (drive.IsReady) { // It checks that the drive is not a CDRom or // other inadvisable drive kind. if (drive.DriveType == DriveType.Fixed || drive.DriveType == DriveType.Removable) { _drivesPath.Add(drive.Name.Trim()); // drive.RootDirectory.FullName.Trim()); _drivesName.Add(drive.Name.Trim()); } } } */ // Drives as subdirectories of "/media" are wanted. DirectoryFinder finder = new DirectoryFinder("/media".Trim()); finder.Find(); // It gets the directories found. foreach (string path in finder.FoldersPathFound) _drivesPath.Add(path); foreach (string name in finder.FoldersNameFound) _drivesName.Add(name); } else { // It launch when the platform is not supported. Debug.LogWarning("LogicalVolume: This platform is not supported."); } }
/// <summary> /// This coroutine looking the subdirectories of the path specified, /// and create the ItemF0 prefabs. /// </summary> /// <returns>Directory.</returns> private IEnumerator SearchDirectory() { yield return(0); // All buttons are disabled, to avoid errors that the player could do. BackButton.GetComponent <UIButton>().isEnabled = false; OpenButton.GetComponent <UIButton>().isEnabled = false; ActionButton.GetComponent <UIButton>().isEnabled = false; // All the ItemF0 prefabs are deleted, if there are. foreach (Transform child in transform) { Destroy(child.gameObject); } // If there are no children, then are created. if (transform.childCount == 0) { // It repositions the UIGrid content to that the ItemF0 elements // are in the order with their respective space. GetComponent <UIGrid>().repositionNow = true; GetComponent <UIGrid>().Reposition(); // Was added from the 3.5.0 version of NGUI. ScrollView.UpdateScrollbars(true); // Was added from the 3.5.0 version of NGUI. // It looking the subdirectories and files. DirectoryFinder finder = new DirectoryFinder(PathToSearch.Trim()); finder.FindFiles = FindFiles; finder.Find(); // If it found, albeit a folder, are created. if (finder.FoldersPathFound.Length > 0) { // The array is traversed and create the UI. for (int i = 0; i < finder.FoldersPathFound.Length; i++) { GameObject newItemFolder = (GameObject)Instantiate(ItemF, new Vector3(0, 0, 0), Quaternion.identity); // To drag the elements. newItemFolder.GetComponent <UIDragScrollView>().scrollView = ScrollView; // Sets the new Item Folder settings. newItemFolder.GetComponent <UIItemF>().ItemSelected = ItemSelected; newItemFolder.GetComponent <UIItemF>().OpenButton = OpenButton.GetComponent <UIDirectoryFinderButton>(); newItemFolder.GetComponent <UIItemF>().ActionButton = ActionButton.GetComponent <UIDirectoryFinderButton>(); newItemFolder.GetComponent <UIItemF>().ItemPath = finder.FoldersPathFound[i].Trim(); newItemFolder.GetComponent <UIItemF>().ItemName = finder.FoldersNameFound[i].Trim(); newItemFolder.GetComponent <UIItemF>().KindOf = true; newItemFolder.name = "ItemF" + i; newItemFolder.transform.parent = transform; newItemFolder.transform.localScale = new Vector3(1, 1, 1); newItemFolder.SetActive(true); } } // If it found, albeit a files, are created. if (finder.FilesPathFound.Length > 0) { // The array is traversed and create the UI. for (int i = 0; i < finder.FilesPathFound.Length; i++) { GameObject newItemFile = (GameObject)Instantiate(ItemF, new Vector3(0, 0, 0), Quaternion.identity); // To frag the elements. newItemFile.GetComponent <UIDragScrollView>().scrollView = ScrollView; // Sets the new Item File settings. newItemFile.GetComponent <UIItemF>().ItemSelected = ItemSelected; newItemFile.GetComponent <UIItemF>().OpenButton = OpenButton.GetComponent <UIDirectoryFinderButton>(); newItemFile.GetComponent <UIItemF>().ActionButton = ActionButton.GetComponent <UIDirectoryFinderButton>(); newItemFile.GetComponent <UIItemF>().ItemPath = finder.FilesPathFound[i].Trim(); newItemFile.GetComponent <UIItemF>().ItemName = finder.FilesNameFound[i].Trim(); newItemFile.GetComponent <UIItemF>().KindOf = false; newItemFile.name = "ItemF" + (i + finder.FoldersPathFound.Length); newItemFile.transform.parent = transform; newItemFile.transform.localScale = new Vector3(1, 1, 1); newItemFile.SetActive(true); } } // Was added from the 3.5.0 version of NGUI. // Locates the new list in the zero position. if (ScrollView.gameObject.GetComponent <SpringPanel>()) { ScrollView.gameObject.GetComponent <SpringPanel>().StopAllCoroutines(); ScrollView.gameObject.GetComponent <SpringPanel>().target = Vector3.zero; ScrollView.gameObject.GetComponent <SpringPanel>().enabled = true; } else { // Was added from the 3.5.9 version of NGUI. ScrollView.gameObject.AddComponent <SpringPanel>(); ScrollView.gameObject.GetComponent <SpringPanel>().target = Vector3.zero; } // It repositions the UIGrid content to that the ItemF0 elements // are in the order with their respective space. GetComponent <UIGrid>().repositionNow = true; GetComponent <UIGrid>().Reposition(); // Was added from the 3.5.0 version of NGUI. ScrollView.UpdateScrollbars(true); // Was added from the 3.5.0 version of NGUI. // It verifies if is possible assign a path of keyboard or game control to the items. if (transform.childCount > 0) { // It gets the UIButtonKeys componet of the children. // Compatibility with NGUI 3.5.4 of higher //UIKeyNavigation[] items = gameObject.GetComponentsInChildren<UIKeyNavigation>(); Drive.GetComponent <UIKeyNavigation>().onDown = transform.GetChild(0).gameObject; BackButton.GetComponent <UIKeyNavigation>().onUp = transform.GetChild(transform.childCount - 1).gameObject; OpenButton.GetComponent <UIKeyNavigation>().onUp = transform.GetChild(transform.childCount - 1).gameObject; ActionButton.GetComponent <UIKeyNavigation>().onUp = transform.GetChild(transform.childCount - 1).gameObject; BackButton.GetComponent <UIKeyNavigation>().onDown = Drive; OpenButton.GetComponent <UIKeyNavigation>().onDown = Drive; ActionButton.GetComponent <UIKeyNavigation>().onDown = Drive; for (int i = 0; i < transform.childCount; i++) { if (i == 0) { transform.GetChild(i).GetComponent <UIKeyNavigation>().onUp = Drive; transform.GetChild(i).GetComponent <UIKeyNavigation>().onDown = (transform.childCount == 1) ? BackButton : transform.GetChild(i + 1).gameObject; transform.GetChild(i).GetComponent <UIKeyNavigation>().onClick = OpenButton; } else if (i < transform.childCount - 1) { transform.GetChild(i).GetComponent <UIKeyNavigation>().onUp = transform.GetChild(i - 1).gameObject; transform.GetChild(i).GetComponent <UIKeyNavigation>().onDown = transform.GetChild(i + 1).gameObject; transform.GetChild(i).GetComponent <UIKeyNavigation>().onClick = OpenButton; } else { transform.GetChild(i).GetComponent <UIKeyNavigation>().onUp = transform.GetChild(i - 1).gameObject; transform.GetChild(i).GetComponent <UIKeyNavigation>().onDown = BackButton; transform.GetChild(i).GetComponent <UIKeyNavigation>().onClick = OpenButton; } } } else // or else, then, it browses between buttons. // Compatibility with NGUI 3.5.4 of higher { Drive.GetComponent <UIKeyNavigation>().onDown = BackButton; BackButton.GetComponent <UIKeyNavigation>().onUp = Drive; OpenButton.GetComponent <UIKeyNavigation>().onUp = Drive; ActionButton.GetComponent <UIKeyNavigation>().onUp = Drive; BackButton.GetComponent <UIKeyNavigation>().onDown = Drive; OpenButton.GetComponent <UIKeyNavigation>().onDown = Drive; ActionButton.GetComponent <UIKeyNavigation>().onDown = Drive; } // Compatibility with NGUI 3.5.4 of higher Drive.GetComponent <UIKeyNavigation>().onUp = BackButton; BackButton.GetComponent <UIKeyNavigation>().onLeft = ActionButton; BackButton.GetComponent <UIKeyNavigation>().onRight = OpenButton; OpenButton.GetComponent <UIKeyNavigation>().onLeft = BackButton; OpenButton.GetComponent <UIKeyNavigation>().onRight = ActionButton; ActionButton.GetComponent <UIKeyNavigation>().onLeft = OpenButton; ActionButton.GetComponent <UIKeyNavigation>().onRight = BackButton; // It show the current path. PathLabel.gameObject.SetActive(ShowPath); if (ShowPath) { PathLabel.text = PathToSearch.Trim(); } // It asks for to the Back Button that save this path. BackButton.GetComponent <UIDirectoryFinderButton>().PathToSearch = PathToSearch.Trim(); // The buttons are enabled. BackButton.GetComponent <UIButton>().isEnabled = true; OpenButton.GetComponent <UIButton>().isEnabled = true; ActionButton.GetComponent <UIButton>().isEnabled = true; } else { // It stops the coroutine, and it runs again, // this is for the delay of the GameObjects destruction. StopCoroutine("SearchDirectory"); StartCoroutine("SearchDirectory"); } }
static WrapperTests() { instance = new Wrapper("WrapperTests", DirectoryFinder.Find("WrapperTests"), 4); instance.Start(DateTime.Now, TestDbBuilder.CreateTable); }