Esempio n. 1
0
        private AuthProperty PtrToAuthProperty(IntPtr authPropertyPtr)
        {
            var nativeAuthProperty = (NativeAuthProperty)Marshal.PtrToStructure(authPropertyPtr, typeof(NativeAuthProperty));
            var name       = Marshal.PtrToStringAnsi(nativeAuthProperty.Name);
            var valueBytes = new byte[(int)nativeAuthProperty.ValueLength];

            Marshal.Copy(nativeAuthProperty.Value, valueBytes, 0, (int)nativeAuthProperty.ValueLength);
            return(AuthProperty.CreateUnsafe(name, valueBytes));
        }
 private AuthProperty PtrToAuthProperty(IntPtr authPropertyPtr)
 {
     #pragma warning disable 0618
     // We need to use the obsolete non-generic version of Marshal.PtrToStructure, because the generic version is not available in net45
     var nativeAuthProperty = (NativeAuthProperty)Marshal.PtrToStructure(authPropertyPtr, typeof(NativeAuthProperty));
     #pragma warning restore 0618
     var name       = Marshal.PtrToStringAnsi(nativeAuthProperty.Name);
     var valueBytes = new byte[(int)nativeAuthProperty.ValueLength];
     Marshal.Copy(nativeAuthProperty.Value, valueBytes, 0, (int)nativeAuthProperty.ValueLength);
     return(AuthProperty.CreateUnsafe(name, valueBytes));
 }
        public void CreateUnsafe()
        {
            var valueBytes   = new byte[] { 68, 69, 70 };
            var authProperty = AuthProperty.CreateUnsafe("abc", valueBytes);

            Assert.AreEqual("abc", authProperty.Name);
            Assert.AreSame(valueBytes, authProperty.ValueBytesUnsafe);
            Assert.AreNotSame(valueBytes, authProperty.ValueBytes);
            CollectionAssert.AreEqual(valueBytes, authProperty.ValueBytes);
            CollectionAssert.AreEqual(valueBytes, authProperty.ValueBytesUnsafe);
            Assert.AreEqual("DEF", authProperty.Value);
        }
 public void Create_ValueIsNotNull()
 {
     Assert.Throws(typeof(ArgumentNullException), () => AuthProperty.Create("abc", null));
     Assert.Throws(typeof(ArgumentNullException), () => AuthProperty.CreateUnsafe("abc", null));
 }
 public void Create_NameIsNotNull()
 {
     Assert.Throws(typeof(ArgumentNullException), () => AuthProperty.Create(null, new byte[0]));
     Assert.Throws(typeof(ArgumentNullException), () => AuthProperty.CreateUnsafe(null, new byte[0]));
 }