public void TestInitialize()
 {
     this.Error             = null;
     this.LoadOperation     = null;
     this.SubmitOperation   = null;
     this.CityDomainContext = new CityDomainContext(TestURIs.Cities);
 }
示例#2
0
        public void CanLoadIsFalseWhenIsSubmittingChangesIsTrue()
        {
            CityDomainContext context = new CityDomainContext();

            EnqueueCallback(() =>
            {
                this._dds.QueryName     = "GetCities";
                this._dds.AutoLoad      = false;
                this._dds.DomainContext = context;
                this._dds.Load();

                Assert.IsFalse(this._dds.IsSubmittingChanges, "IsSubmittingChanges immediately after Load()");
                Assert.IsTrue(this._dds.CanLoad, "CanLoad immediately after Load()");
            });

            this.AssertLoadingData();

            EnqueueCallback(() =>
            {
                this.ResetLoadState();
                Assert.IsFalse(this._dds.IsSubmittingChanges, "IsSubmittingChanges before submitting changes");
                Assert.IsTrue(this._dds.CanLoad, "CanLoad before submitting changes");

                // Pend up some changes
                this._view.RemoveAt(0);

                this._dds.SubmitChanges();
                Assert.IsTrue(this._dds.IsSubmittingChanges, "IsSubmittingChanges after submitting changes");
                Assert.IsFalse(this._dds.CanLoad, "CanLoad after submitting changes");
            });

            this.AssertSubmittingChanges();

            EnqueueTestComplete();
        }
示例#3
0
        public void Paging()
        {
            CityDomainContext context = new CityDomainContext();

            EnqueueCallback(() =>
            {
                this._dds.QueryName                = "GetCitiesQuery";
                this._dds.DomainContext            = context;
                this._pagedCollectionView.PageSize = 10;
                this._dds.Load();
            });

            this.AssertLoadingData();
            this.AssertPageChanged();

            EnqueueCallback(() =>
            {
                this.ResetLoadState();
                this.ResetPageChanged();

                Assert.AreEqual(10, this._view.Count, "this._ecv.Count should be 10 after the initial load");
                Assert.AreEqual(10, context.Cities.Count, "context.Cities.Count should be 10 after the initial load");

                this._view.MoveToNextPage();
            });

            this.AssertLoadingData();
            this.AssertPageChanged();

            EnqueueCallback(() =>
            {
                this.ResetLoadState();
                this.ResetPageChanged();

                Assert.AreEqual(1, this._view.Count, "this._ecv.Count should be 1 after moving to the 2nd page");
                Assert.AreEqual(11, context.Cities.Count, "context.Cities.Count should be 11 after moving to the 2nd page");

                this._dds.PageSize = 0;
                Assert.AreEqual(0, this._dds.PageSize, "DDS PageSize should immediately reflect 0");
                Assert.AreEqual(0, this._view.PageSize, "this._ecv.PageSize should immediately reflect 0");
                Assert.AreEqual(-1, this._view.PageIndex, "this._ecv.PageIndex should immediately reflect -1");

                this._dds.Load();
            });

            this.AssertLoadingData();
            this.AssertPageChanged();

            EnqueueCallback(() =>
            {
                this.ResetLoadState();
                this.ResetPageChanged();

                Assert.AreEqual(11, this._view.Count, "this._ecv.Count should be 11 after turning off paging and reloading");
                Assert.AreEqual(11, context.Cities.Count, "context.Cities.Count should be 11 after turning off paging and reloading");
                Assert.AreEqual(-1, this._view.PageIndex, "this._ecv.PageIndex should remain -1 after reloading");
            });

            EnqueueTestComplete();
        }
        public void ErrorPipeline_UnauthorizedEx()
        {
            CityDomainContext citiesProvider = new CityDomainContext(TestURIs.Cities);

            SubmitOperation so = null;
            LoadOperation   lo = citiesProvider.Load(citiesProvider.GetZipsQuery(), false);

            // wait for Load to complete, then invoke domain method that throws on server. Submit.
            this.EnqueueCompletion(() => lo);
            EnqueueCallback(delegate
            {
                Zip[] zips = citiesProvider.Zips.ToArray();
                citiesProvider.Zips.Remove(zips[1]);
                so = citiesProvider.SubmitChanges(TestHelperMethods.DefaultOperationAction, null);
            });

            // wait for submitted event being fired and verify submittedEventArgs.Error is not null
            this.EnqueueCompletion(() => so);
            EnqueueCallback(delegate
            {
                DomainOperationException error = so.Error as DomainOperationException;
                Assert.IsNotNull(error);
                Assert.AreEqual(string.Format(Resource.DomainContext_SubmitOperationFailed, "Access to operation 'DeleteZip' was denied."), error.Message);
            });

            EnqueueTestComplete();
        }
        public void ErrorPipeline_DomainServiceEx()
        {
            CityDomainContext citiesProvider = new CityDomainContext(TestURIs.Cities);

            LoadOperation   lo = citiesProvider.Load(citiesProvider.GetZipsQuery(), false);
            SubmitOperation so = null;

            // wait for Load to complete, then invoke domain method that throws on server. Submit.
            this.EnqueueCompletion(() => lo);
            EnqueueCallback(delegate
            {
                Zip zip = citiesProvider.Zips.First();
                zip.ThrowException("DomainServiceExceptionWithErrorCode");
                so = citiesProvider.SubmitChanges(TestHelperMethods.DefaultOperationAction, null);
            });
            this.EnqueueCompletion(() => so);
            EnqueueCallback(delegate
            {
                DomainException ex = so.Error as DomainException;
                Assert.IsNotNull(ex);
                Assert.AreEqual("testing with error code", ex.Message);
                Assert.AreEqual(10, ex.ErrorCode);
            });

            EnqueueTestComplete();
        }
示例#6
0
        public void Submit_POCO_Insert5Cities()
        {
            CityDomainContext dc = new CityDomainContext(TestURIs.Cities);

            for (int i = 1; i <= 5; i++)
            {
                dc.Cities.Add(new City()
                {
                    Name       = "Redmond" + new string('x', i),
                    CountyName = "King",
                    StateName  = "WA"
                });
            }
            SubmitOperation so = dc.SubmitChanges();

            EnqueueConditional(delegate
            {
                return(so.IsComplete);
            });
            EnqueueCallback(delegate
            {
                TestHelperMethods.AssertOperationSuccess(so);
            });
            EnqueueTestComplete();
        }
示例#7
0
        public void InvokeOperation_Basic()
        {
            CityDomainContext cities = new CityDomainContext(TestURIs.Cities);
            InvokeOperation   invoke = null;

            // verify with userstate
            EnqueueCallback(delegate
            {
                invoke = cities.Echo("hello", TestHelperMethods.DefaultOperationAction, "my user state");
            });
            EnqueueConditional(() => invoke.IsComplete);
            EnqueueCallback(delegate
            {
                Assert.IsNull(invoke.Error);
                Assert.AreEqual("Echo", invoke.OperationName);
                Assert.AreEqual(1, invoke.Parameters.Count);
                Assert.AreSame("hello", invoke.Parameters["msg"]);
                Assert.AreEqual("Echo: hello", invoke.Value);
                Assert.AreEqual("my user state", invoke.UserState);
            });

            // verify without userstate
            EnqueueCallback(delegate
            {
                invoke = cities.Echo("hello");
            });
            EnqueueConditional(() => invoke.IsComplete);
            EnqueueCallback(delegate
            {
                Assert.AreEqual(invoke.Value, "Echo: hello");
                Assert.IsNull(invoke.UserState);
            });

            EnqueueTestComplete();
        }
示例#8
0
        public void SubmitAddedWithValidationErrors()
        {
            var ctx = new CityDomainContext(new MockDomainClient());

            foreach (var city in CreateCities(NumEntities))
            {
                ctx.Cities.Add(city);
            }

            try
            {
                var res = ctx.SubmitChanges();
                if (!res.HasError)
                {
                    throw new Exception("Operation should have had erros");
                }
                if (res.IsComplete)
                {
                    throw new Exception("Operation should have completed");
                }
            }
            catch (SubmitOperationException)
            {
            }
        }
        public void Cities_Cities_In_State_Parameterized_Query()
        {
            CityDomainContext dp = new CityDomainContext(TestURIs.Cities);    // Abs URI so runs on desktop too

            LoadOperation lo = dp.Load(dp.GetCitiesInStateQuery("WA"), false);

            this.EnqueueCompletion(() => lo);

            EnqueueCallback(() =>
            {
                if (lo.Error != null)
                {
                    Assert.Fail("LoadOperation.Error: " + lo.Error.Message);
                }
                IEnumerable <City> expected = new CityData().Cities.Where(c => c.StateName.Equals("WA"));
                AssertSame(expected, dp.Cities);

                // Validate a [Editable(false)] property deserialized properly
                foreach (City c in dp.Cities)
                {
                    Assert.AreEqual(c.CountyName, c.CalculatedCounty);
                }
            });

            EnqueueTestComplete();
        }
        public void LoadAndMergeEntities()
        {
            var cities1 = CreateValidCities(NumEntities);
            var cities2 = CreateValidCities(NumEntities);

            var mockDomainClient = new MockDomainClient();
            var ctx = new CityDomainContext(mockDomainClient);

            mockDomainClient.SetQueryResult(cities1);
            var res = ctx.Load(ctx.GetCitiesQuery(), true);

            if (res.HasError)
            {
                throw new Exception("Operation should not have had erros");
            }
            if (!res.IsComplete)
            {
                throw new Exception("Operation should have completed");
            }

            mockDomainClient.SetQueryResult(cities2);
            res = ctx.Load(ctx.GetCitiesQuery(), LoadBehavior.MergeIntoCurrent, true);
            if (res.HasError)
            {
                throw new Exception("Operation should not have had erros");
            }
            if (!res.IsComplete)
            {
                throw new Exception("Operation should have completed");
            }
        }
示例#11
0
        public void InvokeOperation_TestPropertyChangeNotifications()
        {
            CityDomainContext cities        = new CityDomainContext(TestURIs.Cities);
            InvokeOperation   invoke        = null;
            List <string>     notifications = new List <string>();

            // verify with userstate
            EnqueueCallback(delegate
            {
                invoke = cities.Echo("hello", TestHelperMethods.DefaultOperationAction, "my user state");

                ((System.ComponentModel.INotifyPropertyChanged)invoke).PropertyChanged += (s, e) =>
                {
                    notifications.Add(e.PropertyName);
                };
            });
            EnqueueConditional(() => invoke.IsComplete);
            EnqueueCallback(delegate
            {
                Assert.IsFalse(invoke.HasError);
                Assert.AreEqual("Echo: hello", invoke.Value);

                Assert.AreEqual(3, notifications.Count);
                Assert.AreEqual("IsComplete", notifications[0]);
                Assert.AreEqual("CanCancel", notifications[1]);
                Assert.AreEqual("Value", notifications[2]);
            });

            EnqueueTestComplete();
        }
示例#12
0
        public void UnhandledSubmitOperationError()
        {
            CityDomainContext cities = new CityDomainContext(TestURIs.Cities);
            CityData          data   = new CityData();

            cities.Cities.LoadEntities(data.Cities.ToArray());

            City city = cities.Cities.First();

            city.ZoneID = 1;
            Assert.IsTrue(cities.EntityContainer.HasChanges);

            SubmitOperation submit = new SubmitOperation(cities.EntityContainer.GetChanges(), null, null, false);

            DomainOperationException expectedException = null;
            DomainOperationException ex = new DomainOperationException("Submit Failed!", OperationErrorStatus.ServerError, 42, "StackTrace");

            try
            {
                submit.SetError(ex);
            }
            catch (DomainOperationException e)
            {
                expectedException = e;
            }

            // verify the exception properties
            Assert.AreSame(expectedException, ex);
            Assert.AreEqual(false, submit.IsErrorHandled);
        }
        public void DomainContext_Submit_ErrorsClearOnReject()
        {
            int refZip = 0;
            CityDomainContext citiesProvider = new CityDomainContext(TestURIs.Cities);

            SubmitOperation so = null;
            LoadOperation   lo = citiesProvider.Load(citiesProvider.GetZipsQuery(), false);

            // wait for Load to complete, then invoke domain method that throws on server. Submit.
            this.EnqueueCompletion(() => lo);
            EnqueueCallback(delegate
            {
                // invoke methods that cause exception
                Zip[] zips = citiesProvider.Zips.ToArray();
                zips[0].ThrowException("ValidationException");
                so = citiesProvider.SubmitChanges(TestHelperMethods.DefaultOperationAction, null);
            });

            // wait for submitted event being fired and verify Entity.ValidationErrors is not empty
            this.EnqueueCompletion(() => so);
            EnqueueCallback(delegate
            {
                DomainOperationException ex = so.Error as DomainOperationException;
                Assert.IsNotNull(ex);

                Zip zip = citiesProvider.Zips.First();
                IEnumerable <ValidationResult> errors = zip.ValidationErrors;
                LogErrorListContents("zips[0].ValidationErrors", errors);
                Assert.AreEqual(1, errors.Count());

                // Verify that failed submission does not clear out the last invocation
                Assert.IsFalse(zip.CanThrowException);
                Assert.IsTrue(zip.EntityActions.Any(a => a.Name == "ThrowException"));

                // Add a custom validation error to ensure it gets cleared
                zip.ValidationErrors.Add(new ValidationResult("Temporary Error"));

                // Call RejectChanges and verify ValidationErrors collection is cleared
                citiesProvider.RejectChanges();
                Assert.IsFalse(zip.ValidationErrors.Any());

                // Invoke domain method that does not throw on same entity
                zip.ReassignZipCode(1, true);
                refZip = zip.Code;
                so     = citiesProvider.SubmitChanges(TestHelperMethods.DefaultOperationAction, null);
            });

            // wait for submitted event being fired and verify Entity.ValidationErrors remains empty
            this.EnqueueCompletion(() => so);
            EnqueueCallback(delegate
            {
                Zip zip = citiesProvider.Zips.First();
                Assert.IsNull(so.Error);
                Assert.IsFalse(zip.ValidationErrors.Any());
                Assert.AreEqual(refZip + 1, zip.Code);
            });

            EnqueueTestComplete();
        }
示例#14
0
        public void Query_MaximumUriLengthExceeded()
        {
            Thread.CurrentThread.CurrentCulture = new CultureInfo("tr-TR");
            CityDomainContext dc = new CityDomainContext(GenerateUriBase(1000)); // --> the length when localized to Turkish is > 2083

            ExceptionHelper.ExpectException <InvalidOperationException>(() => dc.Load(dc.GetCitiesQuery()),
                                                                        String.Format(SSmDsWeb::OpenRiaServices.DomainServices.Client.Resource.WebDomainClient_MaximumUriLengthExceeded, 2083));
        }
        public void NoOp()
        {
            var cities1 = CreateValidCities(NumEntities);
            var cities2 = CreateValidCities(NumEntities);

            var mockDomainClient = new MockDomainClient();
            var ctx = new CityDomainContext(mockDomainClient);

            mockDomainClient.SetQueryResult(cities1);
            mockDomainClient.SetQueryResult(cities2);
        }
示例#16
0
        public void ExogenousDomainClient()
        {
            Cities.CityDomainContext ctxt1 = new CityDomainContext(TestURIs.Cities);
            Cities.CityDomainContext ctxt2 = new CityDomainContext(TestURIs.Cities);

            var q1 = ctxt1.GetCitiesInStateQuery("OH");

            ExceptionHelper.ExpectInvalidOperationException(delegate
            {
                ctxt2.Load(q1, false);
            }, string.Format(Resource.DomainContext_InvalidEntityQueryDomainClient, q1.QueryName));
        }
        public void Inherit_Run_CUD_Update_Derived()
        {
            // Inheritance is City <-- CityWithEditHistory <-- CityWithInfo
            CityDomainContext citiesContext    = new CityDomainContext(TestURIs.Cities);
            DateTime          priorLastUpdated = DateTime.Now;

            // Load all cities, not just derived ones
            LoadOperation   lo                 = citiesContext.Load(citiesContext.GetCitiesQuery());
            SubmitOperation so                 = null;
            CityWithInfo    cityWithInfo       = null;
            string          originalName       = null;
            string          originalStateName  = null;
            string          originalCountyName = null;

            // wait for Load to complete
            EnqueueConditional(() => lo.IsComplete);

            EnqueueCallback(delegate
            {
                cityWithInfo = citiesContext.Cities.OfType <CityWithInfo>().FirstOrDefault();
                Assert.IsNotNull(cityWithInfo, "expected to find at least one CityWithInfo entity");
                Assert.IsFalse(cityWithInfo.EditHistory.Contains("update"), "Did not expect edit history to be set yet.");

                originalName       = cityWithInfo.Name;
                originalStateName  = cityWithInfo.StateName;
                originalCountyName = cityWithInfo.CountyName;

                cityWithInfo.Info = "inserted new info";

                so = citiesContext.SubmitChanges();
            });
            // wait for submit to complete
            EnqueueConditional(() => so.IsComplete);
            EnqueueCallback(delegate
            {
                if (so.Error != null)
                {
                    Assert.Fail("Unexpected error on submit: " + so.Error.Message);
                }

                // verify entities are auto-synced back to the client as a result of the domain method execution on server
                CityWithInfo updatedCity = citiesContext.Cities.OfType <CityWithInfo>().SingleOrDefault <CityWithInfo>
                                               (c => (c.Name == originalName &&
                                                      c.StateName == originalStateName &&
                                                      c.CountyName == originalCountyName));
                Assert.IsNotNull(updatedCity, "Did not find modified City after the submit");
                Assert.IsTrue(updatedCity.EditHistory.Contains("update"), "EditHistory was" + updatedCity.EditHistory);
                Assert.AreEqual("inserted new info", updatedCity.Info, "Updated Info did not get applied");
            });

            EnqueueTestComplete();
        }
示例#18
0
        public void PagingPastEndSkippingLastPageUnknownTotalItemCount()
        {
            CityDomainContext context = new CityDomainContext();

            EnqueueCallback(() =>
            {
                this._dds.PageSize      = 6;
                this._dds.QueryName     = "GetCitiesQuery";
                this._dds.DomainContext = context;
                this._dds.Load();
            });

            this.AssertLoadingData();
            this.AssertPageChanged();

            Action <string> verifyFirstPageLoaded = (string message) =>
            {
                Assert.AreEqual(6, this._view.Count, message);
                Assert.AreEqual(0, this._view.PageIndex, message);
                Assert.AreEqual("Redmond", (this._view[0] as City).Name, message);
                Assert.AreEqual("Bellevue", (this._view[1] as City).Name, message);
                Assert.AreEqual("Duvall", (this._view[2] as City).Name, message);
                Assert.AreEqual("Carnation", (this._view[3] as City).Name, message);
                Assert.AreEqual("Everett", (this._view[4] as City).Name, message);
                Assert.AreEqual("Tacoma", (this._view[5] as City).Name, message);
            };

            EnqueueCallback(() =>
            {
                this.ResetLoadState();
                this.ResetPageChanged();

                verifyFirstPageLoaded("First load");

                this._view.MoveToPage(5);
            });

            // Attempt to load the non-existent page, then load the first page
            this.AssertLoadingData(2);
            this.AssertNoPageChanged();

            EnqueueCallback(() =>
            {
                this.ResetLoadState();
                this.ResetPageChanged();

                verifyFirstPageLoaded("After paging past the end");
            });

            EnqueueTestComplete();
        }
示例#19
0
        public void PagingPastEndTwiceCancelsSecondLoad()
        {
            CityDomainContext context = new CityDomainContext();
            int pageSize      = 6;
            int cityCount     = new CityData().Cities.Count;
            int lastPageIndex = (cityCount / pageSize) - ((cityCount % pageSize == 0) ? 1 : 0);

            EnqueueCallback(() =>
            {
                this._dds.PageSize      = pageSize;
                this._dds.QueryName     = "GetCitiesQuery";
                this._dds.DomainContext = context;
                this._dds.Load();
            });

            this.AssertLoadingData();
            this.AssertPageChanged();

            EnqueueCallback(() =>
            {
                this.ResetLoadState();
                this.ResetPageChanged();

                // We need to make sure the second load caused by paging past the last page is cancelable.
                // To do this, we'll load 4 times. The first is caused by moving past the last page. The second
                // is automatically started when the first load does not return any entities and shifts back to
                // the last page. The third and fourth move past and back again and are started such that the
                // third load cancels the second.
                this._dds.LoadingData += (sender, e) =>
                {
                    // We only want to reload once to cancel the second load attempt
                    if (this._ddsLoadingData == 2)
                    {
                        this._view.MoveToPage(lastPageIndex + 2);
                    }
                };
                this._dds.LoadedData += (sender, e) =>
                {
                    Assert.IsTrue((this._ddsLoadedData == 2) == e.Cancelled,
                                  "Only the second load should have been canceled.");
                };

                this._view.MoveToPage(lastPageIndex + 1);
            });

            this.AssertLoadingData(4);

            EnqueueTestComplete();
        }
示例#20
0
        public void Query_POCO_AllCities()
        {
            CityDomainContext dc = new CityDomainContext(TestURIs.Cities);

            var           query = dc.GetCitiesQuery();
            LoadOperation lo    = dc.Load(query, false);

            this.EnqueueCompletion(() => lo);
            EnqueueCallback(delegate
            {
                TestHelperMethods.AssertOperationSuccess(lo);
                Assert.IsTrue(lo.Entities.Count() > 0);
            });
            EnqueueTestComplete();
        }
示例#21
0
        public void CanLoadIsFalseWhenHasChangesIsTrue()
        {
            CityDomainContext context = this.LoadCities();

            EnqueueCallback(() =>
            {
                City city = context.Cities.First();
                context.Cities.Remove(city);

                Assert.IsTrue(this._dds.HasChanges);
                Assert.IsFalse(this._dds.CanLoad);
            });

            EnqueueTestComplete();
        }
示例#22
0
        public void SubmitAdded()
        {
            var ctx = new CityDomainContext(new MockDomainClient());

            foreach (var city in CreateValidCities(NumEntities))
            {
                ctx.Cities.Add(city);
            }

            var res = ctx.SubmitChanges();

            if (!res.IsComplete)
            {
                throw new Exception("Operation should have completed");
            }
        }
示例#23
0
        //    [Benchmark]
        public async Task Submit()
        {
            CityDomainContext ctx = new CityDomainContext(_clientUri);

            foreach (var city in ChangeSetBenchmarks.CreateValidCities(NumEntities))
            {
                ctx.Cities.Add(city);
            }

            var res = await ctx.SubmitChangesAsync().ConfigureAwait(false);

            if (res.ChangeSet.AddedEntities.Count != NumEntities)
            {
                throw new Exception("Operation should have completed");
            }
        }
        public void Cities_ShouldSupportLongQueries()
        {
            LoadOperation <Zip> lo               = null;
            const int           zipToFind        = 98053;
            const int           QUERY_ITERATIONS = 50;

            EnqueueCallback(() =>
            {
                CityDomainContext dp = new CityDomainContext(TestURIs.Cities);    // Abs URI so runs on desktop too

                // Generate a really long query
                // The load will result in a query where just the query part has length > 3000
                var query = dp.GetZipsQuery();

                // Create a query with QUERY_ITERATIONS where statements checking a range of QUERY_ITERATIONS each
                // this should in the end if simplified result in Code = zipToFind (zipToFind - 1 < Code  <= zipToFind)
                for (int i = 0; i < QUERY_ITERATIONS; ++i)
                {
                    int min = zipToFind + i - QUERY_ITERATIONS;
                    int max = zipToFind + i;
                    query   = query.Where(c => min < c.Code && c.Code <= max);
                }

                lo = dp.Load(query, false);
            });

            this.EnqueueCompletion(() => lo);

            EnqueueCallback(() =>
            {
                if (lo.Error != null)
                {
                    Assert.Fail("LoadOperation.Error: " + lo.Error.Message);
                }
                var expected = new CityData().Zips.Single(z => z.Code == zipToFind);
                Assert.AreEqual(1, lo.Entities.Count(), "Wrong number of entities returned");
                var returned = lo.Entities.Single();

                Assert.AreEqual(expected.Code, returned.Code);
                Assert.AreEqual(expected.FourDigit, returned.FourDigit);
                Assert.AreEqual(expected.CityName, returned.CityName);
                Assert.AreEqual(expected.CountyName, returned.CountyName);
                Assert.AreEqual(expected.StateName, returned.StateName);
            });
            EnqueueTestComplete();
        }
示例#25
0
        public void Bug706034_AccessCachedEntityResultsInCallback()
        {
            Cities.CityDomainContext cities = new CityDomainContext(TestURIs.Cities);

            bool      callbackCalled                = false;
            Exception callbackException             = null;
            Action <LoadOperation <City> > callback = (op) =>
            {
                if (op.HasError)
                {
                    op.MarkErrorAsHandled();
                }

                try
                {
                    Assert.AreEqual(11, op.AllEntities.Count());
                    Assert.AreEqual(11, op.Entities.Count());
                }
                catch (Exception e)
                {
                    callbackException = e;
                }
                finally
                {
                    callbackCalled = true;
                }
            };

            var q = cities.GetCitiesQuery();
            LoadOperation <City> lo = cities.Load(q, callback, null);

            // KEY to bug : access Entity collections to force them to cache
            IEnumerable <City>   entities    = lo.Entities;
            IEnumerable <Entity> allEntities = lo.AllEntities;

            EnqueueConditional(() => lo.IsComplete && callbackCalled);
            EnqueueCallback(delegate
            {
                Assert.IsNull(callbackException);
                Assert.IsNull(lo.Error);

                Assert.AreEqual(11, lo.AllEntities.Count());
                Assert.AreEqual(11, lo.Entities.Count());
            });
            EnqueueTestComplete();
        }
示例#26
0
        public void Query_ShouldSupportLongQueries()
        {
            LoadOperation <Zip> op               = null;
            Exception           error            = null;
            const int           zipToFind        = 98053;
            const int           QUERY_ITERATIONS = 50;

            this.EnqueueCallback(() =>
            {
                this.CreateDomainContext();

                // Generate a really long query
                // The load will result in a query where just the query part has length > 3000
                var query = CityDomainContext.GetZipsQuery();

                // Create a query with QUERY_ITERATIONS where statements checking a range of QUERY_ITERATIONS each
                // this should in the end if simplified result in Code = zipToFind (zipToFind - 1 < Code  <= zipToFind)
                for (int i = 0; i < QUERY_ITERATIONS; ++i)
                {
                    int min = zipToFind + i - QUERY_ITERATIONS;
                    int max = zipToFind + i;
                    query   = query.Where(c => min < c.Code && c.Code <= max);
                }

                op = this.CityDomainContext.Load(query,
                                                 (lo) => WebDomainClientTests.HandleError(lo, ref error),
                                                 null);
            });
            this.EnqueueConditional(() => op.IsComplete);
#if SILVERLIGHT
            this.EnqueueCallback(() =>
            {
                // The query should match a single zip
                //new Zip() { Code=98053, FourDigit=8625, CityName="Redmond", CountyName="King", StateName="WA" },
                Assert.IsFalse(op.HasError, string.Format("The query returned the following error: {0}", op.Error));
                Assert.AreEqual(1, op.Entities.Count(), "A single entity was expected");

                var zip = op.Entities.First();
                Assert.AreEqual(zipToFind, zip.Code, "A single entity was expected");
                Assert.AreEqual(8625, zip.FourDigit);
                Assert.AreEqual("Redmond", zip.CityName);
            });
#endif
            this.EnqueueTestComplete();
        }
示例#27
0
        public void UnhandledInvokeOperationError()
        {
            CityDomainContext cities = new CityDomainContext(TestURIs.Cities);

            InvokeOperation invoke = new InvokeOperation("Echo", null, null, null, null);

            DomainOperationException expectedException = null;
            DomainOperationException ex = new DomainOperationException("Operation Failed!", OperationErrorStatus.ServerError, 42, "StackTrace");

            try
            {
                invoke.Complete(ex);
            }
            catch (DomainOperationException e)
            {
                expectedException = e;
            }

            // verify the exception properties
            Assert.IsNotNull(expectedException);
            Assert.AreEqual(string.Format(Resource.DomainContext_InvokeOperationFailed, "Echo", ex.Message), expectedException.Message);
            Assert.AreEqual(ex.StackTrace, expectedException.StackTrace);
            Assert.AreEqual(ex.Status, expectedException.Status);
            Assert.AreEqual(ex.ErrorCode, expectedException.ErrorCode);

            Assert.AreEqual(false, invoke.IsErrorHandled);

            // now test again with validation errors
            expectedException = null;
            ValidationResult[] validationErrors = new ValidationResult[] { new ValidationResult("Foo", new string[] { "Bar" }) };
            invoke = new InvokeOperation("Echo", null, null, null, null);

            try
            {
                invoke.Complete(validationErrors);
            }
            catch (DomainOperationException e)
            {
                expectedException = e;
            }

            // verify the exception properties
            Assert.IsNotNull(expectedException);
            Assert.AreEqual(string.Format(Resource.DomainContext_InvokeOperationFailed_Validation, "Echo"), expectedException.Message);
        }
示例#28
0
        public void Query_POCO_NoResults()
        {
            CityDomainContext dc = new CityDomainContext(TestURIs.Cities);

            var           query = dc.GetCitiesQuery().Where(c => c.Name == "-");
            LoadOperation lo    = dc.Load(query, false);

            EnqueueConditional(delegate
            {
                return(lo.IsComplete);
            });
            EnqueueCallback(delegate
            {
                TestHelperMethods.AssertOperationSuccess(lo);
                Assert.IsTrue(lo.Entities.Count() == 0);
            });
            EnqueueTestComplete();
        }
        public void Cities_VerifyCustomHost()
        {
            CityDomainContext dp = new CityDomainContext(TestURIs.Cities);    // Abs URI so runs on desktop too

            InvokeOperation <bool> invokeOp = dp.UsesCustomHost(TestHelperMethods.DefaultOperationAction, null);

            this.EnqueueCompletion(() => invokeOp);

            EnqueueCallback(() =>
            {
                if (invokeOp.Error != null)
                {
                    Assert.Fail("InvokeOperation.Error: " + invokeOp.Error.Message);
                }
                Assert.IsTrue(invokeOp.Value, "CityDomainService isn't using a custom host.");
            });

            EnqueueTestComplete();
        }
        public void DomainContext_Submit_ValidationErrorOnServer()
        {
            CityDomainContext citiesProvider = new CityDomainContext(TestURIs.Cities);
            Zip newZip = null;

            SubmitOperation so = null;
            LoadOperation   lo = citiesProvider.Load(citiesProvider.GetZipsQuery(), false);

            // wait for Load to complete, then invoke domain method that throws on server. Submit.
            this.EnqueueCompletion(() => lo);
            EnqueueCallback(delegate
            {
                // Add an entity that will cause a Validation exception on the server (99999 is used as a way to signal failure for our validator)
                newZip = new Zip()
                {
                    Code       = 99999,
                    FourDigit  = 8625,
                    CityName   = "Redmond",
                    CountyName = "King",
                    StateName  = "WA"
                };
                citiesProvider.Zips.Add(newZip);
                newZip.ThrowException("InvalidOperationException");

                so = citiesProvider.SubmitChanges(TestHelperMethods.DefaultOperationAction, null);
            });

            this.EnqueueCompletion(() => so);
            EnqueueCallback(delegate
            {
                DomainOperationException ex = so.Error as DomainOperationException;
                Assert.IsNotNull(ex);
                Assert.AreEqual(OperationErrorStatus.ValidationFailed, ex.Status);
                Assert.AreEqual(Resource.DomainContext_SubmitOperationFailed_Validation, ex.Message);

                IEnumerable <ValidationResult> errors = newZip.ValidationErrors;
                LogErrorListContents("newZip.ValidationErrors", errors);
                Assert.AreEqual(1, errors.Count());
                UnitTestHelper.AssertListContains <ValidationResult>(errors, (e => e.ErrorMessage == "Server fails validation"));
            });

            EnqueueTestComplete();
        }