コード例 #1
0
		public void AddAttachmentToCommunicationItemTest()
		{
			var client = GetRepository();


			var caseFromDb = client.Cases.Expand(c => c.CommunicationItems).FirstOrDefault();

			Assert.IsNotNull(caseFromDb);

			client.Attach(caseFromDb);


			var emailItemToAdd = new EmailItem();
			emailItemToAdd.Body = "newEmailItem";

			var phoneItemToAdd = new PhoneCallItem();
			phoneItemToAdd.Body = "newPhoneBody";

			Attachment attachToemail = new Attachment();
			attachToemail.DisplayName = "emailAttach";

			Attachment attachToPhone = new Attachment();
			attachToPhone.DisplayName = "phoneAttach";

			emailItemToAdd.Attachments.Add(attachToemail);
			phoneItemToAdd.Attachments.Add(attachToPhone);

			caseFromDb.CommunicationItems.Add(emailItemToAdd);
			caseFromDb.CommunicationItems.Add(phoneItemToAdd);

			client.UnitOfWork.Commit();


			client = GetRepository();

			var caseForCheck = client.Cases.Where(c => c.CaseId == caseFromDb.CaseId).Expand(c => c.CommunicationItems).SingleOrDefault();

			Assert.IsNotNull(caseForCheck);
			Assert.IsTrue(caseForCheck.CommunicationItems.Count >= 2);

			var emailForCheck = caseFromDb.CommunicationItems.Where(ci => ci.CommunicationItemId == emailItemToAdd.CommunicationItemId).OfType<EmailItem>()
				.SingleOrDefault();

			Assert.IsNotNull(emailForCheck);

			var emailAttachemntForCheck = emailForCheck.Attachments.Where(at => at.AttachmentId == attachToemail.AttachmentId).SingleOrDefault();

			Assert.IsNotNull(emailAttachemntForCheck);


			var phoneForCheck = caseFromDb.CommunicationItems.Where(ci => ci.CommunicationItemId == phoneItemToAdd.CommunicationItemId)
				.OfType<PhoneCallItem>().SingleOrDefault();

			Assert.IsNotNull(phoneForCheck);

			var phoneAttachmentForCheck = phoneForCheck.Attachments.Where(at => at.AttachmentId == attachToPhone.AttachmentId)
				.SingleOrDefault();

			Assert.IsNotNull(phoneAttachmentForCheck);

		}
コード例 #2
0
		public void AddCommunicationItemsWithAttachmentsToExistingCase()
		{
			var client = GetRepository();

			Case caseFromDb = client.Cases
				.Expand(c => c.Labels).Expand(c => c.Notes).Expand(c => c.CommunicationItems)
				.FirstOrDefault();

			Assert.IsNotNull(caseFromDb);
			client.Attach(caseFromDb);

			var emailItem = new EmailItem();
			emailItem.AuthorName = "Unknown";
			emailItem.Body = "body of emailItem";
			emailItem.From = "*****@*****.**";
			emailItem.Subject = "Subject";
			emailItem.Title = "Hello!!";
			emailItem.To = "*****@*****.**";


			var phoneItem = new PhoneCallItem();
			phoneItem.AuthorName = "bob marley";
			phoneItem.Body = "body of phoneitem";
			phoneItem.Direction = "Inbound";
			phoneItem.PhoneNumber = "789465123";
			phoneItem.Title = "Hey you!";


			var note = new Note();
			note.AuthorName = "Me";
			note.Body = "noteBody";
			note.Title = "note fo case";

			Attachment attach1 = new Attachment();
			attach1.DisplayName = "Attachment1";

			emailItem.Attachments.Add(attach1);

			caseFromDb.CommunicationItems.Add(emailItem);
			caseFromDb.CommunicationItems.Add(phoneItem);
			caseFromDb.Notes.Add(note);

			client.UnitOfWork.Commit();


			client = GetRepository();

			Case caseForCheck = client.Cases.Where(c => c.CaseId == caseFromDb.CaseId)
				.Expand(c => c.Labels).Expand(c => c.Notes).Expand(c => c.CommunicationItems)
				.SingleOrDefault();

			var phoneItemFromDb = caseForCheck.CommunicationItems.Where(ci => ci.CommunicationItemId == phoneItem.CommunicationItemId)
				.OfType<PhoneCallItem>().SingleOrDefault();

			var emailItemFromDb = caseForCheck.CommunicationItems.Where(ci => ci.CommunicationItemId == emailItem.CommunicationItemId)
				.OfType<EmailItem>().SingleOrDefault();

			var noteFromDb = caseForCheck.Notes.Where(n => n.NoteId == note.NoteId).SingleOrDefault();

			Assert.IsNotNull(caseForCheck);
			Assert.IsNotNull(phoneItemFromDb);
			Assert.IsNotNull(emailItemFromDb);
			Assert.IsNotNull(noteFromDb);

		}