Exemple #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);
                }
            }
        }
        /// <summary>
        /// Updates the state of the instance from the specified value.
        /// </summary>
        /// <param name="other">The other value to use to update the instance's state.</param>
        internal void Update(ISqlLocalDbVersionInfo other)
        {
            if (other == null || ReferenceEquals(other, this))
            {
                return;
            }

            Exists  = other.Exists;
            Name    = other.Name;
            Version = other.Version;
        }
Exemple #3
0
        /// <summary>
        /// Returns information about the installed SQL Server LocalDB version(s).
        /// </summary>
        /// <returns>
        /// An <see cref="IList&lt;ISqlLocalDbVersionInfo&gt;"/> containing information
        /// about the SQL Server LocalDB version(s) installed on the current machine.
        /// </returns>
        public virtual IList <ISqlLocalDbVersionInfo> GetVersions()
        {
            IList <string> versionNames = _localDB.Versions;

            List <ISqlLocalDbVersionInfo> versions = new List <ISqlLocalDbVersionInfo>();

            if (versionNames != null)
            {
                foreach (string version in versionNames)
                {
                    ISqlLocalDbVersionInfo info = _localDB.GetVersionInfo(version);
                    versions.Add(info);
                }
            }

            return(versions);
        }
        public static void Update_Does_Not_Copy_State_If_Other_Is_Null()
        {
            // Arrange
            ISqlLocalDbVersionInfo other = null;

            var actual = new SqlLocalDbVersionInfo()
            {
                Exists  = false,
                Name    = "Name",
                Version = new Version(2, 0),
            };

            // Act
            actual.Update(other);

            // Assert
            actual.Exists.ShouldBeFalse();
            actual.Name.ShouldBe("Name");
            actual.Version.ShouldBe(new Version(2, 0));
        }
Exemple #5
0
        /// <summary>
        /// Returns information about the installed SQL Server LocalDB version(s).
        /// </summary>
        /// <param name="api">The <see cref="ISqlLocalDbApi"/> to use to enumerate the installed versions.</param>
        /// <returns>
        /// An <see cref="IReadOnlyList{ISqlLocalDbVersionInfo}"/> containing information
        /// about the SQL Server LocalDB version(s) installed on the current machine.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="api"/> is <see langword="null"/>.
        /// </exception>
        public static IReadOnlyList <ISqlLocalDbVersionInfo> GetVersions(this ISqlLocalDbApi api)
        {
            if (api == null)
            {
                throw new ArgumentNullException(nameof(api));
            }

            IReadOnlyList <string> versionNames = api.Versions;
            var versions = new List <ISqlLocalDbVersionInfo>(versionNames?.Count ?? 0);

            if (versionNames != null)
            {
                foreach (string version in versionNames)
                {
                    ISqlLocalDbVersionInfo info = api.GetVersionInfo(version);
                    versions.Add(info);
                }
            }

            return(versions);
        }