Ejemplo n.º 1
0
		public async Task SendFileToContact_SeemsToWork()
		{
			using (var feedback = new DebugFeedbackChannel("Test"))
			{
				using (var initializing = feedback.BeginSubOperation("InitializeData"))
					await TestData.Current.BringToInitialState(initializing);

				using (var sending = feedback.BeginSubOperation("Sending"))
				{
					var client = new MegaClient(TestData.Current.Email1, TestData.Current.Password1);

					await client.AddContactAsync(TestData.Current.Email2, sending);
					var contactList = await client.GetContactListSnapshotAsync(sending);
					Assert.AreEqual(1, contactList.Count);
					var account2 = contactList.Single();

					var filesystem = await client.GetFilesystemSnapshotAsync(sending);

					var file = TestData.SmallFile.Find(filesystem);

					await file.SendToContactAsync(account2, sending);
				}

				using (var receiving = feedback.BeginSubOperation("Receiving"))
				{
					var client = new MegaClient(TestData.Current.Email2, TestData.Current.Password2);

					var filesystem = await client.GetFilesystemSnapshotAsync(receiving);

					var file = TestData.SmallFile.Find(filesystem);

					Assert.IsNotNull(file);

					var target = Path.GetTempFileName();

					// Verify contents.
					try
					{
						Debug.WriteLine("Temporary local file: " + target);

						await file.DownloadContentsAsync(target, feedback);

						using (var expectedContents = TestData.SmallFile.Open())
						using (var contents = File.OpenRead(target))
							TestHelper.AssertStreamsAreEqual(expectedContents, contents);
					}
					finally
					{
						File.Delete(target);
					}
				}
			}
		}
Ejemplo n.º 2
0
		public async Task SendFolderToContact_SeemsToWork()
		{
			using (var feedback = new DebugFeedbackChannel("Test"))
			{
				using (var initializing = feedback.BeginSubOperation("InitializeData"))
					await TestData.Current.BringToInitialState(initializing);

				using (var sending = feedback.BeginSubOperation("Sending"))
				{
					var client = new MegaClient(TestData.Current.Email1, TestData.Current.Password1);

					await client.AddContactAsync(TestData.Current.Email2, sending);
					var contactList = await client.GetContactListSnapshotAsync(sending);
					Assert.AreEqual(1, contactList.Count);
					var account2 = contactList.Single();

					var filesystem = await client.GetFilesystemSnapshotAsync(sending);

					var folder = filesystem.Files.Children
						.Single(i => i.Type == ItemType.Folder && i.Name == "Folder1");

					await folder.SendToContactAsync(account2, sending);
				}

				using (var receiving = feedback.BeginSubOperation("Receiving"))
				{
					var client = new MegaClient(TestData.Current.Email2, TestData.Current.Password2);

					var filesystem = await client.GetFilesystemSnapshotAsync(receiving);

					var file = TestData.SmallFile.Find(filesystem);

					Assert.IsNotNull(file);
					Assert.IsNotNull(file.Parent);
					Assert.AreEqual("Folder1", file.Parent.Name);
				}
			}
		}
Ejemplo n.º 3
0
		/// <summary>
		/// Brings the two test accounts to the initial state.
		/// </summary>
		/// <remarks>
		/// Account 1 contents:
		/// Files
		/// - Folder1
		/// -- Folder2
		/// --- EmptyFile
		/// -- SmallFile
		/// - BigFile
		/// - MediumFile
		/// Contacts
		/// 
		/// Account 2 contents:
		/// Files
		/// Contacts
		/// - Account 1
		/// </remarks>
		public async Task BringToInitialState(IFeedbackChannel feedback)
		{
			var client1 = new MegaClient(Email1, Password1);
			var client2 = new MegaClient(Email2, Password2);

			var filesystem1 = await client1.GetFilesystemSnapshotAsync(feedback);

			// Got folders?
			var folder1 = filesystem1.Files.Children
				.FirstOrDefault(ci => ci.Type == ItemType.Folder && ci.Name == "Folder1");

			CloudItem folder2 = null;

			if (folder1 != null)
				folder2 = folder1.Children
					.FirstOrDefault(ci => ci.Type == ItemType.Folder && ci.Name == "Folder2");

			// Make folders, if needed.
			if (folder1 == null)
				folder1 = await filesystem1.Files.NewFolderAsync("Folder1", feedback);

			if (folder2 == null)
				folder2 = await folder1.NewFolderAsync("Folder2", feedback);

			// Got files?
			var bigFile = BigFile.TryFind(filesystem1);
			var mediumFile = MediumFile.TryFind(filesystem1);
			var smallFile = SmallFile.TryFind(filesystem1);
			var emptyFile = EmptyFile.TryFind(filesystem1);

			// Then upload the new files.
			if (emptyFile == null || emptyFile.Parent != folder2)
				using (var stream = OpenTestDataFile(EmptyFile.Name))
					emptyFile = await folder2.NewFileAsync(EmptyFile.Name, stream, feedback);

			if (smallFile == null || smallFile.Parent != folder1)
				using (var stream = OpenTestDataFile(SmallFile.Name))
					smallFile = await folder1.NewFileAsync(SmallFile.Name, stream, feedback);

			if (mediumFile == null || mediumFile.Parent != filesystem1.Files)
				using (var stream = OpenTestDataFile(MediumFile.Name))
					mediumFile = await filesystem1.Files.NewFileAsync(MediumFile.Name, stream, feedback);

			if (bigFile == null || bigFile.Parent != filesystem1.Files)
				using (var stream = OpenTestDataFile(BigFile.Name))
					bigFile = await filesystem1.Files.NewFileAsync(BigFile.Name, stream, feedback);

			// Delete all items that we do not care about for account 1.
			var goodItems = new[]
			{
				folder1.ID,
				folder2.ID,
				bigFile.ID,
				mediumFile.ID,
				smallFile.ID,
				emptyFile.ID
			};

			await DeleteUnwantedItems(filesystem1.Files, goodItems, feedback);
			await DeleteUnwantedItems(filesystem1.Trash, goodItems, feedback);

			// Delete all files and folders for account 2.
			var filesystem2 = await client2.GetFilesystemSnapshotAsync(feedback);

			foreach (var item in filesystem2.AllItems.Where(ci => ci.Type == ItemType.File || ci.Type == ItemType.Folder))
				await item.DeleteAsync(feedback);

			// Delete all contacts.
			foreach (var contact in await client1.GetContactListSnapshotAsync(feedback))
				await contact.RemoveAsync(feedback);

			foreach (var contact in await client2.GetContactListSnapshotAsync(feedback))
				await contact.RemoveAsync(feedback);

			// Add account 1 as contact to account 2.
			await client2.AddContactAsync(Email1, feedback);
		}