public void CreateMembership()
        {
            // If this test fails, check whether your API user has the permissions
            // access civimember and edit memberships.
            using (var client = TestHelper.ClientGet())
            {
                var membershipRequest = new MembershipRequest
                {
                    MembershipTypeId = SomeMembershipTypeId,
                    ContactId = _myContactId1,
                    JoinDate = DateTime.Now.Date,
                    StartDate = DateTime.Now.Date,
                    Status = MembershipStatus.Pending
                };

                var result = client.MembershipSave(TestHelper.ApiKey, TestHelper.SiteKey, membershipRequest);
                var newMembership = result.Values.First();

                Assert.AreEqual(membershipRequest.MembershipTypeId, newMembership.MembershipTypeId);
                Assert.AreEqual(membershipRequest.ContactId, newMembership.ContactId);
                Assert.AreEqual(membershipRequest.JoinDate, newMembership.JoinDate);
                Assert.AreEqual(membershipRequest.StartDate, newMembership.StartDate);
                Assert.AreEqual(membershipRequest.Status, newMembership.Status);
            }
        }
        public void GetMembershipWithContact()
        {
            var membershipRequest = new MembershipRequest
            {
                ContactGetRequest = new ContactRequest(),
                ContactId = _myContactId2
            };
            using (var client = TestHelper.ClientGet())
            {
                var result = client.MembershipGet(TestHelper.ApiKey, TestHelper.SiteKey, membershipRequest);

                Assert.IsTrue(result.Count >= 1);
                var first = result.Values.First();
                Assert.IsNotNull(first.ContactResult);
                Assert.AreEqual(_myContactId2, first.ContactResult.Values.First().Id);
            }
        }
        public void GetMembershipWithPayment()
        {
            var membershipRequest = new MembershipRequest
            {
                MembershipPaymentGetRequest = new MembershipPaymentRequest()
            };
            using (var client = TestHelper.ClientGet())
            {
                var result = client.MembershipGet(TestHelper.ApiKey, TestHelper.SiteKey, membershipRequest);

                Assert.IsTrue(result.Count >= 1);
                var first = result.Values.First();
                Assert.IsNotNull(first.MembershipPaymentResult);
            }
        }
        public void RelationshipDateFilter()
        {
            var membershipRequest = new MembershipRequest
            {
                ContactId = _myContactId2,
                StartDateFilter = new Filter<DateTime?>(WhereOperator.Gte, new DateTime(2016, 09, 21))
            };
            using (var client = TestHelper.ClientGet())
            {
                var result = client.MembershipGet(TestHelper.ApiKey, TestHelper.SiteKey, membershipRequest);

                Assert.AreEqual(1, result.Count);
            }
        }
        public void GetMembershipStatusFilter()
        {
            var membershipRequest = new MembershipRequest
            {
                ContactId = _myContactId2,
                StatusFilter = new Filter<MembershipStatus>(WhereOperator.In, MembershipStatus.New, MembershipStatus.Current)
            };
            using (var client = TestHelper.ClientGet())
            {
                var result = client.MembershipGet(TestHelper.ApiKey, TestHelper.SiteKey, membershipRequest);

                Assert.AreEqual(1, result.Count);
            }
        }
        public void GetMembership()
        {
            var membershipRequest = new MembershipRequest
            {
                ContactId = _myContactId2
            };
            using (var client = TestHelper.ClientGet())
            {
                var result = client.MembershipGet(TestHelper.ApiKey, TestHelper.SiteKey, membershipRequest);

                Assert.AreEqual(1, result.Count);
            }
        }