Exemple #1
0
        public void ServerValidation_InvokeOperation()
        {
            TestDomainServices.TestProvider_Scenarios ctxt = new TestDomainServices.TestProvider_Scenarios(TestURIs.TestProvider_Scenarios);

            // Validate using an action so we can assert state for each of the 3 different
            // completion patterns; callback, event, and polling
            Action <InvokeOperation <bool> > validate = (io) =>
            {
                Assert.IsNotNull(io.Error);
                Assert.AreEqual(typeof(DomainOperationException), io.Error.GetType());
                Assert.AreEqual(OperationErrorStatus.ValidationFailed, ((DomainOperationException)io.Error).Status);
                Assert.AreEqual(string.Format(Resource.DomainContext_InvokeOperationFailed_Validation, "InvokeOperationWithParamValidation"), io.Error.Message);
                Assert.AreEqual(1, io.ValidationErrors.Count(),
                                "There should be 1 validation error.");
                ValidationResult error = io.ValidationErrors.Single();
                Assert.AreEqual("Server validation exception thrown!", error.ErrorMessage);
                io.MarkErrorAsHandled();
            };

            InvokeOperation <bool> op = ctxt.InvokeOperationWithParamValidation(5, "ex", new CityWithCacheData(), validate, null);

            op.Completed += (sender, e) =>
            {
                validate((InvokeOperation <bool>)sender);
            };

            this.EnqueueCompletion(() => op);
            EnqueueCallback(delegate
            {
                validate(op);
            });

            EnqueueTestComplete();
        }
Exemple #2
0
        public void ClientValidation_InvokeOperation()
        {
            TestDomainServices.TestProvider_Scenarios ctxt = new TestDomainServices.TestProvider_Scenarios(TestURIs.TestProvider_Scenarios);

            ExceptionHelper.ExpectValidationException(delegate
            {
                ctxt.InvokeOperationWithParamValidation(-3, "ABC", new CityWithCacheData());
            }, "The field a must be between 0 and 10.", typeof(RangeAttribute), -3);

            EnqueueTestComplete();
        }
Exemple #3
0
        public void InvokeOperationWithNoSideEffects_IEnumerableParameters()
        {
            TestDomainServices.TestProvider_Scenarios ctxt = new TestDomainServices.TestProvider_Scenarios(TestURIs.TestProvider_Scenarios);

            TestEntityForInvokeOperations[] list = new TestEntityForInvokeOperations[]
            {
                new TestEntityForInvokeOperations()
                {
                    Key = 1, StrProp = "Str1", CTProp = new TestCT()
                    {
                        CTProp1 = 11, CTProp2 = "CtStr1"
                    }
                },
                new TestEntityForInvokeOperations()
                {
                    Key = 2, StrProp = "Str1", CTProp = new TestCT()
                    {
                        CTProp1 = 22, CTProp2 = "CtStr2"
                    }
                },
                new TestEntityForInvokeOperations()
                {
                    Key = 3, StrProp = "Str1", CTProp = new TestCT()
                    {
                        CTProp1 = 33, CTProp2 = "CtStr3"
                    }
                }
            };

            InvokeOperation <IEnumerable <TestEntityForInvokeOperations> > invoke = ctxt.InvokeOpWithIEnumerableParamAndNoSideEffects(list.AsEnumerable());

            EnqueueConditional(() => invoke.IsComplete);
            EnqueueCallback(delegate
            {
                IEnumerable <TestEntityForInvokeOperations> result = invoke.Value;
                Assert.IsNotNull(result);
                Assert.AreEqual(result.Count(), 3);

                TestEntityForInvokeOperations[] resultArray = result.ToArray();
                for (int i = 0; i < 3; i++)
                {
                    Assert.AreEqual(list[i].Key, resultArray[i].Key);
                    Assert.AreEqual(list[i].StrProp, resultArray[i].StrProp);
                    Assert.AreEqual(list[i].CTProp.CTProp1, resultArray[i].CTProp.CTProp1);
                    Assert.AreEqual(list[i].CTProp.CTProp2, resultArray[i].CTProp.CTProp2);
                }
            });
            EnqueueTestComplete();
        }
Exemple #4
0
        [WorkItem(196039)]  // CSDMain
        public void InvokeOperation_RoundtripDouble()
        {
            TestDomainServices.TestProvider_Scenarios ctxt = new TestDomainServices.TestProvider_Scenarios(TestURIs.TestProvider_Scenarios);

            Double d = Double.Parse("9.2233720368547758E+18");

            InvokeOperation <double> invoke = ctxt.RoundtripDouble(d);

            EnqueueConditional(() => invoke.IsComplete);
            EnqueueCallback(delegate
            {
                double result = invoke.Value;
                Assert.AreEqual(d, result);
            });
            EnqueueTestComplete();
        }
        public void DomainContext_Load_SelectMethodThrows()
        {
            TestProvider_Scenarios provider = new TestProvider_Scenarios(TestURIs.TestProvider_Scenarios);

            LoadOperation lo = provider.Load(provider.GetMixedTypesThrowQuery(), false);

            EnqueueConditional(() => lo.IsComplete);
            EnqueueCallback(delegate
            {
                Assert.IsNotNull(lo.Error);

                // verify we propagate the top level exception message as well
                // as the inner exception message (to one level deep)
                Assert.IsTrue(lo.Error.Message.Contains("Not implemented yet."));
                Assert.IsTrue(lo.Error.Message.Contains("InnerException1"));
                Assert.IsFalse(lo.Error.Message.Contains("InnerException2"));
            });

            EnqueueTestComplete();
        }
        private void ExecuteQuery(Func<TestProvider_Scenarios, EntityQuery<CityWithCacheData>> getQuery, string expectedCacheData)
        {
            LoadOperation<CityWithCacheData> loadOp = null;
            EnqueueCallback(delegate
            {
                TestProvider_Scenarios dc = new TestProvider_Scenarios(TestURIs.TestProvider_Scenarios);
                loadOp = dc.Load(getQuery(dc));
            });

            EnqueueConditional(() => loadOp.IsComplete);
            EnqueueCallback(delegate
            {
                if (loadOp.Error != null)
                {
                    Assert.Fail(loadOp.Error.ToString());
                }

                CityWithCacheData city = loadOp.Entities.First();
                Assert.AreEqual(expectedCacheData, city.CacheData, "Incorrect cache data");
            });
        }
        [FullTrustTest] // ISerializable types cannot be deserialized in medium trust.
        public void DomainMethod_NullableTypes_NullParams()
        {
            TestProvider_Scenarios provider = new TestProvider_Scenarios(TestURIs.TestProvider_Scenarios);
            MixedType obj1 = null;
            MixedType obj2 = null;

            SubmitOperation so = null;
            LoadOperation lo = provider.Load(provider.GetMixedTypesQuery(), false);

            // wait for Load to complete, then invoke some domain methods
            EnqueueConditional(() => lo.IsComplete);
            EnqueueCallback(delegate
            {
                Assert.AreEqual(3, lo.Entities.Count(), "Entities count should be 3");
                obj1 = provider.MixedTypes.Single(t => t.ID == "MixedType_Min");
                obj2 = provider.MixedTypes.Single(t => t.ID == "MixedType_Other");

                // invoke domain methods with null values
                obj1.TestNullablePrimitive(null, null, null, null, null, null, null, null, null, null, null, null);
                obj2.TestNullablePredefined(null, null, null, null, null, null);

                // submit
                so = provider.SubmitChanges(TestHelperMethods.DefaultOperationAction, null);
            });

            // wait for submitted event being fired and verify invoked entities in changeset
            EnqueueConditional(() => so.IsComplete);
            EnqueueCallback(delegate
            {
                Assert.IsNull(so.Error);

                // verify values of obj1 and obj2
                Assert.IsNull(obj1.NullableBooleanProp);
                Assert.IsNull(obj1.NullableByteProp);
                Assert.IsNull(obj1.NullableSByteProp);
                Assert.IsNull(obj1.NullableInt16Prop);
                Assert.IsNull(obj1.NullableUInt16Prop);
                Assert.IsNull(obj1.NullableInt32Prop);
                Assert.IsNull(obj1.NullableUInt32Prop);
                Assert.IsNull(obj1.NullableInt64Prop);
                Assert.IsNull(obj1.NullableUInt64Prop);
                Assert.IsNull(obj1.NullableCharProp);
                Assert.IsNull(obj1.NullableDoubleProp);
                Assert.IsNull(obj1.NullableSingleProp);
                Assert.IsNotNull(obj1.NullableDateTimeProp);

                Assert.IsNull(obj2.NullableDateTimeProp);
                Assert.IsNull(obj2.NullableTimeSpanProp);
                Assert.IsNull(obj2.NullableDecimalProp);
                Assert.IsNull(obj2.NullableGuidProp);
                Assert.IsNull(obj2.NullableEnumProp);
                Assert.IsNotNull(obj2.NullableBooleanProp);
                Assert.IsNull(obj2.NullableDateTimeOffsetProp);
            });

            EnqueueTestComplete();
        }
        [FullTrustTest] // ISerializable types cannot be deserialized in medium trust.
        public void DomainMethod_NullablePredefinedTypes()
        {
            TestProvider_Scenarios provider = new TestProvider_Scenarios(TestURIs.TestProvider_Scenarios);
            MixedType changedObj = null;
            MixedType valuesObj = null;

            SubmitOperation so = null;
            LoadOperation lo = provider.Load(provider.GetMixedTypesQuery(), false);

            // wait for Load to complete, then invoke some domain methods
            EnqueueConditional(() => lo.IsComplete);
            EnqueueCallback(delegate
            {
                Assert.AreEqual(3, lo.Entities.Count(), "Entities count should be 3");
                changedObj = provider.MixedTypes.Single(t => t.ID == "MixedType_Max");
                valuesObj = provider.MixedTypes.Single(t => t.ID == "MixedType_Other");

                // invoke domain method on changedObj with values from valuesObj
                changedObj.TestNullablePredefined(valuesObj.NullableDecimalProp, valuesObj.NullableDateTimeProp,
                    valuesObj.NullableTimeSpanProp, valuesObj.NullableGuidProp, valuesObj.NullableEnumProp, valuesObj.NullableDateTimeOffsetProp);

                // submit
                so = provider.SubmitChanges(TestHelperMethods.DefaultOperationAction, null);
            });

            // wait for submitted event being fired and verify invoked entities in changeset
            EnqueueConditional(() => so.IsComplete);
            EnqueueCallback(delegate
            {
                Assert.IsNull(so.Error);

                // verify values of changedObj are now the same as valuesObj
                Assert.AreNotEqual(valuesObj.ID, changedObj.ID);
                Assert.AreEqual(valuesObj.NullableDateTimeProp, changedObj.NullableDateTimeProp);
                Assert.AreEqual(valuesObj.NullableTimeSpanProp, changedObj.NullableTimeSpanProp);
                Assert.AreEqual(valuesObj.NullableDecimalProp, changedObj.NullableDecimalProp);
                Assert.AreEqual(valuesObj.NullableGuidProp, changedObj.NullableGuidProp);
                Assert.AreEqual(valuesObj.NullableEnumProp, changedObj.NullableEnumProp);
                Assert.AreEqual(valuesObj.NullableDateTimeOffsetProp, changedObj.NullableDateTimeOffsetProp);
            });

            EnqueueTestComplete();
        }
        [FullTrustTest] // ISerializable types cannot be deserialized in medium trust.
        public void DomainMethod_PredefinedTypes()
        {
            TestProvider_Scenarios provider = new TestProvider_Scenarios(TestURIs.TestProvider_Scenarios);
            MixedType changedObj = null;
            MixedType valuesObj = null;

            SubmitOperation so = null;
            LoadOperation lo = provider.Load(provider.GetMixedTypesQuery(), false);

            // wait for Load to complete, then invoke some domain methods
            EnqueueConditional(() => lo.IsComplete);
            EnqueueCallback(delegate
            {
                Assert.AreEqual(3, lo.Entities.Count(), "Entities count should be 3");
                changedObj = provider.MixedTypes.Single(t => t.ID == "MixedType_Max");
                valuesObj = provider.MixedTypes.Single(t => t.ID == "MixedType_Other");

                // invoke domain method on changedObj with values from valuesObj
                changedObj.TestPredefined(valuesObj.StringProp, valuesObj.DecimalProp, valuesObj.DateTimeProp,
                    valuesObj.TimeSpanProp, valuesObj.StringsProp, valuesObj.UriProp, valuesObj.GuidProp, valuesObj.BinaryProp,
                    /*valuesObj.XElementProp,*/ valuesObj.ByteArrayProp, valuesObj.EnumProp, valuesObj.DictionaryStringProp, valuesObj.DateTimeOffsetProp);

                // submit
                so = provider.SubmitChanges(TestHelperMethods.DefaultOperationAction, null);
            });

            // wait for submitted event being fired and verify invoked entities in changeset
            EnqueueConditional(() => so.IsComplete);
            EnqueueCallback(delegate
            {
                Assert.IsNull(so.Error);

                // verify values of changedObj are now the same as valuesObj
                Assert.AreNotEqual(valuesObj.ID, changedObj.ID);
                Assert.AreEqual(valuesObj.StringProp, changedObj.StringProp);
                Assert.AreEqual(valuesObj.DateTimeProp, changedObj.DateTimeProp);
                Assert.AreEqual(valuesObj.TimeSpanProp, changedObj.TimeSpanProp);
                Assert.AreEqual(valuesObj.DecimalProp, changedObj.DecimalProp);
                Assert.AreEqual(valuesObj.UriProp, changedObj.UriProp);
                Assert.AreEqual(valuesObj.GuidProp, changedObj.GuidProp);
                Assert.AreEqual(valuesObj.ByteArrayProp.Length, changedObj.ByteArrayProp.Length);
                Assert.AreEqual(123, changedObj.BinaryProp[2]);
                Assert.AreEqual(valuesObj.BinaryProp.Length, changedObj.BinaryProp.Length);
                //Assert.AreEqual(valuesObj.XElementProp.Value, changedObj.XElementProp.Value);
                //Assert.AreEqual("<someElement>element text</someElement>", changedObj.XElementProp.ToString());
                Assert.AreEqual(valuesObj.EnumProp, changedObj.EnumProp);
                Assert.AreEqual(valuesObj.DictionaryStringProp.Count, changedObj.DictionaryStringProp.Count);
                Assert.IsTrue(valuesObj.DictionaryStringProp.Keys.SequenceEqual(changedObj.DictionaryStringProp.Keys));
                Assert.AreEqual(valuesObj.DateTimeOffsetProp, changedObj.DateTimeOffsetProp);
            });

            EnqueueTestComplete();
        }
        public void EntityRefCaching_MultipartKeys()
        {
            TestProvider_Scenarios ctxt = new TestProvider_Scenarios(TestURIs.TestProvider_Scenarios);

            B b = new B
            {
                ID1 = 1, ID2 = 2
            };
            A a = new A { ID = 1 };

            ctxt.EntityContainer.LoadEntities(new Entity[] { a, b });

            int propChangeCount = 0;
            a.PropertyChanged += (s, e) =>
            {
                if (e.PropertyName == "B")
                {
                    propChangeCount++;
                }
            };

            a.B = b;
            Assert.AreSame(b, a.B);
            Assert.AreEqual(2, propChangeCount);

            // if we set the FK member directly, we expect the
            // cached reference to be reset
            a.BID2 = 0;
            Assert.IsNull(a.B);
            Assert.AreEqual(3, propChangeCount);

            // if we set all values of the multipart
            // key back to valid values we expect to
            // get the valid entity
            a.BID1 = 1;
            a.BID2 = 2;
            Assert.AreSame(b, a.B);
            Assert.AreEqual(4, propChangeCount);
        }
        public void InsertThrows_AssociationCollectionPropertyIsNull()
        {
            TestProvider_Scenarios provider = new TestProvider_Scenarios(TestURIs.TestProvider_Scenarios);
            SubmitOperation so = null;

            Cart c = new Cart();
            c.CartId = 1;
            CartItem ci1 = new CartItem()
            {
                CartItemId = 1,
                CartId = c.CartId,
                Cart = c,
                Data = "Cart item #1 data"
            };
            CartItem ci2 = new CartItem()
            {
                CartItemId = 2,
                CartId = c.CartId,
                Cart = c,
                Data = "Cart item #2 data"
            };
            provider.Carts.Add(c);
            provider.CartItems.Add(ci1);
            provider.CartItems.Add(ci2);

            so = provider.SubmitChanges(TestHelperMethods.DefaultOperationAction, null);
            EnqueueConditional(() => so.IsComplete);
            EnqueueCallback(delegate
            {
                Assert.IsNotNull(so.Error);
                Assert.AreEqual(string.Format(Resource.DomainContext_SubmitOperationFailed, "One or more associated objects were passed for collection property 'Items' on type 'Cart', but the target collection is null."), so.Error.Message);
                Assert.IsNotNull(so.ChangeSet);
                Assert.AreEqual(3, so.ChangeSet.AddedEntities.Count);
            });
            EnqueueTestComplete();
        }
        public void UpdateThrows_ChangeSetStillReturned()
        {
            TestProvider_Scenarios provider = new TestProvider_Scenarios(TestURIs.TestProvider_Scenarios);

            SubmitOperation so = null;
            LoadOperation lo = provider.Load(provider.GetAsQuery(), false);

            EnqueueConditional(() => lo.IsComplete);
            EnqueueCallback(delegate
            {
                Assert.IsNull(lo.Error);
                Assert.IsTrue(lo.Entities.Count() > 0);
                A entity = provider.As.First();
                entity.BID1++;
                so = provider.SubmitChanges(TestHelperMethods.DefaultOperationAction, null);
            });
            EnqueueConditional(() => so.IsComplete);
            EnqueueCallback(delegate
            {
                Assert.IsNotNull(so.Error);
                Assert.AreEqual(Resource.DomainContext_SubmitOperationFailed_Validation, so.Error.Message);
                Assert.IsNotNull(so.ChangeSet);
                Assert.AreEqual(1, so.ChangeSet.ModifiedEntities.Count);
            });
            EnqueueTestComplete();
        }