Ejemplo n.º 1
0
        public void it_can_parse_implicit_boolean_where_filter()
        {
            StubIntegrationProxy integrationProxy = new StubIntegrationProxy();
            Repository repository = new Repository(integrationProxy);

            var users = repository.Users.Where(user => user.IsSubscriber).ToList();

            Assert.AreEqual("(IsSubscriber == true)", integrationProxy.LastQueryDescription.Where);
        }
Ejemplo n.º 2
0
        public void it_can_UpdateOrCreate_a_model_that_represents_a_valid_endpoint()
        {
            var integrationProxy = new Stubs.StubIntegrationProxy();

            Repository repository = new Repository(integrationProxy);

            repository.UpdateOrCreate(new Invoice());

            Assert.AreEqual("Invoice", integrationProxy.LastEndpointName);
        }
Ejemplo n.º 3
0
        public void TestApiQueryCanCallOrganisationsEndpointWithNoArguments()
        {
            StubIntegrationProxy integrationProxy = new StubIntegrationProxy();
            Repository repository = new Repository(integrationProxy);

            List<Organisation> organisations = repository.Organisations.ToList();

            Assert.AreEqual(0, organisations.Count);
            Assert.AreEqual("Organisation", integrationProxy.LastQueryDescription.ElementName);
        }
Ejemplo n.º 4
0
        public void TestApiQueryCanCallInvoicesEndpointWithContactNumberFilter()
        {
            StubIntegrationProxy integrationProxy = new StubIntegrationProxy();
            Repository repository = new Repository(integrationProxy);

            var invoices = repository.Invoices.Where(inv => inv.Contact.ContactNumber == "S0029").ToList();

            var queryDesctipion = integrationProxy.LastQueryDescription;
            Assert.AreEqual("Invoice", queryDesctipion.ElementType.Name);
            Assert.AreEqual("(Contact.ContactNumber == \"S0029\")", queryDesctipion.Where);
            Assert.AreEqual("", queryDesctipion.Order);
        }
Ejemplo n.º 5
0
        public void TestApiQueryCanCallOrganisationsEndpointWithOneWhereArgument()
        {
            StubIntegrationProxy integrationProxy = new StubIntegrationProxy();
            Repository repository = new Repository(integrationProxy);

            var organisations = repository.Organisations.Where(o => o.Name == "Demo Company (NZ)").ToList();

            var queryDesctipion = integrationProxy.LastQueryDescription;
            Assert.AreEqual("Organisation", queryDesctipion.ElementType.Name);
            Assert.AreEqual("(Name == \"Demo Company (NZ)\")", queryDesctipion.Where);
            Assert.AreEqual("", queryDesctipion.Order);
        }
Ejemplo n.º 6
0
        public void TestApiQueryCanCallUsersEndpointWith_implicit_BooleanFilter()
        {
            StubIntegrationProxy integrationProxy = new StubIntegrationProxy();
            Repository repository = new Repository(integrationProxy);

            // Note: This needs the '== true' but to work correctly
            List<User> invoices = repository.Users.Where(user => user.IsSubscriber).ToList();

            var queryDesctipion = integrationProxy.LastQueryDescription;
            Assert.AreEqual("User", queryDesctipion.ElementType.Name);
            Assert.AreEqual("(IsSubscriber == true)", queryDesctipion.Where);
            Assert.AreEqual("", queryDesctipion.Order);
            Assert.AreEqual(0, invoices.Count);
        }
Ejemplo n.º 7
0
        public void TestApiQueryCanCallOrganisationsEndpointWithTwoWhereArguments()
        {
            StubIntegrationProxy integrationProxy = new StubIntegrationProxy();
            Repository repository = new Repository(integrationProxy);

            var response = repository.Organisations
                .Where(o => o.Name == "Demo Company")
                .Where(o => o.APIKey == "ABCDEFG")
                .ToList();

            var queryDesctipion = integrationProxy.LastQueryDescription;
            Assert.AreEqual("Organisation", queryDesctipion.ElementType.Name);
            Assert.AreEqual("(Name == \"Demo Company\") AND (APIKey == \"ABCDEFG\")", queryDesctipion.Where);
            Assert.AreEqual("", queryDesctipion.Order);
        }
Ejemplo n.º 8
0
        public void it_can_filter_string_properties_using_startswith_method_with_another_filter()
        {
            StubIntegrationProxy integrationProxy = new StubIntegrationProxy();
            Repository repository = new Repository(integrationProxy);

            var response = repository.Contacts.FirstOrDefault(c => c.Name.StartsWith("Coffee") && c.IsCustomer == true);

            var queryDesctipion = integrationProxy.LastQueryDescription;

            Assert.AreEqual("Contact", queryDesctipion.ElementType.Name);
            Assert.AreEqual("(Name.StartsWith(\"Coffee\") AND (IsCustomer == true))", queryDesctipion.Where);
        }
Ejemplo n.º 9
0
        public void it_does_not_implement_contains_linq_method()
        {
            StubIntegrationProxy integrationProxy = new StubIntegrationProxy();
            Repository repository = new Repository(integrationProxy);

            Assert.Throws<NotImplementedException>(() => repository.Contacts.Contains(new Contact { Name = "Jason" }));
        }
Ejemplo n.º 10
0
        public void it_can_filter_string_properties_on_methos_of_literal()
        {
            StubIntegrationProxy integrationProxy = new StubIntegrationProxy();
            Repository repository = new Repository(integrationProxy);

            repository.Contacts.FirstOrDefault(c => c.Name == "Jason".ToUpper());
            var queryDesctipion = integrationProxy.LastQueryDescription;

            Assert.AreEqual("Contact", queryDesctipion.ElementType.Name);
            Assert.AreEqual("(Name == \"JASON\")", queryDesctipion.Where);
        }
Ejemplo n.º 11
0
        public void it_can_filter_string_properties_using_contains_method()
        {
            StubIntegrationProxy integrationProxy = new StubIntegrationProxy();
            Repository repository = new Repository(integrationProxy);

            repository.Contacts.FirstOrDefault(c => c.Name.Contains("Coffee"));
            var queryDesctipion = integrationProxy.LastQueryDescription;

            Assert.AreEqual("Contact", queryDesctipion.ElementType.Name);
            Assert.AreEqual("Name.Contains(\"Coffee\")", queryDesctipion.Where);
        }
Ejemplo n.º 12
0
        public void it_can_filter_properties_on_object_properties_not_in_the_linq_definition()
        {
            StubIntegrationProxy integrationProxy = new StubIntegrationProxy();
            Repository repository = new Repository(integrationProxy);

            var invoice = new Invoice {Contact = new Contact { Name = "Joe Bloggs" }};

            var response = repository.Invoices
                .Where(i => i.Contact.Name == invoice.Contact.Name)
                .ToList();

            var queryDesctipion = integrationProxy.LastQueryDescription;
            Assert.AreEqual("Invoice", queryDesctipion.ElementType.Name);
            Assert.AreEqual("(Contact.Name == \"Joe Bloggs\")", queryDesctipion.Where);
        }
Ejemplo n.º 13
0
        public void TestApiQueryCanCallContactsEndpointWithContactNumberIsNotNull()
        {
            StubIntegrationProxy integrationProxy = new StubIntegrationProxy();
            Repository repository = new Repository(integrationProxy);

            var response = repository.Contacts.SingleOrDefault(i => i.ContactNumber != null);

            var queryDesctipion = integrationProxy.LastQueryDescription;

            Assert.AreEqual("Contact", queryDesctipion.ElementType.Name);
            Assert.AreEqual("SingleOrDefault", queryDesctipion.ClientSideExpression);
            Assert.AreEqual("(ContactNumber <> NULL)", queryDesctipion.Where);
        }
Ejemplo n.º 14
0
        public void it_can_filter_using_a_predefined_predicate_expression_variable()
        {
            StubIntegrationProxy integrationProxy = new StubIntegrationProxy();
            Repository repository = new Repository(integrationProxy);

            Expression<Func<Invoice, bool>> filterInvoiceByCurrency = i => i.CurrencyCode == "AUD";

            var response = repository.Invoices.Where(filterInvoiceByCurrency).ToList();
            
            Assert.AreEqual("(CurrencyCode == \"AUD\")", integrationProxy.LastQueryDescription.Where);
        }
Ejemplo n.º 15
0
        public void TestApiQueryCanCallContactsEndpointWithAndAlsoOperator()
        {
            StubIntegrationProxy integrationProxy = new StubIntegrationProxy();
            Repository repository = new Repository(integrationProxy);

            var response = repository.Contacts
                .Where(c => c.ContactStatus == "ACTIVE" && c.IsCustomer == true)
                .ToList();

            var queryDesctipion = integrationProxy.LastQueryDescription;
            Assert.AreEqual("Contact", queryDesctipion.ElementType.Name);
            Assert.AreEqual("((ContactStatus == \"ACTIVE\") AND (IsCustomer == true))", queryDesctipion.Where);
        }
Ejemplo n.º 16
0
        public void TestApiQueryCanCallEmployeeEndpointWithImplicitLinqBooleanOperator()
        {
            StubIntegrationProxy integrationProxy = new StubIntegrationProxy();
            Repository repository = new Repository(integrationProxy);

            var query = from user in repository.Users
                        where user.IsSubscriber == false
                        select user;

            var response = query.GetEnumerator();

            var queryDesctipion = integrationProxy.LastQueryDescription;
            Assert.AreEqual("User", queryDesctipion.ElementType.Name);
            Assert.AreEqual("(IsSubscriber == false)", queryDesctipion.Where);
        }
Ejemplo n.º 17
0
        public void TestApiQueryCanCallEmployeeEndpointWithSingleOperator()
        {
            StubIntegrationProxy integrationProxy = new StubIntegrationProxy();
            Repository repository = new Repository(integrationProxy);

            var response = repository.Users.Single(u => u.FullName == "Joe Bloggs");
            
            var queryDesctipion = integrationProxy.LastQueryDescription;

            Assert.AreEqual("User", queryDesctipion.ElementType.Name);
            Assert.AreEqual("Single", queryDesctipion.ClientSideExpression);
            Assert.AreEqual("(FullName == \"Joe Bloggs\")", queryDesctipion.Where);
        }
Ejemplo n.º 18
0
        public void TestApiQueryCanCallEmployeeEndpointWithImplicitBooleanAndNotOperator()
        {
            StubIntegrationProxy integrationProxy = new StubIntegrationProxy();
            Repository repository = new Repository(integrationProxy);

            var response = repository.Users
                .Where(u => !u.IsSubscriber)
                .ToList();

            var queryDesctipion = integrationProxy.LastQueryDescription;
            Assert.AreEqual("User", queryDesctipion.ElementType.Name);
            Assert.AreEqual("(IsSubscriber == false)", queryDesctipion.Where);
        }
Ejemplo n.º 19
0
        public void TestApiQueryCanCallContactsEndpointWithOrElseAndAndAlsoOperator()
        {
            StubIntegrationProxy integrationProxy = new StubIntegrationProxy();
            Repository repository = new Repository(integrationProxy);

            var response = repository.Contacts
                .Where(c => (c.ContactStatus == "ACTIVE" || c.IsCustomer == true) && (c.ContactStatus == "ARCHIVED"))
                .ToList();

            var queryDesctipion = integrationProxy.LastQueryDescription;
            Assert.AreEqual("(((ContactStatus == \"ACTIVE\") OR (IsCustomer == true)) AND (ContactStatus == \"ARCHIVED\"))", queryDesctipion.Where);
        }
Ejemplo n.º 20
0
        public void TestApiQueryCanCallContactsEndpointWithLinqAndAlsoOperator()
        {
            StubIntegrationProxy integrationProxy = new StubIntegrationProxy();
            Repository repository = new Repository(integrationProxy);

            IQueryable<Contact> query = from contact in repository.Contacts
                      where contact.ContactStatus == "ACTIVE" && contact.IsCustomer == true
                      select contact;

            var response = query.GetEnumerator();

            var queryDesctipion = integrationProxy.LastQueryDescription;
            Assert.AreEqual("Contact", queryDesctipion.ElementType.Name);
            Assert.AreEqual("((ContactStatus == \"ACTIVE\") AND (IsCustomer == true))", queryDesctipion.Where);
        }
Ejemplo n.º 21
0
        public void it_can_filter_string_properties_using_static_methods_with_implicit_affirmation()
        {
            StubIntegrationProxy integrationProxy = new StubIntegrationProxy();
            Repository repository = new Repository(integrationProxy);

            var response = repository.Contacts.Where(c => string.IsNullOrEmpty(c.ContactNumber)).ToList();

            var queryDesctipion = integrationProxy.LastQueryDescription;

            Assert.AreEqual("Contact", queryDesctipion.ElementType.Name);
            Assert.AreEqual("String.IsNullOrEmpty(ContactNumber)", queryDesctipion.Where);
        }
Ejemplo n.º 22
0
        public void it_can_filter_on_inequality_of_the_model_id()
        {
            StubIntegrationProxy integrationProxy = new StubIntegrationProxy();
            Repository repository = new Repository(integrationProxy);

            repository.Invoices.Where(i => i.InvoiceID != Guid.Empty).ToList();

            Assert.AreEqual("", integrationProxy.LastQueryDescription.ElementId);
            Assert.AreEqual("(InvoiceID != Guid('00000000-0000-0000-0000-000000000000'))", integrationProxy.LastQueryDescription.Where);
        }
Ejemplo n.º 23
0
        public void it_can_filter_on_a_nullable_date_property_with_an_inline_value()
        {
            StubIntegrationProxy integrationProxy = new StubIntegrationProxy();
            Repository repository = new Repository(integrationProxy);

            var response = repository.Invoices.Where(i => i.Date == new DateTime(2012, 01, 04)).ToList();

            var queryDesctipion = integrationProxy.LastQueryDescription;

            Assert.AreEqual("Invoice", queryDesctipion.ElementType.Name);
            Assert.AreEqual("(Date == DateTime(2012,1,4))", queryDesctipion.Where);
        }
Ejemplo n.º 24
0
        public void it_can_filter_on_collections_within_the_linq_definition()
        {
            StubIntegrationProxy integrationProxy = new StubIntegrationProxy();
            Repository repository = new Repository(integrationProxy);

            var contact = new Contact { Addresses = new Addresses { new Address { City = "Moscow" } } };

            var response = repository.Invoices
                .Where(i => i.Contact.Addresses[0].City == contact.Addresses[0].City)
                .ToList();

            var queryDesctipion = integrationProxy.LastQueryDescription;
            Assert.AreEqual("Invoice", queryDesctipion.ElementType.Name);
            Assert.AreEqual("(Contact.Addresses[0].City == \"Moscow\")", queryDesctipion.Where);
        }
Ejemplo n.º 25
0
        public void it_can_filter_using_member_method_with_no_arguments()
        {
            StubIntegrationProxy integrationProxy = new StubIntegrationProxy();
            Repository repository = new Repository(integrationProxy);
            
            repository.Invoices.Where(i => i.InvoiceNumber.ToLower() == "inv-123").ToList();

            Assert.AreEqual("(InvoiceNumber.ToLower() == \"inv-123\")", integrationProxy.LastQueryDescription.Where);
        }
Ejemplo n.º 26
0
        public void TestApiQueryCanCallOrganisationsEndpointWithOrderByAndWhereMethod()
        {
            StubIntegrationProxy integrationProxy = new StubIntegrationProxy();
            Repository repository = new Repository(integrationProxy);

            var response = repository.Organisations
                .Where(organisation => organisation.Name == "Demo Company")
                .OrderBy(organisation => organisation.CreatedDateUTC)
                .ToList();

            var queryDesctipion = integrationProxy.LastQueryDescription;
            Assert.AreEqual("Organisation", queryDesctipion.ElementType.Name);
            Assert.AreEqual("(Name == \"Demo Company\")", queryDesctipion.Where);
            Assert.AreEqual("CreatedDateUTC", queryDesctipion.Order);
        }
Ejemplo n.º 27
0
        public void TestApiQueryCanCallInvoicesEndpointWithUpdatedDateAndTypeFilterCombinedWithAndOperator()
        {
            StubIntegrationProxy integrationProxy = new StubIntegrationProxy();
            Repository repository = new Repository(integrationProxy);

            var response = repository.Invoices.Where(i => i.UpdatedDateUTC > new DateTime(2010, 1, 1) && i.Type == "ACCPAY").ToList();

            var queryDesctipion = integrationProxy.LastQueryDescription;

            Assert.AreEqual("Invoice", queryDesctipion.ElementType.Name);
            Assert.AreEqual(null, queryDesctipion.ClientSideExpression);
            Assert.AreEqual("(Type == \"ACCPAY\")", queryDesctipion.Where);
            Assert.AreEqual(new DateTime(2010, 01, 01), queryDesctipion.UpdatedSinceDate);
        }
Ejemplo n.º 28
0
        public void TestApiQueryCanCallInvoicesEndpointFilteringByContactID()
        {
            StubIntegrationProxy integrationProxy = new StubIntegrationProxy();
            Repository repository = new Repository(integrationProxy);

            var response = repository.Invoices
                .Where(invoice => invoice.Contact.ContactID == new Guid("071509D6-BADC-4237-9F52-AD2B4CCD9264"))
                .ToList();

            var queryDesctipion = integrationProxy.LastQueryDescription;
            Assert.AreEqual("Invoice", queryDesctipion.ElementType.Name);
            Assert.AreEqual("(Contact.ContactID == Guid(\"071509d6-badc-4237-9f52-ad2b4ccd9264\"))", queryDesctipion.Where);
        }
Ejemplo n.º 29
0
        public void TestApiQueryCanCallOrganisationsEndpointWithFirstMethod()
        {
            StubIntegrationProxy integrationProxy = new StubIntegrationProxy();
            Repository repository = new Repository(integrationProxy);

            var response = repository.Organisations.First();

            var queryDesctipion = integrationProxy.LastQueryDescription;
            Assert.AreEqual("Organisation", queryDesctipion.ElementType.Name);
            Assert.AreEqual("", queryDesctipion.Where);
            Assert.AreEqual("", queryDesctipion.Order);
        }
Ejemplo n.º 30
0
        public void TestApiQueryCanCallInvoicesEndpointWithUpdatedDateAndUrlFilterCombinedWithAndOperator()
        {
            StubIntegrationProxy integrationProxy = new StubIntegrationProxy();
            Repository repository = new Repository(integrationProxy);

            var response = repository.Invoices.SingleOrDefault(i => i.UpdatedDateUTC > new DateTime(2010, 1, 1) && i.Url != null);
            
            var queryDesctipion = integrationProxy.LastQueryDescription;

            Assert.AreEqual("Invoice", queryDesctipion.ElementType.Name);
            Assert.AreEqual("SingleOrDefault", queryDesctipion.ClientSideExpression);
            Assert.AreEqual("(Url <> NULL)", queryDesctipion.Where);
            Assert.AreEqual(new DateTime(2010, 01, 01), queryDesctipion.UpdatedSinceDate);
        }