public void ReturnsTheNetworkCredentialAsExpected()
        {
            var api = new Mock <IRasApi32>();

            api.Setup(o => o.RasGetCredentials("PATH", "ENTRY", ref It.Ref <RASCREDENTIALS> .IsAny)).Callback(new RasGetCredentialsCallback(
                                                                                                                  (string o1, string o2, ref RASCREDENTIALS o3) =>
            {
                o3.szUserName = "******";
                o3.szPassword = "******";
                o3.szDomain   = "DOMAIN";
            }));

            var structFactory = new Mock <IStructFactory>();

            structFactory.Setup(o => o.Create <RASCREDENTIALS>()).Returns(new RASCREDENTIALS());

            var exceptionPolicy = new Mock <IExceptionPolicy>();

            var target = new RasGetCredentialsService(api.Object, structFactory.Object, exceptionPolicy.Object);
            var result = target.GetNetworkCredential("ENTRY", "PATH");

            Assert.AreEqual("USER", result.UserName);
            Assert.AreEqual("PASSWORD", result.Password);
            Assert.AreEqual("DOMAIN", result.Domain);
        }
        public void DoesNotThrowAnExceptionWhenThePhoneBookPathIsNull()
        {
            var api             = new Mock <IRasApi32>();
            var structFactory   = new Mock <IStructFactory>();
            var exceptionPolicy = new Mock <IExceptionPolicy>();

            var target = new RasGetCredentialsService(api.Object, structFactory.Object, exceptionPolicy.Object);

            Assert.DoesNotThrow(() => target.GetNetworkCredential("ENTRY", null));
        }
        public void ThrowsAnExceptionWhenTheEntryNameIsNull()
        {
            var api             = new Mock <IRasApi32>();
            var structFactory   = new Mock <IStructFactory>();
            var exceptionPolicy = new Mock <IExceptionPolicy>();

            var target = new RasGetCredentialsService(api.Object, structFactory.Object, exceptionPolicy.Object);

            Assert.Throws <ArgumentNullException>(() => target.GetNetworkCredential(null, "PATH"));
        }
        public void ThrowsAnExceptionForANonZeroResultCode()
        {
            var api = new Mock <IRasApi32>();

            api.Setup(o => o.RasGetCredentials("PATH", "ENTRY", ref It.Ref <RASCREDENTIALS> .IsAny)).Returns(-1);

            var structFactory = new Mock <IStructFactory>();

            structFactory.Setup(o => o.Create <RASCREDENTIALS>()).Returns(new RASCREDENTIALS());

            var exceptionPolicy = new Mock <IExceptionPolicy>();

            exceptionPolicy.Setup(o => o.Create(-1)).Returns(new TestException());

            var target = new RasGetCredentialsService(api.Object, structFactory.Object, exceptionPolicy.Object);

            Assert.Throws <TestException>(() => target.GetNetworkCredential("ENTRY", "PATH"));
        }