Ejemplo n.º 1
0
        public void ShareInstance_Throws_If_Api_Is_Null()
        {
            // Arrange
            ISqlLocalDbApi api                = null;
            string         instanceName       = "SomeName";
            string         sharedInstanceName = "SomeSharedName";

            // Act and Assert
            Assert.Throws <ArgumentNullException>("api", () => api.ShareInstance(instanceName, sharedInstanceName));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Shares the specified SQL Server LocalDB instance with other users of the computer,
        /// using the specified shared name for the current Windows user.
        /// </summary>
        /// <param name="api">The <see cref="ISqlLocalDbApi"/> to use to share the instance.</param>
        /// <param name="instanceName">The private name for the LocalDB instance to share.</param>
        /// <param name="sharedInstanceName">The shared name for the LocalDB instance to share.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="api"/>, <paramref name="instanceName"/> or <paramref name="sharedInstanceName"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="PlatformNotSupportedException">
        /// The method is called from a non-Windows operating system.
        /// </exception>
        public static void ShareInstance(this ISqlLocalDbApi api, string instanceName, string sharedInstanceName)
        {
            if (api == null)
            {
                throw new ArgumentNullException(nameof(api));
            }

            SqlLocalDbApi.EnsurePlatformSupported();

            string ownerSid;

            using (var identity = WindowsIdentity.GetCurrent())
            {
                ownerSid = identity.User.Value;
            }

            api.ShareInstance(ownerSid, instanceName, sharedInstanceName);
        }
        public static void ShareInstance_Uses_SID_For_Current_User()
        {
            // Arrange
            string instanceName       = "SomeName";
            string sharedInstanceName = "SomeSharedName";

            var mock = new Mock <ISqlLocalDbApi>();

            mock.Setup((p) => p.ShareInstance(It.IsNotNull <string>(), instanceName, sharedInstanceName))
            .Verifiable();

            ISqlLocalDbApi api = mock.Object;

            // Act
            api.ShareInstance(instanceName, sharedInstanceName);

            // Assert
            mock.Verify();
        }