コード例 #1
0
        public void CustomMethod_BackwardsCompability_430()
        {
            var ctxt = new TestDomainServices.NamedUpdates.CalculatorDomainContext
                (new Uri(TestURIs.RootURI, "TestDomainServices-NamedUpdates-CalculatorDomainService.svc"));

            LoadOperation lo = ctxt.Load(ctxt.GetEntitiesOldCodeGenQuery(), false);
            CalculatorValueOldCodeGen calc = null;
            SubmitOperation so = null;

            List<string> propChanged = new List<string>();
            EnqueueConditional(() => lo.IsComplete);
            EnqueueCallback(delegate
            {
                calc = ctxt.CalculatorValuesOldCodeGen.First();

                Assert.IsTrue(calc.CanAddTwice);
                Assert.IsFalse(calc.IsAddTwiceInvoked);

                calc.PropertyChanged += (sender, args) => propChanged.Add(args.PropertyName);

                calc.AddTwice(2.0m);

                Assert.IsFalse(calc.CanAddTwice, "Should not be able to invoke entity action multiple times");
                Assert.IsTrue(calc.IsAddTwiceInvoked);

                Assert.AreEqual(1, propChanged.Count(p => p == "CanAddTwice"), "Property changes for CanAddTwice");
                Assert.AreEqual(1, propChanged.Count(p => p == "IsAddTwiceInvoked"), "Property changes for CanAddTwice");
                propChanged.Clear();

                // Submit so server calculates 0 + 2*2
                so = ctxt.SubmitChanges(TestHelperMethods.DefaultOperationAction, null);
            });
            EnqueueConditional(() => so.IsComplete);
            EnqueueCallback(delegate
            {
                Assert.IsFalse(so.HasError);

                Assert.AreEqual(4.0m, calc.Value);

                Assert.AreEqual(1, propChanged.Count(p => p == "CanAddTwice"), "Property changes for CanAddTwice");
                Assert.AreEqual(1, propChanged.Count(p => p == "IsAddTwiceInvoked"), "Property changes for CanAddTwice");
            });
            EnqueueTestComplete();
        }
コード例 #2
0
        public void CustomMethod_MultipleInvocations_ShouldHappenInSameOrder()
        {
            var ctxt = new TestDomainServices.NamedUpdates.CalculatorDomainContext
                (new Uri(TestURIs.RootURI, "TestDomainServices-NamedUpdates-CalculatorDomainService.svc"));

            LoadOperation lo = ctxt.Load(ctxt.GetEntitiesQuery(), false);
            CalculatorValue calc = null;
            SubmitOperation so = null;


            EnqueueConditional(() => lo.IsComplete);
            EnqueueCallback(delegate
            {
                calc = ctxt.CalculatorValues.First();

                Assert.IsTrue(calc.CanAdd);
                Assert.IsFalse(calc.IsAddInvoked);

                calc.Add(2.0m);

                Assert.IsTrue(calc.CanAdd, "Should be able to invoke entity action multiple times");
                Assert.IsTrue(calc.IsAddInvoked);

                calc.Multiply(3.0m);

                Assert.IsTrue(calc.CanMultiply, "Should be able to invoke entity action multiple times");
                Assert.IsTrue(calc.IsMultiplyInvoked);

                calc.Add(1.0m);
                calc.Multiply(5.0m);
                calc.Add(2.0m);

                // Submit so server calculates (((((0+2)*3)+1)*5)+2) = 37
                so = ctxt.SubmitChanges(TestHelperMethods.DefaultOperationAction, null);
            });
            EnqueueConditional(() => so.IsComplete);
            EnqueueCallback(delegate
            {
                Assert.IsFalse(so.HasError);

                Assert.AreEqual(37.0m, calc.Value);
            });
            EnqueueTestComplete();
        }