示例#1
0
        public async Task CreateUser_Error()
        {
            //arrange
            var processManager = new TestProcessManager();

            processManager.AddProcess(new[]
            {
                "Error: couldn't create User."
            }, "create-user");

            var adb = new Adb(processManager);

            //act
            try
            {
                await adb.SingleDevice.Shell.PackageManager.CreateUser("Test");

                //assert
                Assert.Fail();
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOf <AdbException>(ex);
            }
        }
示例#2
0
        public async Task GetDevicesAllStates()
        {
            // arrange
            var output = new List <string>
            {
                "List of devices attached",
                "PHILIPS W732\tdevice",
                "0123456789ABCDE\tunauthorized",
                "0123456789ABCDE\toffline"
            };
            var processManager = new TestProcessManager();

            processManager.AddProcess(output);
            var adb = new Adb(processManager);

            // act
            var devices = (await adb.GetDevices()).ToList();

            // assert
            processManager.Stub.AssertWasCalled(_ => _.CreateProcess(Arg <string> .Is.Anything, Arg <string> .Matches(commands => commands.Contains("devices"))));
            Assert.AreEqual(3, devices.Count);
            Assert.IsTrue(devices.ElementAt(0).State == DeviceState.Online);
            Assert.IsTrue(devices.ElementAt(1).State == DeviceState.Unauthorized);
            Assert.IsTrue(devices.ElementAt(2).State == DeviceState.Offline);
        }
示例#3
0
        public async Task GetState(string[] output, AdbState state)
        {
            // arrange
            var processManager = new TestProcessManager();

            processManager.AddProcess(output);
            var adb = new Adb(processManager);

            var result = await adb.GetState();

            processManager.Stub.AssertWasCalled(_ => _.CreateProcess(Arg <string> .Is.Anything, Arg <string> .Matches(commands => commands.Contains("get-state"))));
            Assert.IsTrue(result == state);
        }
示例#4
0
        public async Task GetPropertyNull()
        {
            // arrange
            var processManager = new TestProcessManager();

            processManager.AddProcess(new[] { "  " });
            var adb = new Adb(processManager);

            // act
            var result = await adb.SingleDevice.Shell.GetProperty("test.property");

            // assert
            Assert.IsNull(result);
        }
示例#5
0
        public async Task Install(InstallOptions options, string expected)
        {
            // arrange
            var processManager = new TestProcessManager();

            processManager.AddProcess(new[] { "Success" });
            var adb = new Adb(processManager);

            // act
            var deviceAdb = adb.SingleDevice;
            await deviceAdb.Install("test.apk", options);

            // assert
            processManager.Stub.AssertWasCalled(_ => _.CreateProcess(Arg <string> .Is.Anything, Arg <string> .Matches(c => c.Contains(expected))));
        }
示例#6
0
        public async Task InstallWithInstaller()
        {
            // arrange
            var processManager = new TestProcessManager();

            processManager.AddProcess(new[] { "Success" });
            var adb = new Adb(processManager);

            // act
            var deviceAdb = adb.SingleDevice;
            await deviceAdb.Install("test.apk", InstallOptions.None, "com.android.vending");

            // assert
            processManager.Stub.AssertWasCalled(_ => _.CreateProcess(Arg <string> .Is.Anything, Arg <string> .Matches(c => c.Contains("-i com.android.vending"))));
        }
示例#7
0
        public async Task SingleEmulator()
        {
            // arrange
            var processManager = new TestProcessManager();

            processManager.AddProcess(new[] { "Some output" });
            var adb = new Adb(processManager);

            // act
            var deviceAdb = adb.SingleEmulator;
            await deviceAdb.RunCommand("test");

            // assert
            processManager.Stub.AssertWasCalled(_ => _.CreateProcess(Arg <string> .Is.Anything, Arg <string> .Matches(commands => commands.Contains("-e test"))));
        }
示例#8
0
        public async Task InstallResult(string output, string expected)
        {
            // arrange
            var processManager = new TestProcessManager();

            processManager.AddProcess(new[] { "3584 KB/s (69747 bytes in 0.019s)", "        pkg: /data/local/tmp/LocaleChanger.apk", output });
            var adb = new Adb(processManager);

            // act
            var deviceAdb = adb.SingleDevice;
            var result    = await deviceAdb.Install("test.apk");

            // assert
            Assert.AreEqual(expected, result);
        }
示例#9
0
        public async Task TargetDevice()
        {
            // arrange
            const string id             = "Device ID";
            var          processManager = new TestProcessManager();

            processManager.AddProcess(new[] { "Some output" });
            var adb = new Adb(processManager);

            // act
            var deviceAdb = adb.Target(id);
            await deviceAdb.RunCommand("test");

            // assert
            processManager.Stub.AssertWasCalled(_ => _.CreateProcess(Arg <string> .Is.Anything, Arg <string> .Matches(commands => commands.Contains(String.Format("-s \"{0}\" test", id)))));
        }
示例#10
0
        public async Task FailPushResult2()
        {
            // arrange
            var processManager = new TestProcessManager();

            processManager.AddProcess(new[] { "adb: error: failed to copy 'Log.txt' to '/mnt/rtyrtyurt': Read-only file system" });
            var adb = new Adb(processManager);

            // act
            var deviceAdb = adb.SingleDevice;
            var result    = await deviceAdb.Pull("/mnt/rtyrtyurt", "Log.txt");

            // assert
            Assert.IsFalse(result.Success);
            Assert.AreEqual("Read-only file system", result.Error);
        }
示例#11
0
        public async Task FailPushResult()
        {
            // arrange
            var processManager = new TestProcessManager();

            processManager.AddProcess(new[] { "adb: error: failed to copy 'Log.txt' to '/mnt/sdcard2/Log.txt': Permission denied" });
            var adb = new Adb(processManager);

            // act
            var deviceAdb = adb.SingleDevice;
            var result    = await deviceAdb.Pull("/mnt/sdcard/", "Log.txt");

            // assert
            Assert.IsFalse(result.Success);
            Assert.AreEqual("Permission denied", result.Error);
        }
示例#12
0
        public async Task SuccessPushResult()
        {
            // arrange
            var processManager = new TestProcessManager();

            processManager.AddProcess(new[] { "[100%] /mnt/sdcard/Log.txt" });
            var adb = new Adb(processManager);

            // act
            var deviceAdb = adb.SingleDevice;
            var result    = await deviceAdb.Push("Log.txt", "/mnt/sdcard/");

            // assert
            Assert.IsTrue(result.Success);
            Assert.IsNull(result.Error);
        }
示例#13
0
        public async Task FailPullResult()
        {
            // arrange
            var processManager = new TestProcessManager();

            processManager.AddProcess(new[] { "adb: error: remote object '/mnt/sdcard/Log2.txt' does not exist" });
            var adb = new Adb(processManager);

            // act
            var deviceAdb = adb.SingleDevice;
            var result    = await deviceAdb.Pull("/mnt/sdcard/", "Log.txt");

            // assert
            Assert.IsFalse(result.Success);
            Assert.AreEqual("remote object '/mnt/sdcard/Log2.txt' does not exist", result.Error);
        }
示例#14
0
        public async Task GetDevicesInvalidState()
        {
            // arrange
            var output = new List <string>
            {
                "List of devices attached",
                "0123456789ABCDE\tinvalidstate"
            };
            var processManager = new TestProcessManager();

            processManager.AddProcess(output);
            var adb = new Adb(processManager);

            // act + assert
            await AsyncAssert.Throws <UnexpectedOutputException>(async() => (await adb.GetDevices()).ToList());
        }
示例#15
0
        public async Task GetInstallLocation()
        {
            //arrange
            var processManager = new TestProcessManager();

            processManager.AddProcess(new[]
            {
                "1[internal]",
            }, "get-install-location");

            var adb = new Adb(processManager);

            //act
            var result = await adb.SingleDevice.Shell.PackageManager.GetInstallLocation();

            //assert
            Assert.AreEqual(InstallLocation.Internal, result);
        }
示例#16
0
        public async Task GetAllProperties()
        {
            // arrange
            var processManager = new TestProcessManager();

            processManager.AddProcess(new[]
            {
                "[ro.product.brand]: [Philips]",
                "[ro.secure]: [1]",
                "[ro.wifi.channels]: []"
            }, "getprop");

            var adb = new Adb(processManager);

            // act
            var result = await adb.SingleDevice.Shell.GetAllProperties();

            // assert
            Assert.AreEqual("Philips", result["ro.product.brand"]);
            Assert.AreEqual("1", result["ro.secure"]);
            Assert.AreEqual("", result["ro.wifi.channels"]);
        }
示例#17
0
        public async Task GetPackages()
        {
            //arrange
            var processManager = new TestProcessManager();

            processManager.AddProcess(new[]
            {
                "package:com.google.android.youtube",
                "package:com.android.browser.provider",
                "package:com.android.pacprocessor"
            }, "list packages");

            var adb = new Adb(processManager);

            //act
            var result = await adb.SingleDevice.Shell.PackageManager.GetPackages();

            //assert
            Assert.AreEqual(3, result.Count());
            Assert.AreEqual("com.google.android.youtube", result.ElementAt(0));
            Assert.AreEqual("com.android.browser.provider", result.ElementAt(1));
            Assert.AreEqual("com.android.pacprocessor", result.ElementAt(2));
        }
示例#18
0
        public async Task RestartServerMessagIgnoreAtDevicesList()
        {
            //Arrange
            var output = new List <string>
            {
                "adb server is out of date.  killing...",
                "* daemon started successfully *",
                "List of devices attached",
                "YT910X72U3	device"
            };
            var processManager = new TestProcessManager();

            processManager.AddProcess(output);
            var adb = new Adb(processManager);

            //Act
            var devices = await adb.GetDevices();

            //Assert

            Assert.AreEqual(1, devices.Count());
            Assert.AreEqual("YT910X72U3", devices.First().SerialNumber);
            Assert.AreEqual(DeviceState.Online, devices.First().State);
        }
示例#19
0
        public async Task GetUsers()
        {
            //arrange
            var processManager = new TestProcessManager();

            processManager.AddProcess(new[]
            {
                "Users:",
                "           UserInfo{0:Owner:13} running",
                "           UserInfo{1:Guest:2}"
            }, "list users");

            var adb = new Adb(processManager);

            //act
            var result = await adb.SingleDevice.Shell.PackageManager.GetUsers();

            //assert
            Assert.AreEqual(2, result.Count());
            Assert.AreEqual("0", result.ElementAt(0).Id);
            Assert.AreEqual("Owner", result.ElementAt(0).Name);
            Assert.AreEqual("1", result.ElementAt(1).Id);
            Assert.AreEqual("Guest", result.ElementAt(1).Name);
        }