Skip to content
This repository has been archived by the owner on Dec 29, 2020. It is now read-only.

Commit

Permalink
Merge pull request #2 from Net-Http-OData/develop
Browse files Browse the repository at this point in the history
5.0.0
  • Loading branch information
TrevorPilley authored Mar 25, 2020
2 parents 9f05db3 + be1ee87 commit 84c7aba
Show file tree
Hide file tree
Showing 159 changed files with 6,450 additions and 3,956 deletions.
15 changes: 8 additions & 7 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ indent_style = space
indent_size = 4
trim_trailing_whitespace = true

[project.json]
# JSON files
[*.json]
indent_size = 2

# C# files
Expand Down Expand Up @@ -106,12 +107,12 @@ dotnet_style_prefer_conditional_expression_over_return = true:refactoring
csharp_prefer_simple_default_expression = true:suggestion

# Expression-bodied members
csharp_style_expression_bodied_methods = true:refactoring
csharp_style_expression_bodied_constructors = true:refactoring
csharp_style_expression_bodied_operators = true:refactoring
csharp_style_expression_bodied_properties = true:refactoring
csharp_style_expression_bodied_indexers = true:refactoring
csharp_style_expression_bodied_accessors = true:refactoring
csharp_style_expression_bodied_methods = true:suggestion
csharp_style_expression_bodied_constructors = true:suggestion
csharp_style_expression_bodied_operators = true:suggestion
csharp_style_expression_bodied_properties = true:suggestion
csharp_style_expression_bodied_indexers = true:suggestion
csharp_style_expression_bodied_accessors = true:suggestion
csharp_style_expression_bodied_lambdas = true:refactoring
csharp_style_expression_bodied_local_functions = true:refactoring

Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ bld/
[Ll]og/
[Ll]ogs/

# Visual Studio Code cache/options directory
.vscode/

# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
Expand Down
12 changes: 12 additions & 0 deletions Net.Http.OData.Tests/Metadata/ServiceDocumentItemTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ namespace Net.Http.OData.Tests.Metadata
{
public class ServiceDocumentItemTests
{
[Fact]
public void Constructor_Throws_ArgumentException_ForEmpty_Name()
=> Assert.Throws<ArgumentException>(() => ServiceDocumentItem.EntitySet(" ", new Uri("Products", UriKind.Relative)));

[Fact]
public void Constructor_Throws_ArgumentException_ForNull_Name()
=> Assert.Throws<ArgumentException>(() => ServiceDocumentItem.EntitySet(null, new Uri("Products", UriKind.Relative)));

[Fact]
public void Constructor_Throws_ArgumentNullException_ForNull_Uri()
=> Assert.Throws<ArgumentNullException>(() => ServiceDocumentItem.EntitySet("Products", null));

[Fact]
public void EntitySet()
{
Expand Down
96 changes: 96 additions & 0 deletions Net.Http.OData.Tests/Metadata/ServiceDocumentProviderTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Net.Http.OData.Metadata;
using Net.Http.OData.Model;
using Xunit;

namespace Net.Http.OData.Tests.Metadata
{
public class ServiceDocumentProviderTests
{
[Fact]
public void Create_MetadataMinimum()
{
TestHelper.EnsureEDM();

List<ServiceDocumentItem> serviceDocumentItems = ServiceDocumentProvider.Create(
EntityDataModel.Current,
new ODataRequestOptions(new Uri("https://services.odata.org/OData"), ODataIsolationLevel.None, ODataMetadataLevel.Minimal, ODataVersion.OData40, ODataVersion.OData40))
.ToList();

Assert.Equal(6, serviceDocumentItems.Count);

Assert.Equal("EntitySet", serviceDocumentItems[0].Kind);
Assert.Equal("Categories", serviceDocumentItems[0].Name);
Assert.Equal("Categories", serviceDocumentItems[0].Url.ToString());

Assert.Equal("EntitySet", serviceDocumentItems[1].Kind);
Assert.Equal("Customers", serviceDocumentItems[1].Name);
Assert.Equal("Customers", serviceDocumentItems[1].Url.ToString());

Assert.Equal("EntitySet", serviceDocumentItems[2].Kind);
Assert.Equal("Employees", serviceDocumentItems[2].Name);
Assert.Equal("Employees", serviceDocumentItems[2].Url.ToString());

Assert.Equal("EntitySet", serviceDocumentItems[3].Kind);
Assert.Equal("Managers", serviceDocumentItems[3].Name);
Assert.Equal("Managers", serviceDocumentItems[3].Url.ToString());

Assert.Equal("EntitySet", serviceDocumentItems[4].Kind);
Assert.Equal("Orders", serviceDocumentItems[4].Name);
Assert.Equal("Orders", serviceDocumentItems[4].Url.ToString());

Assert.Equal("EntitySet", serviceDocumentItems[5].Kind);
Assert.Equal("Products", serviceDocumentItems[5].Name);
Assert.Equal("Products", serviceDocumentItems[5].Url.ToString());
}

[Fact]
public void Create_MetadataNone()
{
TestHelper.EnsureEDM();

List<ServiceDocumentItem> serviceDocumentItems = ServiceDocumentProvider.Create(
EntityDataModel.Current,
new ODataRequestOptions(new Uri("https://services.odata.org/OData/"), ODataIsolationLevel.None, ODataMetadataLevel.None, ODataVersion.OData40, ODataVersion.OData40))
.ToList();

Assert.Equal(6, serviceDocumentItems.Count);

Assert.Equal("EntitySet", serviceDocumentItems[0].Kind);
Assert.Equal("Categories", serviceDocumentItems[0].Name);
Assert.Equal("https://services.odata.org/OData/Categories", serviceDocumentItems[0].Url.ToString());

Assert.Equal("EntitySet", serviceDocumentItems[1].Kind);
Assert.Equal("Customers", serviceDocumentItems[1].Name);
Assert.Equal("https://services.odata.org/OData/Customers", serviceDocumentItems[1].Url.ToString());

Assert.Equal("EntitySet", serviceDocumentItems[2].Kind);
Assert.Equal("Employees", serviceDocumentItems[2].Name);
Assert.Equal("https://services.odata.org/OData/Employees", serviceDocumentItems[2].Url.ToString());

Assert.Equal("EntitySet", serviceDocumentItems[3].Kind);
Assert.Equal("Managers", serviceDocumentItems[3].Name);
Assert.Equal("https://services.odata.org/OData/Managers", serviceDocumentItems[3].Url.ToString());

Assert.Equal("EntitySet", serviceDocumentItems[4].Kind);
Assert.Equal("Orders", serviceDocumentItems[4].Name);
Assert.Equal("https://services.odata.org/OData/Orders", serviceDocumentItems[4].Url.ToString());

Assert.Equal("EntitySet", serviceDocumentItems[5].Kind);
Assert.Equal("Products", serviceDocumentItems[5].Name);
Assert.Equal("https://services.odata.org/OData/Products", serviceDocumentItems[5].Url.ToString());
}

[Fact]
public void Create_Throws_ArgumentNullException_For_Null_EntityDataModel()
=> Assert.Throws<ArgumentNullException>(() => ServiceDocumentProvider.Create(
null,
new ODataRequestOptions(new Uri("https://services.odata.org/OData"), ODataIsolationLevel.None, ODataMetadataLevel.Minimal, ODataVersion.OData40, ODataVersion.OData40)));

[Fact]
public void Create_Throws_ArgumentNullException_For_Null_ODataRequestOptions()
=> Assert.Throws<ArgumentNullException>(() => ServiceDocumentProvider.Create(EntityDataModel.Current, null));
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Xml.Linq;
using System;
using System.Xml.Linq;
using Net.Http.OData.Metadata;
using Net.Http.OData.Model;
using Xunit;
Expand All @@ -12,7 +13,9 @@ public void Create_Returns_CSDL()
{
TestHelper.EnsureEDM();

var expected = XDocument.Parse(@"<edmx:Edmx xmlns:edmx=""http://docs.oasis-open.org/odata/ns/edmx"" Version=""4.0"">
ODataServiceOptions serviceOptions = TestHelper.ODataServiceOptions;

var expected = XDocument.Parse($@"<edmx:Edmx xmlns:edmx=""http://docs.oasis-open.org/odata/ns/edmx"" Version=""{serviceOptions.MaxVersion}"">
<edmx:DataServices>
<Schema xmlns=""http://docs.oasis-open.org/odata/ns/edm"" Namespace=""NorthwindModel"">
<EnumType Name=""AccessLevel"" UnderlyingType=""Edm.Int32"" IsFlags=""True"">
Expand Down Expand Up @@ -72,6 +75,7 @@ public void Create_Returns_CSDL()
<Key>
<PropertyRef Name=""OrderId"" />
</Key>
<Property Name=""Date"" Type=""Edm.DateTimeOffset"" Nullable=""false"" />
<Property Name=""Freight"" Type=""Edm.Decimal"" Nullable=""false"" />
<Property Name=""OrderDetails"" Type=""Collection(NorthwindModel.OrderDetail)"" />
<Property Name=""OrderId"" Type=""Edm.Int64"" Nullable=""false"" />
Expand Down Expand Up @@ -218,42 +222,51 @@ public void Create_Returns_CSDL()
<Annotation Term=""Org.OData.Capabilities.V1.BatchContinueOnErrorSupported"" Bool=""false"" />
<Annotation Term=""Org.OData.Capabilities.V1.FilterFunctions"">
<Collection>
<String>cast</String>
<String>isof</String>
<String>concat</String>
<String>contains</String>
<String>endswith</String>
<String>indexof</String>
<String>length</String>
<String>startswith</String>
<String>contains</String>
<String>substring</String>
<String>tolower</String>
<String>toupper</String>
<String>trim</String>
<String>length</String>
<String>indexof</String>
<String>replace</String>
<String>substring</String>
<String>concat</String>
<String>year</String>
<String>month</String>
<String>date</String>
<String>day</String>
<String>fractionalseconds</String>
<String>hour</String>
<String>maxdatetime</String>
<String>mindatetime</String>
<String>minute</String>
<String>second</String>
<String>fractionalseconds</String>
<String>month</String>
<String>now</String>
<String>mindatetime</String>
<String>maxdatetime</String>
<String>round</String>
<String>second</String>
<String>totaloffsetminutes</String>
<String>year</String>
<String>ceiling</String>
<String>floor</String>
<String>round</String>
<String>cast</String>
<String>isof</String>
</Collection>
</Annotation>
</Annotations>
</Schema>
</edmx:DataServices>
</edmx:Edmx>");

XDocument csdlDocument = MetadataProvider.Create(EntityDataModel.Current);
XDocument csdlDocument = XmlMetadataProvider.Create(EntityDataModel.Current, serviceOptions);

Assert.Equal(expected.ToString(), csdlDocument.ToString());
}

[Fact]
public void Create_Throws_ArgumentNullException_For_Null_EntityDataModel()
=> Assert.Throws<ArgumentNullException>(() => XmlMetadataProvider.Create(null, TestHelper.ODataServiceOptions));

[Fact]
public void Create_Throws_ArgumentNullException_For_Null_ODataServiceOptions()
=> Assert.Throws<ArgumentNullException>(() => XmlMetadataProvider.Create(EntityDataModel.Current, null));
}
}
2 changes: 1 addition & 1 deletion Net.Http.OData.Tests/Model/EdmCollectionTypeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void Constructor_SetsProperties()
}

[Fact]
public void Constructor_ThrowsArgumentNullException_ForNullContainedType()
public void Constructor_Throws_ArgumentNullException_For_Null_ContainedType()
{
Type type = typeof(int);

Expand Down
12 changes: 6 additions & 6 deletions Net.Http.OData.Tests/Model/EdmComplexTypeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Net.Http.OData.Tests.Model
public class EdmComplexTypeTests
{
[Fact]
public void Constructor_ThrowsArgumentNullException_ForNullProperties()
public void Constructor_Throws_ArgumentNullException_For_Null_Properties()
{
Type type = typeof(Customer);

Expand Down Expand Up @@ -38,7 +38,7 @@ public void Constructor_Type_Type_Properties_SetsProperties()
var baseType = new EdmComplexType(typeof(Employee), new EdmProperty[0]);
var properties = new EdmProperty[0];

var edmComplexType = new EdmComplexType(type, baseType, properties);
var edmComplexType = new EdmComplexType(type, properties, baseType);

Assert.Same(baseType, edmComplexType.BaseType);
Assert.Same(type, edmComplexType.ClrType);
Expand Down Expand Up @@ -107,16 +107,16 @@ public void GetProperty_ReturnsProperty()
}

[Fact]
public void GetProperty_ThrowsODataExceptionIfPropertyNameNotFound()
public void GetProperty_Throws_ODataException_If_PropertyNameNotFound()
{
TestHelper.EnsureEDM();

EdmComplexType edmComplexType = EntityDataModel.Current.EntitySets["Customers"].EdmType;

ODataException exception = Assert.Throws<ODataException>(() => edmComplexType.GetProperty("Name"));
ODataException odataException = Assert.Throws<ODataException>(() => edmComplexType.GetProperty("Name"));

Assert.Equal(HttpStatusCode.BadRequest, exception.StatusCode);
Assert.Equal("The type 'NorthwindModel.Customer' does not contain a property named 'Name'", exception.Message);
Assert.Equal(ExceptionMessage.EdmTypeDoesNotContainProperty("NorthwindModel.Customer", "Name"), odataException.Message);
Assert.Equal(HttpStatusCode.BadRequest, odataException.StatusCode);
}

[Fact]
Expand Down
2 changes: 1 addition & 1 deletion Net.Http.OData.Tests/Model/EdmEnumTypeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void Constructor_SetsProperties()
}

[Fact]
public void Constructor_ThrowsArgumentNullException_ForNullMembers()
public void Constructor_Throws_ArgumentNullException_For_Null_Members()
{
Type type = typeof(AccessLevel);

Expand Down
Loading

0 comments on commit 84c7aba

Please sign in to comment.