public void Find() { var proxy = new ActivityProxy(); ActivityDto first = GetActivityDto(); first.Owner = ApiUserEmailAddress; proxy.Insert(first); Assert.AreNotEqual(0, first.Uid); var firstGet = (ActivityDto) proxy.GetByUid(first.Uid); ReflectionTester.AssertAreEqual(first, firstGet, "LastModified"); ActivityDto second = GetActivityDto(); second.Owner = ApiUserEmailAddress; second.AttachedToType = "Contact"; second.AttachedToUid = MrSmith.Uid; proxy.Insert(second); var secondGet = (ActivityDto) proxy.GetByUid(second.Uid); ReflectionTester.AssertAreEqual(second, secondGet, "LastModified"); List<ActivityDto> activities = proxy.FindList<ActivityDto>(ActivityProxy.ResponseXPath, "Type", "Meeting"); Assert.AreNotEqual(0, activities.Count); List<ActivityDto> kazActivities = proxy.FindList<ActivityDto>(ActivityProxy.ResponseXPath, "Type", "Meeting", "Owner", ApiUserEmailAddress); Assert.AreNotEqual(0, kazActivities.Count); // all api/kaz should be part of activities AssertInList(kazActivities, activities); // delete proxy.DeleteByUid(first.Uid); try { firstGet = (ActivityDto) proxy.GetByUid(first.Uid); } catch (RestException exception) { Assert.AreEqual("RecordNotFoundException", exception.Type); } proxy.DeleteByUid(second.Uid); try { secondGet = (ActivityDto) proxy.GetByUid(second.Uid); } catch (RestException exception) { Assert.AreEqual("RecordNotFoundException", exception.Type); } }
public void FindAttachedToContact() { var proxy = new ActivityProxy(); ActivityDto entity = GetActivityDto(); entity.Owner = ApiUserEmailAddress; entity.AttachedToType = "Contact"; entity.AttachedToUid = MrSmith.Uid; proxy.Insert(entity); List<ActivityDto> apiActivities = proxy.FindList<ActivityDto>(ActivityProxy.ResponseXPath, "Type", "Meeting", "Owner", ApiUserEmailAddress, "AttachedToType", "Contact", "AttachedToUid", MrSmith.Uid.ToString()); Assert.AreNotEqual(0, apiActivities.Count); bool found = false; foreach (ActivityDto activity in apiActivities) { Assert.AreEqual(entity.AttachedToUid, activity.AttachedToUid); Assert.AreEqual(entity.AttachedToType, activity.AttachedToType); if (activity.Uid == entity.Uid) { found = true; } } if (!found) Assert.Fail("Could not find entity {0} attached to contact.", entity.Uid); proxy.DeleteByUid(entity.Uid); }
public void TryGetByLastModified() { var proxy = new ActivityProxy(); ActivityDto first = GetActivityDto(); first.Owner = ApiUserEmailAddress; Thread.Sleep(2*1000); proxy.Insert(first); var retrived = (ActivityDto) proxy.GetByUid(first.Uid); DateTime firstInsert = retrived.LastModified.AddSeconds(-1); // go back once Thread.Sleep(5*1000); ActivityDto second = GetActivityDto(); second.Owner = ApiUserEmailAddress; Thread.Sleep(2*1000); proxy.Insert(second); retrived = (ActivityDto) proxy.GetByUid(second.Uid); DateTime secondInsert = retrived.LastModified.AddSeconds(-1); // go back once var dateFrom = secondInsert; var dateTo = DateTime.UtcNow.AddMinutes(5); List<ActivityDto> secondOnly = proxy.FindList<ActivityDto>(ActivityProxy.ResponseXPath, "datetype", "modified", "Owner", ApiUserEmailAddress, "DateFrom", dateFrom.ToString("s"), "DateTo", dateTo.ToString("s")); Assert.IsTrue(secondOnly.Count >= 1); foreach (var activityDto in secondOnly) { Assert.IsTrue(activityDto.LastModified >= dateFrom && activityDto.LastModified <= dateTo, "Activity where last mod outside date range included. ActivityId: {0}.", activityDto.Uid); } ReflectionTester.AssertAreEqual(second, secondOnly[0], new[] {"LastModified", "UtcLastModified"}); List<ActivityDto> firstAndSecond = proxy.FindList<ActivityDto>(ActivityProxy.ResponseXPath, "datetype", "modified", "Owner", ApiUserEmailAddress, "DateFrom", firstInsert.ToString("s"), "DateTo", DateTime.UtcNow.AddMinutes(5).ToString("s")); Assert.AreEqual(2, firstAndSecond.Count); ReflectionTester.AssertAreEqual(first, firstAndSecond[1], new[] {"LastModified", "UtcLastModified"}); ReflectionTester.AssertAreEqual(second, firstAndSecond[0], new[] {"LastModified", "UtcLastModified"}); }