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); } }
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); }
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); }
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); }
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)))); }
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")))); }
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")))); }
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); }
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))))); }
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); }
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); }
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); }
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); }
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()); }
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); }
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"]); }
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)); }
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); }
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); }