예제 #1
0
            public async void ReturnsFalseWhenCfCidFails([Frozen] ITmNative native, TmsApi tms)
            {
                A.CallTo(() => native.TmcGetCfsHandle(A <int> ._))
                .Returns(IntPtr.Zero);

                var result = await tms.DownloadFile(A.Dummy <string>(), A.Dummy <string>());

                result.Should().BeFalse();
            }
예제 #2
0
            public async void ReturnsNullWhenCfCidFails([Frozen] ITmNative native, TmsApi tms)
            {
                A.CallTo(() => native.TmcGetCfsHandle(A <int> ._))
                .Returns(IntPtr.Zero);

                var result = await tms.GetFilesInDirectory(A.Dummy <string>());

                result.Should().BeNull();
            }
예제 #3
0
            public async void ReturnsFalseWhenNoFileFound([Frozen] ITmNative native, TmsApi tms)
            {
                uint error;
                var  errorBuf = new byte[80];

                A.CallTo(() => native.TmcGetCfsHandle(A <int> ._))
                .Returns(new IntPtr(1));
                A.CallTo(() => native.CfsFileGet(new IntPtr(1), "", "", 0, IntPtr.Zero, out error, ref errorBuf, 0))
                .WithAnyArguments()
                .Returns(true);

                var result = await tms.DownloadFile(A.Dummy <string>(), A.Dummy <string>());

                result.Should().BeFalse();
            }
예제 #4
0
            public async void ReturnsNullWhenWhenTmconnReturnsFalse([Frozen] ITmNative native, TmsApi tms)
            {
                uint error;
                var  errorBuf  = new byte[80];
                uint bufLength = 80;
                var  buf       = new char[bufLength];

                A.CallTo(() => native.TmcGetCfsHandle(A <int> ._))
                .Returns(new IntPtr(1));
                A.CallTo(() => native.CfsDirEnum(new IntPtr(1), "", ref buf, bufLength, out error, ref errorBuf, 0))
                .WithAnyArguments()
                .Returns(false);

                var result = await tms.GetFilesInDirectory(A.Dummy <string>());

                result.Should().BeNull();
            }
예제 #5
0
        public static TmUserInfo GetUserInfo(int tmCid,
                                             string serverName)
        {
            var nativeUserInfoSize = Marshal.SizeOf(typeof(TmNativeDefs.TExtendedUserInfo));
            var nativeUserInfoPtr  = Marshal.AllocHGlobal(nativeUserInfoSize);

            var cfCid = Native.TmcGetCfsHandle(tmCid);

            if (cfCid == IntPtr.Zero)
            {
                return(null);
            }

            var fetchResult = Native.CfsGetExtendedUserData(cfCid,
                                                            "tms$",
                                                            serverName,
                                                            nativeUserInfoPtr,
                                                            (uint)nativeUserInfoSize);

            if (fetchResult == 0)
            {
                return(null);
            }

            var extendedUserInfo = Marshal.PtrToStructure <TmNativeDefs.TExtendedUserInfo>(nativeUserInfoPtr);

            var userInfo = new TmNativeDefs.TUserInfo();

            if (!Native.TmcGetUserInfo(tmCid, 0, ref userInfo))
            {
                return(null);
            }

            return(new TmUserInfo(extendedUserInfo.UserId,
                                  Encoding.GetEncoding(1251).GetString(extendedUserInfo.UserName).Trim('\0'),
                                  Encoding.GetEncoding(1251).GetString(userInfo.UserCategory).Trim('\0'),
                                  Encoding.GetEncoding(1251).GetString(extendedUserInfo.KeyId).Trim('\0'),
                                  extendedUserInfo.Group,
                                  extendedUserInfo.Rights));
        }
예제 #6
0
            public async void ReturnsCorrectList([Frozen] ITmNative native, TmsApi tms)
            {
                uint error;
                var  errorBuf  = new byte[80];
                uint bufLength = 80;
                var  buf       = new char[bufLength];

                A.CallTo(() => native.TmcGetCfsHandle(A <int> ._))
                .Returns(new IntPtr(1));
                A.CallTo(() => native.CfsDirEnum(new IntPtr(1), "", ref buf, bufLength, out error, ref errorBuf, 0))
                .WithAnyArguments()
                .Returns(true)
                .AssignsOutAndRefParameters(new[]
                {
                    'I', 't', 'e', 'm', '1', '\0',
                    'I', 't', 'e', 'm', '2', '\0', '\0',
                    'T', 'r', 'a', 's', 'h'
                }, A.Dummy <uint>(), A.Dummy <byte[]>());

                var result = await tms.GetFilesInDirectory(A.Dummy <string>());

                result.Should().Equal("Item1", "Item2");
            }