Ejemplo n.º 1
0
        public void Can_Create_SqlLocalDB_Instances_With_Different_Versions()
        {
            // Arrange
            using (var actual = new SqlLocalDbApi(_loggerFactory))
            {
                foreach (string version in actual.Versions)
                {
                    // Act
                    ISqlLocalDbVersionInfo versionInfo = actual.GetVersionInfo(version);

                    // Assert
                    versionInfo.ShouldNotBeNull();
                    versionInfo.Name.ShouldStartWith(version.Split('.').First());
                    versionInfo.Exists.ShouldBeTrue();
                    versionInfo.Version.ShouldNotBeNull();
                    versionInfo.Version.ShouldNotBe(new Version());

                    string instanceName = Guid.NewGuid().ToString();

                    // Act
                    ISqlLocalDbInstanceInfo instanceInfo = actual.CreateInstance(instanceName, version);

                    // Assert
                    instanceInfo.ShouldNotBeNull();
                    instanceInfo.Name.ShouldBe(instanceName);
                    instanceInfo.Exists.ShouldBeTrue();
                    instanceInfo.IsRunning.ShouldBeFalse();
                    instanceInfo.LocalDbVersion.ShouldBe(versionInfo.Version);

                    // Act (no Assert)
                    actual.DeleteInstance(instanceName);
                    actual.DeleteInstanceFiles(instanceName);
                }
            }
        }
Ejemplo n.º 2
0
        public static void AssemblyCleanup()
        {
            // Get the names of all the SQL LocalDB instance folders that existed after the tests are run
            string[] instanceNames = GetInstanceNames();

            // Filter the list down to just the names of the instances that were created in the test run
            string[] createdInstanceNames = instanceNames
                                            .Except(InstanceNames)
                                            .ToArray();

            // Try and delete all the leftover file(s) from the test run
            foreach (string instanceName in createdInstanceNames)
            {
                SqlLocalDbApi.DeleteInstanceFiles(instanceName);
            }
        }
Ejemplo n.º 3
0
        public void Can_Manage_SqlLocalDB_Instances()
        {
            // Arrange
            using (var actual = new SqlLocalDbApi(_loggerFactory))
            {
                string instanceName = Guid.NewGuid().ToString();

                // Act
                ISqlLocalDbInstanceInfo instance = actual.GetInstanceInfo(instanceName);

                // Assert
                instance.ShouldNotBeNull();
                instance.Name.ShouldBe(instanceName);
                instance.Exists.ShouldBeFalse();
                instance.IsRunning.ShouldBeFalse();

                // Act and Assert
                actual.InstanceExists(instanceName).ShouldBeFalse();

                // Act
                actual.CreateInstance(instanceName);

                // Assert
                instance = actual.GetInstanceInfo(instanceName);
                instance.ShouldNotBeNull();
                instance.Name.ShouldBe(instanceName);
                instance.Exists.ShouldBeTrue();
                instance.IsRunning.ShouldBeFalse();

                // Act
                actual.StartInstance(instanceName);

                // Assert
                instance = actual.GetInstanceInfo(instanceName);
                instance.ShouldNotBeNull();
                instance.Name.ShouldBe(instanceName);
                instance.Exists.ShouldBeTrue();
                instance.IsRunning.ShouldBeTrue();

                // Act and Assert
                actual.InstanceExists(instanceName).ShouldBeTrue();

                // Act
                actual.StopInstance(instanceName);

                // Assert
                instance = actual.GetInstanceInfo(instanceName);
                instance.ShouldNotBeNull();
                instance.Name.ShouldBe(instanceName);
                instance.Exists.ShouldBeTrue();
                instance.IsRunning.ShouldBeFalse();

                // Act
                actual.DeleteInstance(instanceName);

                // Assert
                instance = actual.GetInstanceInfo(instanceName);
                instance.ShouldNotBeNull();
                instance.Name.ShouldBe(instanceName);
                instance.Exists.ShouldBeFalse();
                instance.IsRunning.ShouldBeFalse();

                // Act and Assert
                actual.InstanceExists(instanceName).ShouldBeFalse();

                // Act (no Assert)
                actual.DeleteInstanceFiles(instanceName);
            }
        }
Ejemplo n.º 4
0
        public async Task Can_Manage_SqlLocalDB_Instances()
        {
            // Arrange
            using (var actual = new SqlLocalDbApi(_loggerFactory))
            {
                string instanceName = Guid.NewGuid().ToString();

                // Act
                ISqlLocalDbInstanceInfo instance = actual.GetInstanceInfo(instanceName);

                // Assert
                instance.ShouldNotBeNull();
                instance.Name.ShouldBe(instanceName);
                instance.Exists.ShouldBeFalse();
                instance.IsRunning.ShouldBeFalse();

                // Act and Assert
                actual.InstanceExists(instanceName).ShouldBeFalse();

                // Act
                instance = actual.CreateInstance(instanceName);

                // Assert
                instance = actual.GetInstanceInfo(instanceName);
                instance.ShouldNotBeNull();
                instance.Name.ShouldBe(instanceName);
                instance.Exists.ShouldBeTrue();
                instance.IsRunning.ShouldBeFalse();

                // Act
                string namedPipe = actual.StartInstance(instanceName);

                // Assert
                namedPipe.ShouldNotBeNullOrWhiteSpace();

                var builder = new SqlConnectionStringBuilder()
                {
                    DataSource = namedPipe
                };

                using (var connection = new SqlConnection(builder.ConnectionString))
                {
                    await connection.OpenAsync();
                }

                // Act
                instance = actual.GetInstanceInfo(instanceName);

                // Assert
                instance.ShouldNotBeNull();
                instance.Name.ShouldBe(instanceName);
                instance.Exists.ShouldBeTrue();
                instance.IsRunning.ShouldBeTrue();

                // Act and Assert
                actual.InstanceExists(instanceName).ShouldBeTrue();

                // Act
                actual.StopInstance(instanceName);

                // Assert
                instance = actual.GetInstanceInfo(instanceName);
                instance.ShouldNotBeNull();
                instance.Name.ShouldBe(instanceName);
                instance.Exists.ShouldBeTrue();
                instance.IsRunning.ShouldBeFalse();

                // Act
                actual.DeleteInstance(instanceName);

                // Assert
                instance = actual.GetInstanceInfo(instanceName);
                instance.ShouldNotBeNull();
                instance.Name.ShouldBe(instanceName);
                instance.Exists.ShouldBeFalse();
                instance.IsRunning.ShouldBeFalse();

                // Act and Assert
                actual.InstanceExists(instanceName).ShouldBeFalse();

                // Act (no Assert)
                actual.DeleteInstanceFiles(instanceName);
            }
        }