Beispiel #1
0
        public void Can_search_by_Zip()
        {
            using (GetNewServer())
                using (var store = new DocumentStore {
                    Url = "http://localhost:8080"
                }.Initialize())
                {
                    CreateTestData(store);

                    var fromCutoffDate = DateTime.MaxValue;
                    var thruCutoffDate = DateTime.MinValue;
                    var searchCriteria = new SearchProviderParamsPto
                    {
                        Zip          = "WA000",
                        AddressTypes = new Collection <AddressTypeEnumPto2>
                        {
                            AddressTypeEnumPto2.PayToAddress,
                            AddressTypeEnumPto2.PracticeOfficeAddress,
                            AddressTypeEnumPto2.ProviderAddress
                        }
                    };

                    using (var session = store.OpenSession())
                    {
                        var query = from p in session.Query <ProviderPto2>()
                                    where
                                    // Search for Provider Addresses: Zip
                                    (p.AddressesPto.Any(x => x.Address.Zip == searchCriteria.Zip &&
                                                        x.Address.AddressTypePto.In(searchCriteria.AddressTypes)))

                                    // ... or PracticeOffice Addresses : Zip
                                    || (p.PracticeOfficesPto.Any(x => x.PrimaryContact.Address.Zip == searchCriteria.Zip
                                                                 &&
                                                                 x.PrimaryContact.Address.AddressTypePto.In(
                                                                     searchCriteria.AddressTypes) &&
                                                                 // Check PracticeOffice effective dates
                                                                 (x.EffectiveFrom <= fromCutoffDate)
                                                                 &&
                                                                 ((x.EffectiveThrough == null) ||
                                                                  (x.EffectiveThrough >= thruCutoffDate)) &&
                                                                 // Check Contact effective dates
                                                                 (x.PrimaryContact.ContactEffectiveFrom <= fromCutoffDate) &&
                                                                 ((x.PrimaryContact.ContactEffectiveThrough == null) ||
                                                                  (x.PrimaryContact.ContactEffectiveThrough >= thruCutoffDate)) &&
                                                                 // Check Contact address effective dates
                                                                 (x.PrimaryContact.AddressEffectiveFrom <= fromCutoffDate) &&
                                                                 ((x.PrimaryContact.AddressEffectiveThrough == null) ||
                                                                  (x.PrimaryContact.AddressEffectiveThrough >= thruCutoffDate))
                                                                 ))

                                    // ... or Vendor Addresses: Zip
                                    || (p.PayTosPto.Any(x => x.PrimaryContact.Zip == searchCriteria.Zip &&
                                                        x.PrimaryContact.AddressTypePto.In(searchCriteria.AddressTypes)))
                                    select p;
                        Assert.Equal(1, query.ToArray().Length);
                    }
                }
        }
Beispiel #2
0
        public void Can_search_by_Zip()
        {
            using (var ravenServer = GetNewServer(requestedStorage: "esent"))
            using (var store = NewRemoteDocumentStore(ravenDbServer:ravenServer))
            {
                CreateTestData(store);

                var fromCutoffDate = DateTime.MaxValue;
                var thruCutoffDate = DateTime.MinValue;
                var searchCriteria = new SearchProviderParamsPto
                                        {
                                            Zip = "WA000",
                                            AddressTypes = new Collection<AddressTypeEnumPto2>
                                                            {
                                                                AddressTypeEnumPto2.PayToAddress,
                                                                AddressTypeEnumPto2.PracticeOfficeAddress,
                                                                AddressTypeEnumPto2.ProviderAddress

                                                            }
                                        };

                using (var session = store.OpenSession())
                {
                    var query = from p in session.Query<ProviderPto2>()
                                where
                                    // Search for Provider Addresses: Zip
                                    (p.AddressesPto.Any(x => x.Address.Zip == searchCriteria.Zip
                                                             && x.Address.AddressTypePto.In(searchCriteria.AddressTypes)))

                                    // ... or PracticeOffice Addresses : Zip
                                    || (p.PracticeOfficesPto.Any(x => x.PrimaryContact.Address.Zip == searchCriteria.Zip
                                                                      &&
                                                                      x.PrimaryContact.Address.AddressTypePto.In(
                                                                        searchCriteria.AddressTypes) &&
                                        // Check PracticeOffice effective dates
                                                                      (x.EffectiveFrom <= fromCutoffDate)
                                                                      &&
                                                                      ((x.EffectiveThrough == null) ||
                                                                       (x.EffectiveThrough >= thruCutoffDate)) &&
                                        // Check Contact effective dates
                                                                      (x.PrimaryContact.ContactEffectiveFrom <= fromCutoffDate) &&
                                                                      ((x.PrimaryContact.ContactEffectiveThrough == null) ||
                                                                       (x.PrimaryContact.ContactEffectiveThrough >= thruCutoffDate)) &&
                                        // Check Contact address effective dates
                                                                      (x.PrimaryContact.AddressEffectiveFrom <= fromCutoffDate) &&
                                                                      ((x.PrimaryContact.AddressEffectiveThrough == null) ||
                                                                       (x.PrimaryContact.AddressEffectiveThrough >= thruCutoffDate))
                                        ))

                                    // ... or Vendor Addresses: Zip
                                    || (p.PayTosPto.Any(x => x.PrimaryContact.Zip == searchCriteria.Zip
                                                             && x.PrimaryContact.AddressTypePto.In(searchCriteria.AddressTypes)))
                                select p;
                    Assert.Equal(1, query.ToArray().Length);
                }
            }
        }