Ejemplo n.º 1
0
        public void EndSubmit_ThrowsOnBadAsyncResult()
        {
            IAsyncResult result;

            // Null IAsyncResult
            result = null;
            ExceptionHelper.ExpectArgumentNullException(() => this.DomainClient.EndSubmit(result), "asyncResult");

            // Unexpected IAsyncResult type
            result = new MockAsyncResult();
            ExceptionHelper.ExpectArgumentException(() => this.DomainClient.EndSubmit(result), Resources.WrongAsyncResult, "asyncResult");

            ChannelFactory <CityDomainContext.ICityDomainServiceContract> factory = CreateChannelFactory <CityDomainContext.ICityDomainServiceContract>();
            MethodInfo endMethod = typeof(CityDomainContext.ICityDomainServiceContract).GetMethod("EndGetCities");

            // TODO: This fails because S.SM.DS.Client.DomainClientAsyncResult != S.SM.DS.Web.DomainClientAsyncResult
            //// IAsyncResult operation not complete
            //result = WebDomainClientAsyncResult<CityDomainContext.ICityDomainServiceContract>.CreateSubmitResult(this.DomainClient, factory.CreateChannel(), endMethod, null, null, null, null);
            //ExceptionHelper.ExpectInvalidOperationException(() => this.DomainClient.EndSubmit(result), Resources.OperationNotComplete);

            //// IAsyncResult from a different operation
            //result = WebDomainClientAsyncResult<CityDomainContext.ICityDomainServiceContract>.CreateInvokeResult(this.DomainClient, factory.CreateChannel(), endMethod, null, null, null, null);
            //((WebDomainClientAsyncResult<CityDomainContext.ICityDomainServiceContract>)result).Complete();
            //ExceptionHelper.ExpectArgumentException(() => this.DomainClient.EndSubmit(result), Resources.WrongAsyncResult, "asyncResult");

            //// IAsyncResult from a different instance
            //WebDomainClient<CityDomainContext.ICityDomainServiceContract> otherClient = new WebDomainClient<CityDomainContext.ICityDomainServiceContract>(TestURIs.Cities);
            //result = WebDomainClientAsyncResult<CityDomainContext.ICityDomainServiceContract>.CreateSubmitResult(otherClient, factory.CreateChannel(), endMethod, null, null, null, null);
            //((WebDomainClientAsyncResult<CityDomainContext.ICityDomainServiceContract>)result).Complete();
            //ExceptionHelper.ExpectArgumentException(() => this.DomainClient.EndSubmit(result), Resources.WrongAsyncResult, "asyncResult");
        }
        protected override QueryCompletedResult EndQueryCore(IAsyncResult asyncResult)
        {
            MockAsyncResult      ar          = (MockAsyncResult)asyncResult;
            int                  entityCount = ar.Entities.Count();
            QueryCompletedResult results     = new QueryCompletedResult(ar.Entities, new Entity[0], entityCount, new ValidationResult[0]);

            return(results);
        }
        protected override InvokeCompletedResult EndInvokeCore(IAsyncResult asyncResult)
        {
            MockAsyncResult ar = (MockAsyncResult)asyncResult;

            InvokeCompletedResult invokeResults = new InvokeCompletedResult(ar.ReturnValue);

            return(invokeResults);
        }
        protected override IAsyncResult BeginSubmitCore(EntityChangeSet changeSet, AsyncCallback callback, object userState)
        {
            IEnumerable <ChangeSetEntry> submitOperations = changeSet.GetChangeSetEntries();
            MockAsyncResult ar = new MockAsyncResult(null, userState, new object[] { changeSet, submitOperations, userState });

            // perform mock submit operations

            callback.Invoke(ar);

            return(ar);
        }
        protected override SubmitCompletedResult EndSubmitCore(IAsyncResult asyncResult)
        {
            MockAsyncResult ar = (MockAsyncResult)asyncResult;

            object[]        stateParts = (object[])ar.InnerState;
            EntityChangeSet changeSet  = (EntityChangeSet)stateParts[0];
            IEnumerable <ChangeSetEntry> submitOperations = (IEnumerable <ChangeSetEntry>)stateParts[1];

            SubmitCompletedResult submitResults = new SubmitCompletedResult(changeSet, submitOperations);

            return(submitResults);
        }
        protected override IAsyncResult BeginInvokeCore(InvokeArgs invokeArgs, AsyncCallback callback, object userState)
        {
            MockAsyncResult ar = new MockAsyncResult(null, userState, new object[] { invokeArgs.OperationName, invokeArgs.ReturnType, invokeArgs.Parameters, userState });

            // do the invoke and get the return value
            if (invokeArgs.OperationName == "Echo")
            {
                ar.ReturnValue = "Echo: " + (string)invokeArgs.Parameters.Values.First();
            }

            callback.Invoke(ar);

            return(ar);
        }
        protected override IAsyncResult BeginQueryCore(EntityQuery query, AsyncCallback callback, object userState)
        {
            // load test data and get query result
            IEnumerable <Entity> entities = GetQueryResult(query.QueryName, query.Parameters);

            if (query.Query != null)
            {
                entities = RebaseQuery(entities.AsQueryable(), query.Query).Cast <Entity>();
            }

            MockAsyncResult ar = new MockAsyncResult(entities, userState, null);

            callback.Invoke(ar);

            return(ar);
        }
        protected override IAsyncResult BeginInvokeCore(InvokeArgs invokeArgs, AsyncCallback callback, object userState)
        {
            MockAsyncResult ar = new MockAsyncResult(null, userState, new object[] { invokeArgs.OperationName, invokeArgs.ReturnType, invokeArgs.Parameters, userState });

            // do the invoke and get the return value
            if (invokeArgs.OperationName == "Echo")
            {
                ar.ReturnValue = "Echo: " + (string)invokeArgs.Parameters.Values.First();
            }

            callback.Invoke(ar);

            return ar;
        }
        protected override IAsyncResult BeginSubmitCore(EntityChangeSet changeSet, AsyncCallback callback, object userState)
        {
            IEnumerable<ChangeSetEntry> submitOperations = changeSet.GetChangeSetEntries();
            MockAsyncResult ar = new MockAsyncResult(null, userState, new object[] { changeSet, submitOperations, userState });

            // perform mock submit operations

            callback.Invoke(ar);

            return ar;
        }
        protected override IAsyncResult BeginQueryCore(EntityQuery query, AsyncCallback callback, object userState)
        {
            // load test data and get query result
            IEnumerable<Entity> entities = GetQueryResult(query.QueryName, query.Parameters);
            if (query.Query != null)
            {
                entities = RebaseQuery(entities.AsQueryable(), query.Query).Cast<Entity>();
            }

            MockAsyncResult ar = new MockAsyncResult(entities, userState, null);
            callback.Invoke(ar);

            return ar;
        }