public void BuildsTheStructureWithTheStoredCredentialsWithNullCredentials() { var entryName = "Test"; var phoneBookPath = @"C:\Test.pbk"; var api = new Mock <IRasApi32>(); api.Setup(o => o.RasGetEntryDialParams(phoneBookPath, ref It.Ref <RASDIALPARAMS> .IsAny, out It.Ref <bool> .IsAny)).Returns(new RasGetEntryDialParamsCallback( (string o1, ref RASDIALPARAMS o2, out bool o3) => { o2.szUserName = "******"; o2.szPassword = "******"; o2.szDomain = "Domain"; o3 = true; return(SUCCESS); })); var structFactory = new Mock <IStructFactory>(); var exceptionPolicy = new Mock <IExceptionPolicy>(); var context = new RasDialContext { EntryName = entryName, PhoneBookPath = phoneBookPath, Credentials = null }; var target = new RasDialParamsBuilder(api.Object, structFactory.Object, exceptionPolicy.Object); var result = target.Build(context); Assert.AreEqual("User", result.szUserName); Assert.AreEqual("Password", result.szPassword); Assert.AreEqual("Domain", result.szDomain); }
public void OverwritesTheStoredCredentialsWhenCredentialsAreSupplied() { var entryName = "Test"; var phoneBookPath = @"C:\Test.pbk"; api.Setup(o => o.RasGetEntryDialParams(phoneBookPath, ref It.Ref <RASDIALPARAMS> .IsAny, out It.Ref <bool> .IsAny)).Returns(new RasGetEntryDialParamsCallback( (string o1, ref RASDIALPARAMS o2, out bool o3) => { o2.szUserName = "******"; o2.szPassword = "******"; o2.szDomain = "Domain1"; o3 = true; return(SUCCESS); })); var context = new RasDialContext { EntryName = entryName, PhoneBookPath = phoneBookPath, Credentials = new NetworkCredential("User2", "Password2", "Domain2") }; var target = new RasDialParamsBuilder(api.Object, structFactory.Object, exceptionPolicy.Object); var result = target.Build(context); Assert.AreEqual("User2", result.szUserName); Assert.AreEqual("Password2", result.szPassword); Assert.AreEqual("Domain2", result.szDomain); }
public void BuildsTheStructureWithTheEntryName() { var context = new RasDialContext { EntryName = "Test" }; var target = new RasDialParamsBuilder(api.Object, structFactory.Object, exceptionPolicy.Object); var result = target.Build(context); Assert.AreEqual("Test", result.szEntryName); }
public void BuildsTheStructureWithTheUserNameAndPassword() { var context = new RasDialContext { Credentials = new NetworkCredential("User", "Pass") }; var target = new RasDialParamsBuilder(api.Object, structFactory.Object, exceptionPolicy.Object); var result = target.Build(context); Assert.AreEqual("User", result.szUserName); Assert.AreEqual("Pass", result.szPassword); }
public void BuildsTheStructureWithTheInterfaceIndex() { var context = new RasDialContext { Options = new RasDialerOptions { InterfaceIndex = 1 } }; var target = new RasDialParamsBuilder(api.Object, structFactory.Object, exceptionPolicy.Object); var result = target.Build(context); Assert.AreEqual(1, result.dwIfIndex); }
public void ThrowsAnExceptionWhenTheApiResultIsNonZero() { var entryName = "Test"; var phoneBookPath = @"C:\Test.pbk"; api.Setup(o => o.RasGetEntryDialParams(phoneBookPath, ref It.Ref <RASDIALPARAMS> .IsAny, out It.Ref <bool> .IsAny)).Returns(ERROR_INSUFFICIENT_BUFFER); exceptionPolicy.Setup(o => o.Create(ERROR_INSUFFICIENT_BUFFER)).Returns(new TestException()); var target = new RasDialParamsBuilder(api.Object, structFactory.Object, exceptionPolicy.Object); Assert.Throws <TestException>(() => target.Build(new RasDialContext { EntryName = entryName, PhoneBookPath = phoneBookPath })); }
public void BuildsTheStructureWithTheUserNamePasswordAndDomain() { var api = new Mock <IRasApi32>(); var structFactory = new Mock <IStructFactory>(); var exceptionPolicy = new Mock <IExceptionPolicy>(); var context = new RasDialContext { Credentials = new NetworkCredential("User", "Pass", "Domain") }; var target = new RasDialParamsBuilder(api.Object, structFactory.Object, exceptionPolicy.Object); var result = target.Build(context); Assert.AreEqual("User", result.szUserName); Assert.AreEqual("Pass", result.szPassword); Assert.AreEqual("Domain", result.szDomain); }
public void ThrowsAnExceptionWhenContextIsNull() { var target = new RasDialParamsBuilder(api.Object, structFactory.Object, exceptionPolicy.Object); Assert.Throws <ArgumentNullException>(() => target.Build(null)); }