public void InitializeTest() { using (var client = TestHelper.ClientGet()) { var locBlockRequest = new LocBlockRequest { Address = new AddressRequest { StreetAddress = "Kipdorp 30", PostalCode = "2000", City = "Antwerpen", CountryId = 1020, // Belgium LocationTypeId = 1, Name = MyAddressName } }; _myLocBlock = client.LocBlockSave(TestHelper.ApiKey, TestHelper.SiteKey, locBlockRequest).Values.First(); } }
public void GetLocBlockWithEvents() { // Make sure that your API user has permissions // 'access CiviEvent', 'view event info', // and 'edit all events'. var myAddressRequest = new AddressRequest { LocationTypeId = 1, StreetAddress = "Kipdorp 30", PostalCode = "2000", City = "Antwerpen" }; var myEventRequest = new EventRequest { Title = "My mighty unit test event", Description = "It will be fun.", StartDate = new Filter<DateTime?>(new DateTime(2015, 07, 01)), EndDate = new Filter<DateTime?>(new DateTime(2015, 07, 10)), EventTypeId = MyEventTypeId, }; using (var client = TestHelper.ClientGet()) { // Save the event by chaining everything to the loc block. var saveResult = client.LocBlockSave(TestHelper.ApiKey, TestHelper.SiteKey, new LocBlockRequest { Address = myAddressRequest, EventSaveRequest = new[] { myEventRequest } }); Assert.IsNotNull(saveResult.Id); int myLocBlockId = saveResult.Id.Value; int? myAddressId = saveResult.Values.First().AddressId; Assert.IsNotNull(myAddressId); var locBlockGetRequest = new LocBlockRequest { Id = myLocBlockId, EventGetRequest = new EventRequest { LocBlockIdValueExpression = "$value.id", } }; var getResult = client.LocBlockGetSingle(TestHelper.ApiKey, TestHelper.SiteKey, locBlockGetRequest); client.EventDelete(TestHelper.ApiKey, TestHelper.SiteKey, new DeleteRequest(getResult.EventResult.Values.First().Id)); client.LocBlockDelete(TestHelper.ApiKey, TestHelper.SiteKey, new DeleteRequest(myLocBlockId)); client.AddressDelete(TestHelper.ApiKey, TestHelper.SiteKey, new DeleteRequest(myAddressId.Value)); Assert.AreEqual(myLocBlockId, getResult.Id); Assert.AreEqual(1, getResult.EventResult.Count); var retrievedEvent = getResult.EventResult.Values.First(); Assert.AreEqual(myEventRequest.Title, retrievedEvent.Title); } }