public void ChangeStateShouldFailWhenChangingAddedToDeleted()
 {
     var entity = new TestEntityType();
     this.testSubject.AddObject("Things", entity);
     Action changeToDeleted = () => this.testSubject.ChangeState(entity, EntityStates.Deleted);
     changeToDeleted.ShouldThrow<InvalidOperationException>().WithMessage(ClientStrings.Context_CannotChangeStateIfAdded(EntityStates.Deleted));
 }
        public void ChangeStateShouldSetToDeletedAndSetChangeOrder()
        {
            var entity     = new TestEntityType();
            var descriptor = this.AttachAndGetDescriptor(entity);

            this.testSubject.ChangeState(entity, EntityStates.Deleted);
            descriptor.State.Should().Be(EntityStates.Deleted);
            descriptor.ChangeOrder.Should().Be(2);
        }
        public void ChangeStateShouldSetToDetachedAndActuallyRemoveFromTracking()
        {
            var entity     = new TestEntityType();
            var descriptor = this.AttachAndGetDescriptor(entity);

            this.testSubject.ChangeState(entity, EntityStates.Detached);
            descriptor.State.Should().Be(EntityStates.Detached);
            this.testSubject.GetEntityDescriptor(entity).Should().BeNull();
        }
        public void ChangeStateShouldFailWhenChangingAddedToUnchanged()
        {
            var entity = new TestEntityType();

            this.testSubject.AddObject("Things", entity);
            Action changeToUnchanged = () => this.testSubject.ChangeState(entity, EntityStates.Unchanged);

            changeToUnchanged.ShouldThrow <InvalidOperationException>().WithMessage(ClientStrings.Context_CannotChangeStateIfAdded(EntityStates.Unchanged));
        }
        public void ChangeStateShouldFailWhenChangingDeletedToModified()
        {
            var entity = new TestEntityType();

            this.AttachAndGetDescriptor(entity);
            this.testSubject.DeleteObject(entity);
            Action changeToModified = () => this.testSubject.ChangeState(entity, EntityStates.Modified);

            changeToModified.ShouldThrow <InvalidOperationException>().WithMessage(ClientStrings.Context_CannotChangeStateToModifiedIfNotUnchanged);
        }
        public void ChangeStateShouldAllowSettingModifiedToModified()
        {
            var entity     = new TestEntityType();
            var descriptor = this.AttachAndGetDescriptor(entity);

            this.testSubject.UpdateObject(entity);
            descriptor.State.Should().Be(EntityStates.Modified);

            this.testSubject.ChangeState(entity, EntityStates.Modified);
            descriptor.State.Should().Be(EntityStates.Modified);
        }
        public void HeadersInArgsShouldNotBeModifiedDuringGetReadStream()
        {
            // Regression coverage for: SendingRequest cannot set Accept-Charset header for SetSaveStream if reusing request arg
            new TransportLayerThatAlwaysSendsBack204(this.testSubject);
            var entity     = new TestEntityType();
            var descriptor = this.AttachAndGetDescriptor(entity);

            descriptor.ReadStreamUri = new Uri("http://fakeReadStreamUri.org/");

            var args = new DataServiceRequestArgs();

            this.testSubject.GetReadStream(entity, args);
            args.Headers.Should().BeEmpty();
        }
        public void SettingETagOnDescriptorShouldOverrideWhatIsSent()
        {
            // regression coverage for Light switch issue: due to attach detach workaround identity strings don't match and duplicates occur with doubles,
            // which was really due to: DataServiceContext should support changing EntityState and ETag values for entity instances
            var entity         = new TestEntityType();
            var transportLayer = new TransportLayerThatRemembersIfMatchAndAlwaysSendsBack204(this.testSubject);

            this.testSubject.AttachTo("Things", entity, "ETagSetInAttach");
            this.testSubject.ChangeState(entity, EntityStates.Modified);
            this.testSubject.GetEntityDescriptor(entity).ETag = "ETagSetInProperty";

            this.testSubject.SaveChanges().Should().HaveCount(1);
            transportLayer.LastIfMatchHeaderValue.Should().Be("ETagSetInProperty");
        }
        public void ChangingStateToUnchangedShouldPreventRequestFromBeingSent()
        {
            // regression coverage for Light switch issue: due to attach detach workaround identity strings don't match and duplicates occur with doubles,
            // which was really due to: DataServiceContext should support changing EntityState and ETag values for entity instances
            var entity = new TestEntityType();

            this.testSubject.AttachTo("Things", entity);
            this.testSubject.UpdateObject(entity);
            this.testSubject.ChangeState(entity, EntityStates.Unchanged);
            this.testSubject.Configurations.RequestPipeline.OnMessageCreating = (args) => { throw new NotImplementedException(); };
            Action saveChanges = () => this.testSubject.SaveChanges();

            saveChanges.ShouldNotThrow();
        }
        public void ChangeStateShouldSetToUnchangedAndNotModifyChangeOrder()
        {
            var entity     = new TestEntityType();
            var descriptor = this.AttachAndGetDescriptor(entity);

            this.testSubject.UpdateObject(entity);
            descriptor.Should().NotBeNull();
            descriptor.State.Should().Be(EntityStates.Modified);
            descriptor.ChangeOrder.Should().Be(2);

            this.testSubject.ChangeState(entity, EntityStates.Unchanged);
            descriptor.State.Should().Be(EntityStates.Unchanged);
            descriptor.ChangeOrder.Should().Be(2);
        }
 public void ChangeStateShouldFailWhenChangingDeletedToModified()
 {
     var entity = new TestEntityType();
     this.AttachAndGetDescriptor(entity);
     this.testSubject.DeleteObject(entity);
     Action changeToModified = () => this.testSubject.ChangeState(entity, EntityStates.Modified);
     changeToModified.ShouldThrow<InvalidOperationException>().WithMessage(ClientStrings.Context_CannotChangeStateToModifiedIfNotUnchanged);
 }
        public void ChangeStateShouldSetToUnchangedAndNotModifyChangeOrder()
        {
            var entity = new TestEntityType();
            var descriptor = this.AttachAndGetDescriptor(entity);
            this.testSubject.UpdateObject(entity);
            descriptor.Should().NotBeNull();
            descriptor.State.Should().Be(EntityStates.Modified);
            descriptor.ChangeOrder.Should().Be(2);

            this.testSubject.ChangeState(entity, EntityStates.Unchanged);
            descriptor.State.Should().Be(EntityStates.Unchanged);
            descriptor.ChangeOrder.Should().Be(2);
        }
        public void ChangeStateShouldSetToDeletedAndSetChangeOrder()
        {
            var entity = new TestEntityType();
            var descriptor = this.AttachAndGetDescriptor(entity);

            this.testSubject.ChangeState(entity, EntityStates.Deleted);
            descriptor.State.Should().Be(EntityStates.Deleted);
            descriptor.ChangeOrder.Should().Be(2);
        }
        public void ChangeStateShouldAllowSettingModifiedToModified()
        {
            var entity = new TestEntityType();
            var descriptor = this.AttachAndGetDescriptor(entity);
            this.testSubject.UpdateObject(entity);
            descriptor.State.Should().Be(EntityStates.Modified);

            this.testSubject.ChangeState(entity, EntityStates.Modified);
            descriptor.State.Should().Be(EntityStates.Modified);
        }
        public void ChangeStateShouldSetToDetachedAndActuallyRemoveFromTracking()
        {
            var entity = new TestEntityType();
            var descriptor = this.AttachAndGetDescriptor(entity);

            this.testSubject.ChangeState(entity, EntityStates.Detached);
            descriptor.State.Should().Be(EntityStates.Detached);
            this.testSubject.GetEntityDescriptor(entity).Should().BeNull();
        }
        public void HeadersInArgsShouldNotBeModifiedDuringGetReadStream()
        {
            // Regression coverage for: SendingRequest cannot set Accept-Charset header for SetSaveStream if reusing request arg
            new TransportLayerThatAlwaysSendsBack204(this.testSubject);
            var entity = new TestEntityType();
            var descriptor = this.AttachAndGetDescriptor(entity);
            descriptor.ReadStreamUri = new Uri("http://fakeReadStreamUri.org/");

            var args = new DataServiceRequestArgs();
            this.testSubject.GetReadStream(entity, args);
            args.Headers.Should().BeEmpty();
        }
        public void SettingETagOnDescriptorShouldOverrideWhatIsSent()
        {
            // regression coverage for Light switch issue: due to attach detach workaround identity strings don't match and duplicates occur with doubles,
            // which was really due to: DataServiceContext should support changing EntityState and ETag values for entity instances 
            var entity = new TestEntityType();
            var transportLayer = new TransportLayerThatRemembersIfMatchAndAlwaysSendsBack204(this.testSubject);

            this.testSubject.AttachTo("Things", entity, "ETagSetInAttach");
            this.testSubject.ChangeState(entity, EntityStates.Modified);
            this.testSubject.GetEntityDescriptor(entity).ETag = "ETagSetInProperty";

            this.testSubject.SaveChanges().Should().HaveCount(1);
            transportLayer.LastIfMatchHeaderValue.Should().Be("ETagSetInProperty");
        }
 public void ChangingStateToUnchangedShouldPreventRequestFromBeingSent()
 {
     // regression coverage for Light switch issue: due to attach detach workaround identity strings don't match and duplicates occur with doubles,
     // which was really due to: DataServiceContext should support changing EntityState and ETag values for entity instances 
     var entity = new TestEntityType();
     this.testSubject.AttachTo("Things", entity);
     this.testSubject.UpdateObject(entity);
     this.testSubject.ChangeState(entity, EntityStates.Unchanged);
     this.testSubject.Configurations.RequestPipeline.OnMessageCreating = (args) => { throw new NotImplementedException(); };
     Action saveChanges = () => this.testSubject.SaveChanges();
     saveChanges.ShouldNotThrow();
 }