Exemple #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");
        }
Exemple #2
0
        public void Entity_GetIdentityDefault()
        {
            EntityNoKeyMembers e0 = new EntityNoKeyMembers();

            ExceptionHelper.ExpectArgumentException(() => { e0.GetIdentity(); }, Resource.EntityKey_EmptyKeyMembers, "keyValues");

            Entity1KeyMember e1 = new Entity1KeyMember()
            {
                K1 = 5
            };

            Entity1KeyMember ee1 = new Entity1KeyMember()
            {
                K1 = 5
            };

            EnsureEntityKeysEqual(e1, ee1);
            ee1.K1 = 7;
            EnsureEntityKeysNotEqual(e1, ee1);

            Entity2KeyMembers e2  = new Entity2KeyMembers(e1, "A");
            Entity2KeyMembers ee2 = new Entity2KeyMembers(e1, "A");

            EnsureEntityKeysEqual(e2, ee2);
            ee2.K2 = "B";
            EnsureEntityKeysNotEqual(e2, ee2);

            Entity3KeyMembers e3  = new Entity3KeyMembers(e2, 3.1m);
            Entity3KeyMembers ee3 = new Entity3KeyMembers(e2, 3.1m);

            EnsureEntityKeysEqual(e3, ee3);
            ee3.K3 = 4.2m;
            EnsureEntityKeysNotEqual(e3, ee3);

            DateTime          someDate = new DateTime(2009, 1, 1);
            Entity4KeyMembers e4       = new Entity4KeyMembers(e3, someDate);
            Entity4KeyMembers ee4      = new Entity4KeyMembers(e3, someDate);

            EnsureEntityKeysEqual(e4, ee4);
            ee4.K4 = new DateTime(2008, 1, 1);
            EnsureEntityKeysNotEqual(e4, ee4);

            Entity5KeyMembers e5  = new Entity5KeyMembers(e4, TimeSpan.FromHours(2));
            Entity5KeyMembers ee5 = new Entity5KeyMembers(e4, TimeSpan.FromHours(2));

            EnsureEntityKeysEqual(e5, ee5);
            ee5.K5 = TimeSpan.FromHours(3);
            EnsureEntityKeysNotEqual(e5, ee5);

            Guid someGuid         = Guid.NewGuid();
            Entity4KeyMembers e6  = new Entity6KeyMembers(e5, someGuid);
            Entity6KeyMembers ee6 = new Entity6KeyMembers(e5, someGuid);

            EnsureEntityKeysEqual(e6, ee6);
            ee6.K6 = Guid.NewGuid();
            EnsureEntityKeysNotEqual(e6, ee6);
        }
        public void AddRedundantReference()
        {
            // Add a reference to an entity type already in the codegen'd definition
            ExceptionHelper.ExpectArgumentException(
                () => this.CustomerDomainService.AddReference(typeof(MockCustomer), this.CustomerDomainService),
                string.Format(CultureInfo.InvariantCulture, Resource.EntityContainer_EntitySetAlreadyExists, typeof(MockCustomer)));

            // First time adding an external entity should succeed
            this.CustomerDomainService.AddReference(typeof(City), this.CityDomainContext);

            // Second time should fail
            ExceptionHelper.ExpectArgumentException(
                () => this.CustomerDomainService.AddReference(typeof(City), this.CityDomainContext),
                string.Format(CultureInfo.InvariantCulture, Resource.EntityContainer_EntitySetAlreadyExists, typeof(City)));
        }