コード例 #1
0
        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));
        }
コード例 #2
0
 public void GetEdmTypeTests()
 {
     Assert.AreEqual("Edm.TestPrimitive", ClientConvert.GetEdmType(typeof(TestPrimitiveType)));
     foreach (Type t in new Type[] { typeof(UInt16), typeof(UInt32), typeof(UInt64) })
     {
         Action test = () => ClientConvert.GetEdmType(t);
         test.ShouldThrow <NotSupportedException>().WithMessage(Strings.ALinq_CantCastToUnsupportedPrimitive(t.Name));
     }
 }
        /// <summary>
        /// Implementation of Read>.
        /// </summary>
        /// <returns>
        /// Return value of Read/>
        /// </returns>
        protected sealed override bool ReadImplementation()
        {
            if (!this.hasReadValue)
            {
                try
                {
                    ClientEdmModel    model              = this.MaterializerContext.Model;
                    Type              expectedType       = this.ExpectedType;
                    IEdmTypeReference expectedClientType = model.GetOrCreateEdmType(expectedType).ToEdmTypeReference(ClientTypeUtil.CanAssignNull(expectedType));
                    if ((this.SingleResult.HasValue && !this.SingleResult.Value) && expectedClientType.Definition.TypeKind != EdmTypeKind.Collection)
                    {
                        expectedType = typeof(ICollection <>).MakeGenericType(expectedType);

                        // we do not allow null values for collection
                        expectedClientType = model.GetOrCreateEdmType(expectedType).ToEdmTypeReference(false);
                    }

                    IEdmTypeReference expectedReaderType = this.MaterializerContext.ResolveExpectedTypeForReading(expectedType).ToEdmTypeReference(expectedClientType.IsNullable);

                    this.ReadWithExpectedType(expectedClientType, expectedReaderType);
                }
                catch (ODataErrorException e)
                {
                    throw new DataServiceClientException(ClientStrings.Deserialize_ServerException(e.Error.Message), e);
                }
                catch (ODataException e)
                {
                    throw new InvalidOperationException(e.Message, e);
                }
                catch (ArgumentException e)
                {
                    throw new InvalidOperationException(e.Message, e);
                }
                finally
                {
                    this.hasReadValue = true;
                }

                return(true);
            }
            else
            {
                return(false);
            }
        }