public void ShareInstance_Shares_Instance_For_Current_User()
        {
            // Arrange
            using var api = new SqlLocalDbApi(_loggerFactory);
            using TemporarySqlLocalDbInstance target = api.CreateTemporaryInstance(deleteFiles: true);

            target.GetInstanceInfo().IsShared.ShouldBeFalse();

            // Act
            api.ShareInstance(target.Name, Guid.NewGuid().ToString());

            // Assert
            target.GetInstanceInfo().IsShared.ShouldBeTrue();
        }
        public void TemporaryInstance_Ignores_Exception_If_Stop_Fails(int errorCode)
        {
            // Arrange
            var mock = new Mock <ISqlLocalDbApi>();

            mock.Setup((p) => p.LatestVersion)
            .Returns("v99.9");

            mock.Setup((p) => p.CreateInstance(It.IsAny <string>(), "v99.9"))
            .Verifiable();

            mock.Setup((p) => p.StartInstance(It.IsAny <string>()))
            .Verifiable();

            mock.Setup((p) => p.StopInstance(It.IsAny <string>(), null))
            .Throws(new SqlLocalDbException("Error", errorCode))
            .Verifiable();

            mock.Setup((p) => p.DeleteInstance(It.IsAny <string>()))
            .Verifiable();

            ISqlLocalDbApi api = mock.Object;

            // Act
            using (TemporarySqlLocalDbInstance target = api.CreateTemporaryInstance())
            {
                target.GetInstanceInfo();
            }

            // Assert
            mock.Verify();
        }
        public void TemporaryInstance_Deletes_Instance_If_Start_Fails()
        {
            // Arrange
            var mock = new Mock <ISqlLocalDbApi>();

            mock.Setup((p) => p.LatestVersion)
            .Returns("v99.9");

            mock.Setup((p) => p.CreateInstance(It.IsAny <string>(), "v99.9"))
            .Verifiable();

            mock.Setup((p) => p.StartInstance(It.IsAny <string>()))
            .Throws <PlatformNotSupportedException>();

            mock.Setup((p) => p.DeleteInstance(It.IsAny <string>()))
            .Verifiable();

            ISqlLocalDbApi api = mock.Object;

            using (TemporarySqlLocalDbInstance target = api.CreateTemporaryInstance())
            {
                // Act and Assert
                Assert.Throws <PlatformNotSupportedException>(() => target.GetInstanceInfo());
            }

            mock.Verify();
        }
Пример #4
0
        public void Restart_Stops_And_Starts_Instance()
        {
            // Arrange
            using var api = new SqlLocalDbApi(_loggerFactory);
            using TemporarySqlLocalDbInstance temporary = api.CreateTemporaryInstance(deleteFiles: true);

            ISqlLocalDbInstanceManager manager = temporary.Manage();

            // Act
            manager.Restart();

            // Assert
            temporary.GetInstanceInfo().IsRunning.ShouldBeTrue();
        }
        public void TemporaryInstance_Throws_If_Used_After_Disposal()
        {
            // Arrange
            var api = Mock.Of <ISqlLocalDbApi>();

            TemporarySqlLocalDbInstance instance = api.CreateTemporaryInstance();

            // Act
            instance.Dispose();

            // Assert
            Assert.Throws <ObjectDisposedException>(() => instance.Name);
            Assert.Throws <ObjectDisposedException>(() => instance.GetInstanceInfo());
        }
Пример #6
0
        public void CreateTemporaryInstance_Creates_Starts_And_Deletes_An_Instance(bool deleteFiles)
        {
            // Arrange
            if (!SqlLocalDbApi.IsWindows)
            {
                // HACK Theories dont seem to work correctly with subclasses now
                // so cannot make a derived class for a "Windows-only" theory.
                return;
            }

            using (var api = new SqlLocalDbApi(_loggerFactory))
            {
                ISqlLocalDbInstanceInfo info;
                string name;

                // Act
                using (TemporarySqlLocalDbInstance target = api.CreateTemporaryInstance(deleteFiles))
                {
                    // Assert
                    target.ShouldNotBeNull();
                    target.Name.ShouldNotBeNull();
                    target.Name.ShouldNotBeEmpty();

                    Guid.TryParse(target.Name, out Guid nameAsGuid).ShouldBeTrue();
                    nameAsGuid.ShouldNotBe(Guid.Empty);

                    // Act
                    info = target.GetInstanceInfo();

                    // Assert
                    info.ShouldNotBeNull();
                    info.Exists.ShouldBeTrue();
                    info.IsRunning.ShouldBeTrue();

                    name = target.Name;
                }

                // Act
                info = api.GetInstanceInfo(name);

                // Assert
                info.ShouldNotBeNull();
                info.Exists.ShouldBeFalse();
            }
        }
        public static void TemporaryInstance_Ignores_Exception_If_Delete_Fails(int errorCode)
        {
            // Arrange
            if (!SqlLocalDbApi.IsWindows)
            {
                // HACK Theories dont seem to work correctly with subclasses now
                // so cannot make a derived class for a "Windows-only" theory.
                return;
            }

            // Arrange
            var mock = new Mock <ISqlLocalDbApi>();

            mock.Setup((p) => p.LatestVersion)
            .Returns("v99.9");

            mock.Setup((p) => p.CreateInstance(It.IsAny <string>(), "v99.9"))
            .Verifiable();

            mock.Setup((p) => p.StartInstance(It.IsAny <string>()))
            .Verifiable();

            mock.Setup((p) => p.StopInstance(It.IsAny <string>(), null))
            .Verifiable();

            mock.Setup((p) => p.DeleteInstance(It.IsAny <string>()))
            .Throws(new SqlLocalDbException("Error", errorCode))
            .Verifiable();

            ISqlLocalDbApi api = mock.Object;

            // Act
            using (TemporarySqlLocalDbInstance target = api.CreateTemporaryInstance())
            {
                target.GetInstanceInfo();
            }

            // Assert
            mock.Verify();
        }
        private void CreateTemporaryInstance_Creates_Starts_And_Deletes_An_Instance(bool deleteFiles)
        {
            // Arrange
            using (var api = new SqlLocalDbApi(_loggerFactory))
            {
                ISqlLocalDbInstanceInfo info;
                string name;

                // Act
                using (TemporarySqlLocalDbInstance target = api.CreateTemporaryInstance(deleteFiles))
                {
                    // Assert
                    target.ShouldNotBeNull();
                    target.Name.ShouldNotBeNull();
                    target.Name.ShouldNotBeEmpty();

                    Guid.TryParse(target.Name, out Guid nameAsGuid).ShouldBeTrue();
                    nameAsGuid.ShouldNotBe(Guid.Empty);

                    // Act
                    info = target.GetInstanceInfo();

                    // Assert
                    info.ShouldNotBeNull();
                    info.Exists.ShouldBeTrue();
                    info.IsRunning.ShouldBeTrue();

                    name = target.Name;
                }

                // Act
                info = api.GetInstanceInfo(name);

                // Assert
                info.ShouldNotBeNull();
                info.Exists.ShouldBeFalse();
            }
        }