コード例 #1
0
 public void ThrowAnExceptionWhenTheApiIsNull()
 {
     Assert.Throws <ArgumentNullException>(() =>
     {
         _ = new RasGetErrorStringService(null);
     });
 }
コード例 #2
0
        public void ThrowAWin32ExceptionWhenTheBufferSizeIsTooSmall()
        {
            var api = new Mock <IRasApi32>();

            api.Setup(o => o.RasGetErrorString(1, It.IsAny <StringBuilder>(), It.IsAny <int>())).Returns(ERROR_INSUFFICIENT_BUFFER);

            var target = new RasGetErrorStringService(api.Object);

            Assert.Throws <System.ComponentModel.Win32Exception>(() => target.GetErrorString(1));
        }
コード例 #3
0
        public void MustNotThrowAnExceptionWhenTheErrorCodeIsLessThanZero()
        {
            var api = new Mock <IRasApi32>();

            var target = new RasGetErrorStringService(api.Object);

            Assert.DoesNotThrow(() => target.GetErrorString(-1));

            api.Verify(o => o.RasGetErrorString(It.IsAny <int>(), It.IsAny <StringBuilder>(), It.IsAny <int>()), Times.Once);
        }
コード例 #4
0
        public void ReturnNullWhenTheErrorCodeIsNotValid()
        {
            var api = new Mock <IRasApi32>();

            api.Setup(o => o.RasGetErrorString(87, It.IsAny <StringBuilder>(), It.IsAny <int>())).Returns(ERROR_INVALID_PARAMETER);

            var target = new RasGetErrorStringService(api.Object);
            var result = target.GetErrorString(87);

            Assert.IsNull(result);
        }
コード例 #5
0
        public void ReturnTheErrorString()
        {
            var message = "This is a test message!";

            var api = new Mock <IRasApi32>();

            api.Setup(o => o.RasGetErrorString(1, It.IsAny <StringBuilder>(), It.IsAny <int>()))
            .Callback <int, StringBuilder, int>((o1, o2, o3) => { o2.Append(message); })
            .Returns(SUCCESS);

            var target = new RasGetErrorStringService(api.Object);
            var result = target.GetErrorString(1);

            Assert.AreEqual(message, result);
        }