public void NetworkDisconnectDialogTest() { var ncd = new NetworkDisconnectDialog { LocalDeviceName = "S:", ForceDisconnect = true, UpdateProfile = true }; Assert.That(ncd.ShowDialog(), Is.EqualTo(DialogResult.OK)); Assert.That(MessageBox.Show("Confirm local, force and update", "NetworkDisconnectDialog Confirm", MessageBoxButtons.YesNo) == DialogResult.Yes); ncd.Reset(); Assert.That(ncd.ForceDisconnect, Is.False); Assert.That(ncd.LocalDeviceName, Is.Null); ncd.RemoteNetworkName = @"\\HALLAN-SVR\share"; Assert.That(() => ncd.UpdateProfile = true, Throws.InvalidOperationException); Assert.That(ncd.ShowDialog(), Is.EqualTo(DialogResult.OK)); Assert.That(MessageBox.Show("Confirm remote.", "NetworkDisconnectDialog Confirm", MessageBoxButtons.YesNo) == DialogResult.Yes); }
public void NetworkDisconnectDialogTest() { const string drive = "S:"; Vanara.PInvoke.Mpr.WNetAddConnection2(new PInvoke.Mpr.NETRESOURCE(remoteName, drive), null, null, PInvoke.Mpr.CONNECT.CONNECT_TEMPORARY | PInvoke.Mpr.CONNECT.CONNECT_UPDATE_RECENT); var ncd = new NetworkDisconnectDialog { LocalDeviceName = drive, RemoteNetworkName = remoteName, ForceDisconnect = false, UpdateProfile = true }; Assert.That(ncd.ShowDialog(), Is.EqualTo(DialogResult.OK).Or.EqualTo(DialogResult.Cancel)); Assert.That(MessageBox.Show("Confirm local, force and update", "NetworkDisconnectDialog Confirm", MessageBoxButtons.YesNo) == DialogResult.Yes); ncd.Reset(); Assert.That(ncd.ForceDisconnect, Is.True); Assert.That(ncd.LocalDeviceName, Is.Null); Vanara.PInvoke.Mpr.WNetAddConnection2(new PInvoke.Mpr.NETRESOURCE(remoteName, drive), null, null, PInvoke.Mpr.CONNECT.CONNECT_TEMPORARY | PInvoke.Mpr.CONNECT.CONNECT_UPDATE_RECENT); Assert.That(() => ncd.UpdateProfile = true, Throws.InvalidOperationException); ncd.LocalDeviceName = drive; Assert.That(ncd.ShowDialog(), Is.EqualTo(DialogResult.OK).Or.EqualTo(DialogResult.Cancel)); Assert.That(MessageBox.Show("Confirm remote.", "NetworkDisconnectDialog Confirm", MessageBoxButtons.YesNo) == DialogResult.Yes); }