Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@ -0,0 +1,45 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
namespace System.Web.Http.Query
{
public class Product
{
public int ProductID { get; set; }
public string ProductName { get; set; }
public int SupplierID { get; set; }
public int CategoryID { get; set; }
public string QuantityPerUnit { get; set; }
public decimal UnitPrice { get; set; }
public short UnitsInStock { get; set; }
public short UnitsOnOrder { get; set; }
public short ReorderLevel { get; set; }
public bool Discontinued { get; set; }
public DateTime DiscontinuedDate { get; set; }
public Category Category { get; set; }
}
public class Category
{
public int CategoryID { get; set; }
public string CategoryName { get; set; }
}
public class DataTypes
{
public Guid GuidProp { get; set; }
public DateTime DateTimeProp { get; set; }
public DateTimeOffset DateTimeOffsetProp { get; set; }
public byte[] ByteArrayProp { get; set; }
public TimeSpan TimeSpanProp { get; set; }
public decimal DecimalProp { get; set; }
public double DoubleProp { get; set; }
public float FloatProp { get; set; }
public long LongProp { get; set; }
public int IntProp { get; set; }
public string Inaccessable() { return String.Empty; }
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,154 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System.Linq;
using System.Linq.Expressions;
using System.Runtime.Serialization;
using System.Xml.Serialization;
using Moq;
using Xunit;
using Assert = Microsoft.TestCommon.AssertEx;
namespace System.Web.Http.Query
{
public class QueryValidatorTest
{
QueryValidator _queryValidator = QueryValidator.Instance;
[Fact]
public void XmlIgnoreAttributeCausesInvalidOperation()
{
IQueryable<QueryValidatorSampleClass> query = new QueryValidatorSampleClass[0].AsQueryable();
Assert.Throws<InvalidOperationException>(
() => _queryValidator.Validate(query.Where((sample) => sample.XmlIgnoreProperty == 0)),
"The property or field 'XmlIgnoreProperty' in type 'QueryValidatorSampleClass' is not accessible.");
}
[Fact]
public void IgnoreDataMemberAttributeCausesInvalidOperation()
{
IQueryable<QueryValidatorSampleClass> query = new QueryValidatorSampleClass[0].AsQueryable();
Assert.Throws<InvalidOperationException>(
() => _queryValidator.Validate(query.Where((sample) => sample.IgnoreDataMemberProperty == 0)),
"The property or field 'IgnoreDataMemberProperty' in type 'QueryValidatorSampleClass' is not accessible.");
}
[Fact]
public void NonSerializedAttributeCausesInvalidOperation()
{
IQueryable<QueryValidatorSampleClass> query = new QueryValidatorSampleClass[0].AsQueryable();
Assert.Throws<InvalidOperationException>(
() => _queryValidator.Validate(query.Where((sample) => sample.NonSerializedAttributeField == 0)),
"The property or field 'NonSerializedAttributeField' in type 'QueryValidatorSampleClass' is not accessible.");
}
[Fact]
public void NormalPropertyAccessDoesnotThrow()
{
IQueryable<QueryValidatorSampleClass> query = new QueryValidatorSampleClass[0].AsQueryable();
_queryValidator.Validate(query.Where((sample) => sample.NormalProperty == 0));
}
[Fact]
public void NormalFieldAccessDoesnotThrow()
{
IQueryable<QueryValidatorSampleClass> query = new QueryValidatorSampleClass[0].AsQueryable();
_queryValidator.Validate(query.Where((sample) => sample.PublicField == 0));
}
[Fact]
public void DataContractDataMemberPropertyAccessDoesnotThrow()
{
IQueryable<QueryValidatorSampleDataContractClass> query = new QueryValidatorSampleDataContractClass[0].AsQueryable();
_queryValidator.Validate(query.Where((sample) => sample.DataMemberProperty == 0));
}
[Fact]
public void DataContractNonDataMemberPropertyAccessCausesInvalidOperation()
{
IQueryable<QueryValidatorSampleDataContractClass> query = new QueryValidatorSampleDataContractClass[0].AsQueryable();
Assert.Throws<InvalidOperationException>(
() => _queryValidator.Validate(query.Where((sample) => sample.NonDataMemberProperty == 0)),
"The property or field 'NonDataMemberProperty' in type 'QueryValidatorSampleDataContractClass' is not accessible.");
}
[Fact]
public void DataContractNonDataMemberFieldAccessCausesInvalidOperation()
{
IQueryable<QueryValidatorSampleDataContractClass> query = new QueryValidatorSampleDataContractClass[0].AsQueryable();
Assert.Throws<InvalidOperationException>(
() => _queryValidator.Validate(query.Where((sample) => sample.NonDataMemberField == 0)),
"The property or field 'NonDataMemberField' in type 'QueryValidatorSampleDataContractClass' is not accessible.");
}
[Fact]
public void SetOnlyPropertyAccessCausesInvalidOperation()
{
Mock<IQueryable> query = new Mock<IQueryable>();
query
.Setup(q => q.Expression)
.Returns(
Expression.PropertyOrField(
Expression.Constant(new QueryValidatorSampleClass()),
"SetOnlyProperty"));
Assert.Throws<InvalidOperationException>(
() => _queryValidator.Validate(query.Object),
"The property or field 'SetOnlyProperty' in type 'QueryValidatorSampleClass' is not accessible.");
}
[Fact]
public void NonPublicGetPropertyAccessCausesInvalidOperation()
{
Mock<IQueryable> query = new Mock<IQueryable>();
query
.Setup(q => q.Expression)
.Returns(
Expression.PropertyOrField(
Expression.Constant(new QueryValidatorSampleClass()),
"NonPublicGetProperty"));
Assert.Throws<InvalidOperationException>(
() => _queryValidator.Validate(query.Object),
"The property or field 'NonPublicGetProperty' in type 'QueryValidatorSampleClass' is not accessible.");
}
public class QueryValidatorSampleClass
{
[XmlIgnore]
public int XmlIgnoreProperty { get; set; }
[IgnoreDataMember]
public int IgnoreDataMemberProperty { get; set; }
[NonSerialized]
public int NonSerializedAttributeField = 0;
public int NormalProperty { get; set; }
public int SetOnlyProperty { set { } }
public int NonPublicGetProperty { set; private get; }
public int PublicField;
}
[DataContract]
public class QueryValidatorSampleDataContractClass
{
[DataMember]
public int DataMemberProperty { get; set; }
public int NonDataMemberProperty { get; set; }
public int NonDataMemberField;
}
}
}