From 1a4dce94a0c5d2c7fccba77a093598c2ab890297 Mon Sep 17 00:00:00 2001
From: Anisimova2020 <70688166+Anisimova2020@users.noreply.github.com>
Date: Sat, 15 Apr 2023 21:33:02 +0500
Subject: [PATCH 01/12] Updates NewPlatform.Flexberry.ORM up to 7.1.1-beta01
---
.../NewPlatform.Flexberry.ORM.ODataService.Files.csproj | 2 +-
.../NewPlatform.Flexberry.ORM.ODataService.WebApi.csproj | 2 +-
.../NewPlatform.Flexberry.ORM.ODataService.csproj | 2 +-
...wPlatform.Flexberry.ORM.ODataServiceCore.Common.csproj | 2 +-
...lexberry.ORM.ODataService.Tests.BusinessServers.csproj | 8 ++++----
.../NewPlatform.Flexberry.ORM.ODataService.Tests.csproj | 6 +++---
...atform.Flexberry.ORM.ODataService.Tests.Objects.csproj | 8 ++++----
7 files changed, 15 insertions(+), 15 deletions(-)
diff --git a/NewPlatform.Flexberry.ORM.ODataService.Files/NewPlatform.Flexberry.ORM.ODataService.Files.csproj b/NewPlatform.Flexberry.ORM.ODataService.Files/NewPlatform.Flexberry.ORM.ODataService.Files.csproj
index 6443def9..c95c47da 100644
--- a/NewPlatform.Flexberry.ORM.ODataService.Files/NewPlatform.Flexberry.ORM.ODataService.Files.csproj
+++ b/NewPlatform.Flexberry.ORM.ODataService.Files/NewPlatform.Flexberry.ORM.ODataService.Files.csproj
@@ -21,7 +21,7 @@
all
runtime; build; native; contentfiles; analyzers; buildtransitive
-
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
diff --git a/NewPlatform.Flexberry.ORM.ODataService.WebApi/NewPlatform.Flexberry.ORM.ODataService.WebApi.csproj b/NewPlatform.Flexberry.ORM.ODataService.WebApi/NewPlatform.Flexberry.ORM.ODataService.WebApi.csproj
index c29f2c93..5293c358 100644
--- a/NewPlatform.Flexberry.ORM.ODataService.WebApi/NewPlatform.Flexberry.ORM.ODataService.WebApi.csproj
+++ b/NewPlatform.Flexberry.ORM.ODataService.WebApi/NewPlatform.Flexberry.ORM.ODataService.WebApi.csproj
@@ -22,7 +22,7 @@
runtime; build; native; contentfiles; analyzers; buildtransitive
-
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
diff --git a/NewPlatform.Flexberry.ORM.ODataService/NewPlatform.Flexberry.ORM.ODataService.csproj b/NewPlatform.Flexberry.ORM.ODataService/NewPlatform.Flexberry.ORM.ODataService.csproj
index f5e49399..956c37a7 100644
--- a/NewPlatform.Flexberry.ORM.ODataService/NewPlatform.Flexberry.ORM.ODataService.csproj
+++ b/NewPlatform.Flexberry.ORM.ODataService/NewPlatform.Flexberry.ORM.ODataService.csproj
@@ -26,7 +26,7 @@
runtime; build; native; contentfiles; analyzers; buildtransitive
-
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
diff --git a/NewPlatform.Flexberry.ORM.ODataServiceCore.Common/NewPlatform.Flexberry.ORM.ODataServiceCore.Common.csproj b/NewPlatform.Flexberry.ORM.ODataServiceCore.Common/NewPlatform.Flexberry.ORM.ODataServiceCore.Common.csproj
index 959f3040..bc24bf67 100644
--- a/NewPlatform.Flexberry.ORM.ODataServiceCore.Common/NewPlatform.Flexberry.ORM.ODataServiceCore.Common.csproj
+++ b/NewPlatform.Flexberry.ORM.ODataServiceCore.Common/NewPlatform.Flexberry.ORM.ODataServiceCore.Common.csproj
@@ -26,7 +26,7 @@
-
+
diff --git a/Tests/BusinessServers/NewPlatform.Flexberry.ORM.ODataService.Tests.BusinessServers.csproj b/Tests/BusinessServers/NewPlatform.Flexberry.ORM.ODataService.Tests.BusinessServers.csproj
index e5c2a1e5..42fd38a2 100644
--- a/Tests/BusinessServers/NewPlatform.Flexberry.ORM.ODataService.Tests.BusinessServers.csproj
+++ b/Tests/BusinessServers/NewPlatform.Flexberry.ORM.ODataService.Tests.BusinessServers.csproj
@@ -14,10 +14,10 @@
-
-
-
-
+
+
+
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
diff --git a/Tests/NewPlatform.Flexberry.ORM.ODataService.Tests/NewPlatform.Flexberry.ORM.ODataService.Tests.csproj b/Tests/NewPlatform.Flexberry.ORM.ODataService.Tests/NewPlatform.Flexberry.ORM.ODataService.Tests.csproj
index ec8bcc03..e91c942a 100644
--- a/Tests/NewPlatform.Flexberry.ORM.ODataService.Tests/NewPlatform.Flexberry.ORM.ODataService.Tests.csproj
+++ b/Tests/NewPlatform.Flexberry.ORM.ODataService.Tests/NewPlatform.Flexberry.ORM.ODataService.Tests.csproj
@@ -40,9 +40,9 @@
-
-
-
+
+
+
diff --git a/Tests/Objects/NewPlatform.Flexberry.ORM.ODataService.Tests.Objects.csproj b/Tests/Objects/NewPlatform.Flexberry.ORM.ODataService.Tests.Objects.csproj
index c0fe08bd..7ae77c6e 100644
--- a/Tests/Objects/NewPlatform.Flexberry.ORM.ODataService.Tests.Objects.csproj
+++ b/Tests/Objects/NewPlatform.Flexberry.ORM.ODataService.Tests.Objects.csproj
@@ -14,10 +14,10 @@
-
-
-
-
+
+
+
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
From 0d35e6901e37c5f4da25a7bc21d5b626753288a8 Mon Sep 17 00:00:00 2001
From: Anisimova2020 <70688166+Anisimova2020@users.noreply.github.com>
Date: Sat, 15 Apr 2023 21:37:28 +0500
Subject: [PATCH 02/12] Changed objects for new test on ORM
---
Tests/Objects/BaseLegoBlock.cs | 12 ++++++++++--
Tests/Objects/LegoBlock.cs | 14 ++++++++++++--
...265\320\264\320\262\320\265\320\264\321\214.cs" | 2 ++
3 files changed, 24 insertions(+), 4 deletions(-)
diff --git a/Tests/Objects/BaseLegoBlock.cs b/Tests/Objects/BaseLegoBlock.cs
index f293872f..c3c45511 100644
--- a/Tests/Objects/BaseLegoBlock.cs
+++ b/Tests/Objects/BaseLegoBlock.cs
@@ -39,12 +39,20 @@ public class BaseLegoBlock : ICSSoft.STORMNET.DataObject
private NewPlatform.Flexberry.ORM.ODataService.Tests.LegoBlockColor fColor;
private NewPlatform.Flexberry.ORM.ODataService.Tests.DetailArrayOfLegoPatent fPatents;
-
+
// *** Start programmer edit section *** (BaseLegoBlock CustomMembers)
+ [NotStored]
+ public virtual string AssocType
+ {
+ get
+ {
+ return GetType().Name;
+ }
+ }
// *** End programmer edit section *** (BaseLegoBlock CustomMembers)
-
+
///
/// Name.
///
diff --git a/Tests/Objects/LegoBlock.cs b/Tests/Objects/LegoBlock.cs
index 655dcf7b..47d1db04 100644
--- a/Tests/Objects/LegoBlock.cs
+++ b/Tests/Objects/LegoBlock.cs
@@ -48,12 +48,22 @@ public class LegoBlock : NewPlatform.Flexberry.ORM.ODataService.Tests.BaseLegoBl
private NewPlatform.Flexberry.ORM.ODataService.Tests.DetailArrayOfLegoBlockCustomPanel fCustomPanels;
private NewPlatform.Flexberry.ORM.ODataService.Tests.DetailArrayOfLegoBlockTopPanel fTopPanels;
-
+
// *** Start programmer edit section *** (LegoBlock CustomMembers)
+ [NotStored]
+ [DataServiceExpression(typeof(ICSSoft.STORMNET.Business.PostgresDataService), "'Association'")]
+ public override string AssocType
+ {
+ get
+ {
+ return base.AssocType;
+ }
+ }
+
// *** End programmer edit section *** (LegoBlock CustomMembers)
-
+
///
/// Width.
///
diff --git "a/Tests/Objects/\320\234\320\265\320\264\320\262\320\265\320\264\321\214.cs" "b/Tests/Objects/\320\234\320\265\320\264\320\262\320\265\320\264\321\214.cs"
index 48d23425..2f2b5414 100644
--- "a/Tests/Objects/\320\234\320\265\320\264\320\262\320\265\320\264\321\214.cs"
+++ "b/Tests/Objects/\320\234\320\265\320\264\320\262\320\265\320\264\321\214.cs"
@@ -326,6 +326,8 @@ public virtual ICSSoft.STORMNET.UserDataTypes.NullableDateTime ДатаРожд
[StrLen(255)]
[DataServiceExpression(typeof(ICSSoft.STORMNET.Business.MSSQLDataService), "\'ПорядковыйНомер:\' + @ПорядковыйНомер@ + \", Цвет глаз мамы:\" + isnull(@Мама.ЦветГ" +
"лаз@,\'\')")]
+ [DataServiceExpression(typeof(ICSSoft.STORMNET.Business.PostgresDataService), "\'ПорядковыйНомер:\' || @ПорядковыйНомер@ || \", Цвет глаз мамы:\" || coalesce(@Мама.ЦветГ" +
+ "лаз@,\'\')")]
public virtual string МедведьСтрокой
{
get
From d29705a5eeb6637dfb313f506d85ec0247853de2 Mon Sep 17 00:00:00 2001
From: Anisimova2020 <70688166+Anisimova2020@users.noreply.github.com>
Date: Sat, 15 Apr 2023 21:38:40 +0500
Subject: [PATCH 03/12] Reverse previous changes
---
.../Expressions/EdmLibHelpers.cs | 2 +-
.../Model/DataObjectEdmModel.cs | 11 +++--------
.../Model/DefaultDataObjectEdmModelBuilder.cs | 3 +--
3 files changed, 5 insertions(+), 11 deletions(-)
diff --git a/NewPlatform.Flexberry.ORM.ODataService/Expressions/EdmLibHelpers.cs b/NewPlatform.Flexberry.ORM.ODataService/Expressions/EdmLibHelpers.cs
index 86ab66e7..ef8eddec 100644
--- a/NewPlatform.Flexberry.ORM.ODataService/Expressions/EdmLibHelpers.cs
+++ b/NewPlatform.Flexberry.ORM.ODataService/Expressions/EdmLibHelpers.cs
@@ -351,7 +351,7 @@ private static string EdmName(this Type clrType)
private static string EdmFullName(this Type clrType)
{
- return string.IsNullOrEmpty(clrType.Namespace) ? clrType.EdmName() : string.Format(CultureInfo.InvariantCulture, "{0}.{1}", clrType.Namespace, clrType.EdmName());
+ return string.Format(CultureInfo.InvariantCulture, "{0}.{1}", clrType.Namespace, clrType.EdmName());
}
private static IEdmPrimitiveType GetPrimitiveType(EdmPrimitiveTypeKind primitiveKind)
diff --git a/NewPlatform.Flexberry.ORM.ODataService/Model/DataObjectEdmModel.cs b/NewPlatform.Flexberry.ORM.ODataService/Model/DataObjectEdmModel.cs
index 0b9f94e3..c386f791 100644
--- a/NewPlatform.Flexberry.ORM.ODataService/Model/DataObjectEdmModel.cs
+++ b/NewPlatform.Flexberry.ORM.ODataService/Model/DataObjectEdmModel.cs
@@ -153,10 +153,7 @@ private void BuildTypeHierarchy()
else
_typeHierarchy[baseDataObjectType].Add(dataObjectType);
- string nameSpace = GetEntityTypeNamespace(dataObjectType);
- string typeName = GetEntityTypeName(dataObjectType);
-
- var typeFullName = string.IsNullOrEmpty(nameSpace) ? typeName : $"{nameSpace}.{typeName}";
+ var typeFullName = $"{GetEntityTypeNamespace(dataObjectType)}.{GetEntityTypeName(dataObjectType)}";
if (!_aliasesNameToProperty.ContainsKey(typeFullName))
{
_aliasesNameToProperty.Add(typeFullName, new Dictionary());
@@ -724,7 +721,7 @@ private string GetEntityTypeName(Type type)
var nameSpace = GetEntityTypeNamespace(type);
if (type != typeof(DataObject) && EdmModelBuilder != null && EdmModelBuilder.EntityTypeNameBuilder != null)
name = EdmModelBuilder.EntityTypeNameBuilder(type);
- var fullname = string.IsNullOrEmpty(nameSpace) ? name : $"{nameSpace}.{name}";
+ var fullname = $"{nameSpace}.{name}";
if (!_aliasesNameToType.ContainsKey(fullname))
_aliasesNameToType.Add(fullname, type);
if (!_aliasesTypeToName.ContainsKey(type))
@@ -762,9 +759,7 @@ private string GetEntityPropertyName(PropertyInfo prop)
var name = prop.Name;
if (name != KeyPropertyName && prop.DeclaringType != typeof(DataObject) && EdmModelBuilder != null && EdmModelBuilder.EntityPropertyNameBuilder != null)
name = EdmModelBuilder.EntityPropertyNameBuilder(prop);
- string nameSpace = GetEntityTypeNamespace(prop.DeclaringType);
- string typeName = GetEntityTypeName(prop.DeclaringType);
- string typeFullName = string.IsNullOrEmpty(nameSpace) ? typeName : $"{nameSpace}.{typeName}";
+ var typeFullName = $"{GetEntityTypeNamespace(prop.DeclaringType)}.{GetEntityTypeName(prop.DeclaringType)}";
if (!_aliasesNameToProperty.ContainsKey(typeFullName))
{
_aliasesNameToProperty.Add(typeFullName, new Dictionary());
diff --git a/NewPlatform.Flexberry.ORM.ODataService/Model/DefaultDataObjectEdmModelBuilder.cs b/NewPlatform.Flexberry.ORM.ODataService/Model/DefaultDataObjectEdmModelBuilder.cs
index 9115e228..b345ffcb 100644
--- a/NewPlatform.Flexberry.ORM.ODataService/Model/DefaultDataObjectEdmModelBuilder.cs
+++ b/NewPlatform.Flexberry.ORM.ODataService/Model/DefaultDataObjectEdmModelBuilder.cs
@@ -324,8 +324,7 @@ private string BuildEntitySetName(Type dataObjectType)
string typeName = BuildEntityTypeName(dataObjectType);
string nameSpace = BuildEntityTypeNamespace(dataObjectType);
- return string.Concat((_useNamespaceInEntitySetName && !string.IsNullOrEmpty(nameSpace)) ? $"{nameSpace}.{typeName}".Replace(".", string.Empty) : typeName, "s"/* "Aliases"*/).Replace("_", string.Empty);
- //return string.Concat(_useNamespaceInEntitySetName ? dataObjectType.FullName.Replace(".", string.Empty) : dataObjectType.Name, "s"/* "Aliases"*/).Replace("_", string.Empty);
+ return string.Concat(_useNamespaceInEntitySetName ? $"{nameSpace}.{typeName}".Replace(".", string.Empty) : typeName, "s"/* "Aliases"*/).Replace("_", string.Empty);
}
///
From 0c0c70dc85aca02142339c87fc9f1b663bd32d24 Mon Sep 17 00:00:00 2001
From: Anisimova2020 <70688166+Anisimova2020@users.noreply.github.com>
Date: Sat, 15 Apr 2023 21:39:49 +0500
Subject: [PATCH 04/12] Added filter on response
---
.../ODataApplicationBuilderExtensions.cs | 64 ++++++++++++++++++-
1 file changed, 62 insertions(+), 2 deletions(-)
diff --git a/NewPlatform.Flexberry.ORM.ODataService/Extensions/ODataApplicationBuilderExtensions.cs b/NewPlatform.Flexberry.ORM.ODataService/Extensions/ODataApplicationBuilderExtensions.cs
index 9c936c27..a9699e42 100644
--- a/NewPlatform.Flexberry.ORM.ODataService/Extensions/ODataApplicationBuilderExtensions.cs
+++ b/NewPlatform.Flexberry.ORM.ODataService/Extensions/ODataApplicationBuilderExtensions.cs
@@ -1,11 +1,15 @@
#if NETSTANDARD
namespace NewPlatform.Flexberry.ORM.ODataService.Extensions
{
- using System;
+ using System;
+ using System.IO;
+ using System.Net.Mime;
+ using System.Threading.Tasks;
using Microsoft.AspNet.OData;
using Microsoft.AspNet.OData.Common;
using Microsoft.AspNet.OData.Extensions;
- using Microsoft.AspNetCore.Builder;
+ using Microsoft.AspNetCore.Builder;
+ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
using NewPlatform.Flexberry.ORM.ODataService.Middleware;
@@ -30,6 +34,11 @@ public static IApplicationBuilder UseODataService(this IApplicationBuilder app,
VerifyODataServiceIsRegistered(app);
+ app.Use(async (context, next) =>
+ {
+ await RewriteResponse(context, next);
+ });
+
return app
.UseODataBatching()
.UseMiddleware()
@@ -48,6 +57,57 @@ private static void VerifyODataServiceIsRegistered(IApplicationBuilder app)
throw Error.InvalidOperation(SRResources.MissingODataServices, nameof(IPerRouteContainer));
}
}
+
+ ///
+ /// Removing of extra symbols from response.
+ ///
+ /// Context of request.
+ /// Next middleware.
+ /// Formed task.
+ public static async Task RewriteResponse(HttpContext context, Func next)
+ {
+ using (var responseBodyStream = new MemoryStream())
+ {
+ var bodyStream = context.Response.Body;
+
+ try
+ {
+ context.Response.Body = responseBodyStream;
+
+ await next();
+
+ responseBodyStream.Seek(0, SeekOrigin.Begin);
+ var responseBody = new StreamReader(responseBodyStream).ReadToEnd();
+
+ //Modify the response in some way.
+ if (context.Response.ContentType.Contains("application/json")
+ || context.Response.ContentType.Contains("application/xml")
+ || context.Response.ContentType.Contains("multipart/mixed"))
+ {
+ responseBody = responseBody
+ .Replace("(____.", "(")
+ .Replace("\"____.", "\"")
+ .Replace("____.", ".")
+ .Replace(" Namespace=\"____\"", " Namespace=\"\"");
+ }
+
+ using (var newStream = new MemoryStream())
+ {
+ var sw = new StreamWriter(newStream);
+ sw.Write(responseBody);
+ sw.Flush();
+
+ newStream.Seek(0, SeekOrigin.Begin);
+
+ await newStream.CopyToAsync(bodyStream);
+ }
+ }
+ finally
+ {
+ context.Response.Body = bodyStream;
+ }
+ }
+ }
}
}
#endif
From 8be8eba80fa1e26bf64d25a01d3a06d86e4f9c01 Mon Sep 17 00:00:00 2001
From: Anisimova2020 <70688166+Anisimova2020@users.noreply.github.com>
Date: Sat, 15 Apr 2023 21:43:25 +0500
Subject: [PATCH 05/12] Added test on wrong symbols on get
---
.../CRUD/Read/GetTest.cs | 108 ++++++++++++++++++
.../CRUD/Read/MetaDataTest.cs | 5 +-
2 files changed, 112 insertions(+), 1 deletion(-)
create mode 100644 Tests/NewPlatform.Flexberry.ORM.ODataService.Tests/CRUD/Read/GetTest.cs
diff --git a/Tests/NewPlatform.Flexberry.ORM.ODataService.Tests/CRUD/Read/GetTest.cs b/Tests/NewPlatform.Flexberry.ORM.ODataService.Tests/CRUD/Read/GetTest.cs
new file mode 100644
index 00000000..2205aee6
--- /dev/null
+++ b/Tests/NewPlatform.Flexberry.ORM.ODataService.Tests/CRUD/Read/GetTest.cs
@@ -0,0 +1,108 @@
+namespace NewPlatform.Flexberry.ORM.ODataService.Tests.CRUD.Read
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Net;
+ using System.Net.Http;
+
+ using ICSSoft.STORMNET;
+ using ICSSoft.STORMNET.UserDataTypes;
+ using ICSSoft.STORMNET.Windows.Forms;
+
+ using NewPlatform.Flexberry.ORM.ODataService.Tests.Extensions;
+
+ using Newtonsoft.Json;
+ using Newtonsoft.Json.Linq;
+
+ using Xunit;
+
+ ///
+ /// Класс тестов для проверки корректной обработки Get-запросов.
+ ///
+ public class GetTest : BaseODataServiceIntegratedTest
+ {
+#if NETCOREAPP
+ ///
+ /// Конструктор по-умолчанию.
+ ///
+ /// Фабрика для приложения.
+ /// Вывод отладочной информации.
+ public GetTest(CustomWebApplicationFactory factory, Xunit.Abstractions.ITestOutputHelper output)
+ : base(factory, output)
+ {
+ }
+#endif
+
+ ///
+ /// Проверка получения данных для классов, в которых есть нехранимые поля, который не содержат setter'ов.
+ /// (Такие варианты присутствуют в старом коде).
+ ///
+ [Fact]
+ public void TestGetNotStored()
+ {
+ ActODataService(args =>
+ {
+ LegoBlock block = new LegoBlock { Name = "Легосити" };
+ var objs = new DataObject[] { block };
+ args.DataService.UpdateObjects(ref objs);
+
+ string requestUrl = string.Format(
+ "http://localhost/odata/{0}?$select=__PrimaryKey,AssocType",
+ args.Token.Model.GetEdmEntitySet(typeof(LegoBlock)).Name);
+
+ // Обращаемся к OData-сервису и обрабатываем ответ.
+ using (HttpResponseMessage response = args.HttpClient.GetAsync(requestUrl).Result)
+ {
+ // Убедимся, что запрос завершился успешно.
+ Assert.Equal(HttpStatusCode.OK, response.StatusCode);
+
+ // Получим строку с ответом.
+ string receivedStr = response.Content.ReadAsStringAsync().Result.Beautify();
+
+ // Преобразуем полученный объект в словарь.
+ Dictionary receivedDict = JsonConvert.DeserializeObject>(receivedStr);
+
+ Assert.Equal(1, ((JArray)receivedDict["value"]).Count);
+ }
+ });
+ }
+
+ ///
+ /// Проверка значение в атрибуте @odata.type.
+ ///
+ [Fact]
+ public void TestGetWithMaster()
+ {
+ ActODataService(args =>
+ {
+ LegoBlock block = new LegoBlock { Name = "Легосити" };
+ LegoPatent patent = new LegoPatent { Name = "ZeroM", BaseLegoBlock = block };
+ var objs = new DataObject[] { block, patent };
+ args.DataService.UpdateObjects(ref objs);
+
+ string requestUrl = string.Format(
+ "http://localhost/odata/{0}?$select=__PrimaryKey,Name&$expand=BaseLegoBlock($select=__PrimaryKey,Name)",
+ args.Token.Model.GetEdmEntitySet(typeof(LegoPatent)).Name);
+
+ // Обращаемся к OData-сервису и обрабатываем ответ.
+ using (HttpResponseMessage response = args.HttpClient.GetAsync(requestUrl).Result)
+ {
+ // Убедимся, что запрос завершился успешно.
+ Assert.Equal(HttpStatusCode.OK, response.StatusCode);
+
+ // Получим строку с ответом.
+ string receivedStr = response.Content.ReadAsStringAsync().Result.Beautify();
+
+ // Преобразуем полученный объект в словарь.
+ Dictionary receivedDict = JsonConvert.DeserializeObject>(receivedStr);
+
+ Assert.Equal(1, ((JArray)receivedDict["value"]).Count);
+ Assert.Contains("@odata.type", receivedStr);
+#if NETCOREAPP
+ Assert.DoesNotContain("____", receivedStr);
+#endif
+ }
+ });
+ }
+ }
+}
diff --git a/Tests/NewPlatform.Flexberry.ORM.ODataService.Tests/CRUD/Read/MetaDataTest.cs b/Tests/NewPlatform.Flexberry.ORM.ODataService.Tests/CRUD/Read/MetaDataTest.cs
index 3f388322..d9b7ea82 100644
--- a/Tests/NewPlatform.Flexberry.ORM.ODataService.Tests/CRUD/Read/MetaDataTest.cs
+++ b/Tests/NewPlatform.Flexberry.ORM.ODataService.Tests/CRUD/Read/MetaDataTest.cs
@@ -97,7 +97,10 @@ public void GetFullMetadataTest()
string receivedData = response.Content.ReadAsStringAsync().Result.Beautify();
Assert.True(!string.IsNullOrEmpty(receivedData));
- Assert.StartsWith("", receivedData);
+ Assert.StartsWith("", receivedData);
+#if NETCOREAPP
+ Assert.DoesNotContain("____", receivedData);
+#endif
}
});
}
From f85c0af4737857f2e95a15b43094fc391262f90f Mon Sep 17 00:00:00 2001
From: Anisimova2020 <70688166+Anisimova2020@users.noreply.github.com>
Date: Mon, 17 Apr 2023 11:04:03 +0500
Subject: [PATCH 06/12] Fixed problems with NullReference on response update
---
.../Extensions/ODataApplicationBuilderExtensions.cs | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/NewPlatform.Flexberry.ORM.ODataService/Extensions/ODataApplicationBuilderExtensions.cs b/NewPlatform.Flexberry.ORM.ODataService/Extensions/ODataApplicationBuilderExtensions.cs
index a9699e42..75dabb7f 100644
--- a/NewPlatform.Flexberry.ORM.ODataService/Extensions/ODataApplicationBuilderExtensions.cs
+++ b/NewPlatform.Flexberry.ORM.ODataService/Extensions/ODataApplicationBuilderExtensions.cs
@@ -80,9 +80,10 @@ public static async Task RewriteResponse(HttpContext context, Func next)
var responseBody = new StreamReader(responseBodyStream).ReadToEnd();
//Modify the response in some way.
- if (context.Response.ContentType.Contains("application/json")
+ if (context.Response.ContentType != null &&
+ (context.Response.ContentType.Contains("application/json")
|| context.Response.ContentType.Contains("application/xml")
- || context.Response.ContentType.Contains("multipart/mixed"))
+ || context.Response.ContentType.Contains("multipart/mixed")))
{
responseBody = responseBody
.Replace("(____.", "(")
From cb02c668524ecf63150231be4325155f48e850d1 Mon Sep 17 00:00:00 2001
From: Anisimova2020 <70688166+Anisimova2020@users.noreply.github.com>
Date: Mon, 17 Apr 2023 11:06:32 +0500
Subject: [PATCH 07/12] Updated on nuspek
NewPlatform.Flexberry.ORM.ODataService up to 7.1.1-beta01
---
CHANGELOG.md | 2 ++
NewPlatform.Flexberry.ORM.ODataService.nuspec | 7 +++++--
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index cc8187bd..b0999de8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,8 +7,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### Added
### Changed
+1. Updated `NewPlatform.Flexberry.ORM` up to `7.1.1-beta01`.
### Fixed
+1. Fixed problem with metadata when inheritance and PublishName is used (for Net Standart 2.0, Net Core 3.1, Net 6.0, Net 7.0).
## [7.1.0] - 2023.04.12
diff --git a/NewPlatform.Flexberry.ORM.ODataService.nuspec b/NewPlatform.Flexberry.ORM.ODataService.nuspec
index 13a49fab..415acec7 100644
--- a/NewPlatform.Flexberry.ORM.ODataService.nuspec
+++ b/NewPlatform.Flexberry.ORM.ODataService.nuspec
@@ -2,7 +2,7 @@
NewPlatform.Flexberry.ORM.ODataService
- 7.1.0
+ 7.1.1-beta01
Flexberry ORM ODataService
New Platform Ltd.
New Platform Ltd.
@@ -13,7 +13,10 @@
Flexberry ORM OData Service Package.
Changed
- 1. Updated `NewPlatform.Flexberry.ORM` up to `7.1.0`.
+ 1. Updated `NewPlatform.Flexberry.ORM` up to `7.1.1-beta01`.
+
+ Fixed
+ 1. Fixed problem with metadata when inheritance and PublishName is used (for Net Standart 2.0, Net Core 3.1, Net 6.0, Net 7.0).
Copyright New Platform Ltd 2023
Flexberry ORM OData ODataService
From 5652085146ccfaba8532de21068f10aa545c39bc Mon Sep 17 00:00:00 2001
From: Anisimova2020 <70688166+Anisimova2020@users.noreply.github.com>
Date: Mon, 17 Apr 2023 12:17:19 +0500
Subject: [PATCH 08/12] Changed test object value for test fixing
---
.../CRUD/Read/GetTest.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Tests/NewPlatform.Flexberry.ORM.ODataService.Tests/CRUD/Read/GetTest.cs b/Tests/NewPlatform.Flexberry.ORM.ODataService.Tests/CRUD/Read/GetTest.cs
index 2205aee6..3d60358e 100644
--- a/Tests/NewPlatform.Flexberry.ORM.ODataService.Tests/CRUD/Read/GetTest.cs
+++ b/Tests/NewPlatform.Flexberry.ORM.ODataService.Tests/CRUD/Read/GetTest.cs
@@ -76,7 +76,7 @@ public void TestGetWithMaster()
ActODataService(args =>
{
LegoBlock block = new LegoBlock { Name = "Легосити" };
- LegoPatent patent = new LegoPatent { Name = "ZeroM", BaseLegoBlock = block };
+ LegoPatent patent = new LegoPatent { Name = "ZeroM", BaseLegoBlock = block, Date = DateTime.Now };
var objs = new DataObject[] { block, patent };
args.DataService.UpdateObjects(ref objs);
From 24ca683b3b77ec0f68d55574b43cc444fc111013 Mon Sep 17 00:00:00 2001
From: Anisimova2020 <70688166+Anisimova2020@users.noreply.github.com>
Date: Mon, 17 Apr 2023 13:58:44 +0500
Subject: [PATCH 09/12] Removed commented code
---
.../Model/DefaultDataObjectEdmModelBuilder.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/NewPlatform.Flexberry.ORM.ODataService/Model/DefaultDataObjectEdmModelBuilder.cs b/NewPlatform.Flexberry.ORM.ODataService/Model/DefaultDataObjectEdmModelBuilder.cs
index b345ffcb..63f84ab6 100644
--- a/NewPlatform.Flexberry.ORM.ODataService/Model/DefaultDataObjectEdmModelBuilder.cs
+++ b/NewPlatform.Flexberry.ORM.ODataService/Model/DefaultDataObjectEdmModelBuilder.cs
@@ -324,7 +324,7 @@ private string BuildEntitySetName(Type dataObjectType)
string typeName = BuildEntityTypeName(dataObjectType);
string nameSpace = BuildEntityTypeNamespace(dataObjectType);
- return string.Concat(_useNamespaceInEntitySetName ? $"{nameSpace}.{typeName}".Replace(".", string.Empty) : typeName, "s"/* "Aliases"*/).Replace("_", string.Empty);
+ return string.Concat(_useNamespaceInEntitySetName ? $"{nameSpace}.{typeName}".Replace(".", string.Empty) : typeName, "s").Replace("_", string.Empty);
}
///
From 62ad75af418426108480daf3ade0d58ff5c54823 Mon Sep 17 00:00:00 2001
From: Anisimova2020 <70688166+Anisimova2020@users.noreply.github.com>
Date: Tue, 18 Apr 2023 13:14:47 +0500
Subject: [PATCH 10/12] Added support of removing extra symbols from response
for net4.5
---
.../ODataApplicationBuilderExtensions.cs | 10 +--
.../Handlers/PostPatchHandler.cs | 61 +++++++++++++++++--
.../CRUD/Read/GetTest.cs | 4 +-
.../CRUD/Read/MetaDataTest.cs | 4 +-
4 files changed, 65 insertions(+), 14 deletions(-)
diff --git a/NewPlatform.Flexberry.ORM.ODataService/Extensions/ODataApplicationBuilderExtensions.cs b/NewPlatform.Flexberry.ORM.ODataService/Extensions/ODataApplicationBuilderExtensions.cs
index 75dabb7f..065a45c6 100644
--- a/NewPlatform.Flexberry.ORM.ODataService/Extensions/ODataApplicationBuilderExtensions.cs
+++ b/NewPlatform.Flexberry.ORM.ODataService/Extensions/ODataApplicationBuilderExtensions.cs
@@ -66,9 +66,10 @@ private static void VerifyODataServiceIsRegistered(IApplicationBuilder app)
/// Formed task.
public static async Task RewriteResponse(HttpContext context, Func next)
{
+ /* Same code for NETFRAMEWORK is placed on NewPlatform.Flexberry.ORM.ODataService.Handlers.PostPatchHandler.*/
using (var responseBodyStream = new MemoryStream())
{
- var bodyStream = context.Response.Body;
+ Stream bodyStream = context.Response.Body;
try
{
@@ -77,7 +78,8 @@ public static async Task RewriteResponse(HttpContext context, Func next)
await next();
responseBodyStream.Seek(0, SeekOrigin.Begin);
- var responseBody = new StreamReader(responseBodyStream).ReadToEnd();
+ using StreamReader sr = new StreamReader(responseBodyStream);
+ var responseBody = sr.ReadToEnd();
//Modify the response in some way.
if (context.Response.ContentType != null &&
@@ -92,9 +94,9 @@ public static async Task RewriteResponse(HttpContext context, Func next)
.Replace(" Namespace=\"____\"", " Namespace=\"\"");
}
- using (var newStream = new MemoryStream())
+ using (MemoryStream newStream = new MemoryStream())
{
- var sw = new StreamWriter(newStream);
+ using StreamWriter sw = new StreamWriter(newStream);
sw.Write(responseBody);
sw.Flush();
diff --git a/NewPlatform.Flexberry.ORM.ODataService/Handlers/PostPatchHandler.cs b/NewPlatform.Flexberry.ORM.ODataService/Handlers/PostPatchHandler.cs
index ae7c0e1d..e8a95c4f 100644
--- a/NewPlatform.Flexberry.ORM.ODataService/Handlers/PostPatchHandler.cs
+++ b/NewPlatform.Flexberry.ORM.ODataService/Handlers/PostPatchHandler.cs
@@ -1,6 +1,10 @@
#if NETFRAMEWORK
namespace NewPlatform.Flexberry.ORM.ODataService.Handlers
-{
+{
+ using Microsoft.AspNet.OData.Batch;
+ using System;
+ using System.IO;
+ using System.Net;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
@@ -33,8 +37,13 @@ public class PostPatchHandler : DelegatingHandler
public const string AcceptApplicationMsExcel = "PostPatchHandler_AcceptApplicationMsExcel";
///
- protected override Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
+ protected override async Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
+ if (request == null)
+ {
+ throw new ArgumentNullException(nameof(request));
+ }
+
foreach (var val in request.Headers.Accept)
{
if (val.MediaType == "application/ms-excel")
@@ -62,9 +71,53 @@ protected override Task SendAsync(HttpRequestMessage reques
/// Исправление для Mono, взято из https://github.com/OData/odata.net/issues/165
*/
if (!request.Headers.Contains("Accept-Charset"))
- request.Headers.Add("Accept-Charset", new[] { "utf-8" });
+ request.Headers.Add("Accept-Charset", new[] { "utf-8" });
+
+ HttpResponseMessage responseMessage = await base.SendAsync(request, cancellationToken);
+ await RewriteResponse(responseMessage);
+ return responseMessage;
+
+ }
- return base.SendAsync(request, cancellationToken);
+ ///
+ /// Удаление некорректных символов в именах типов метаданных.
+ /// Данные символы добавляются специально, чтобы MS не бросало исключение на пустой Namespace у типов с PublishName.
+ ///
+ /// Текущее ответное сообщение, в котором могут быть заменены символы.
+ /// Задача на обработку.
+ private static async Task RewriteResponse(HttpResponseMessage response)
+ {
+ /* Same code for NETSTANDARD is placed on NewPlatform.Flexberry.ORM.ODataService.Extensions.ODataApplicationBuilderExtensions.*/
+ string contentType = response?.Content?.Headers?.ContentType?.MediaType;
+ if (!string.IsNullOrEmpty(contentType) &&
+ (contentType.Contains("application/json")
+ || contentType.Contains("application/xml")
+ || contentType.Contains("multipart/mixed")))
+ {
+ HttpContent content = response.Content;
+ Stream contentStream = await content.ReadAsStreamAsync();
+ using StreamReader sr = new StreamReader(contentStream);
+ string responseStr = sr.ReadToEnd();
+
+ responseStr = responseStr
+ .Replace("(____.", "(")
+ .Replace("\"____.", "\"")
+ .Replace("____.", ".")
+ .Replace(" Namespace=\"____\"", " Namespace=\"\"");
+
+ using (MemoryStream newStream = new MemoryStream())
+ {
+ using StreamWriter sw = new StreamWriter(newStream);
+ sw.Write(responseStr);
+ sw.Flush();
+ newStream.Seek(0, SeekOrigin.Begin);
+
+ contentStream.Position = 0;
+ contentStream.SetLength(0);
+
+ await newStream.CopyToAsync(contentStream);
+ }
+ }
}
}
}
diff --git a/Tests/NewPlatform.Flexberry.ORM.ODataService.Tests/CRUD/Read/GetTest.cs b/Tests/NewPlatform.Flexberry.ORM.ODataService.Tests/CRUD/Read/GetTest.cs
index 3d60358e..019014ad 100644
--- a/Tests/NewPlatform.Flexberry.ORM.ODataService.Tests/CRUD/Read/GetTest.cs
+++ b/Tests/NewPlatform.Flexberry.ORM.ODataService.Tests/CRUD/Read/GetTest.cs
@@ -97,10 +97,8 @@ public void TestGetWithMaster()
Dictionary receivedDict = JsonConvert.DeserializeObject>(receivedStr);
Assert.Equal(1, ((JArray)receivedDict["value"]).Count);
- Assert.Contains("@odata.type", receivedStr);
-#if NETCOREAPP
+ Assert.Contains("@odata.type", receivedStr);
Assert.DoesNotContain("____", receivedStr);
-#endif
}
});
}
diff --git a/Tests/NewPlatform.Flexberry.ORM.ODataService.Tests/CRUD/Read/MetaDataTest.cs b/Tests/NewPlatform.Flexberry.ORM.ODataService.Tests/CRUD/Read/MetaDataTest.cs
index d9b7ea82..e90fbf41 100644
--- a/Tests/NewPlatform.Flexberry.ORM.ODataService.Tests/CRUD/Read/MetaDataTest.cs
+++ b/Tests/NewPlatform.Flexberry.ORM.ODataService.Tests/CRUD/Read/MetaDataTest.cs
@@ -97,10 +97,8 @@ public void GetFullMetadataTest()
string receivedData = response.Content.ReadAsStringAsync().Result.Beautify();
Assert.True(!string.IsNullOrEmpty(receivedData));
- Assert.StartsWith("", receivedData);
-#if NETCOREAPP
+ Assert.StartsWith("", receivedData);
Assert.DoesNotContain("____", receivedData);
-#endif
}
});
}
From 029aa1efd75122b97d91637f5d824b12465961db Mon Sep 17 00:00:00 2001
From: Anisimova2020 <70688166+Anisimova2020@users.noreply.github.com>
Date: Tue, 18 Apr 2023 13:17:30 +0500
Subject: [PATCH 11/12] Changed version of
NewPlatform.Flexberry.ORM.ODataService up to
---
CHANGELOG.md | 2 +-
NewPlatform.Flexberry.ORM.ODataService.nuspec | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b0999de8..9ca34b78 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,7 +10,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
1. Updated `NewPlatform.Flexberry.ORM` up to `7.1.1-beta01`.
### Fixed
-1. Fixed problem with metadata when inheritance and PublishName is used (for Net Standart 2.0, Net Core 3.1, Net 6.0, Net 7.0).
+1. Fixed problem with metadata when inheritance and PublishName is used.
## [7.1.0] - 2023.04.12
diff --git a/NewPlatform.Flexberry.ORM.ODataService.nuspec b/NewPlatform.Flexberry.ORM.ODataService.nuspec
index 415acec7..997f6282 100644
--- a/NewPlatform.Flexberry.ORM.ODataService.nuspec
+++ b/NewPlatform.Flexberry.ORM.ODataService.nuspec
@@ -2,7 +2,7 @@
NewPlatform.Flexberry.ORM.ODataService
- 7.1.1-beta01
+ 7.1.1-beta02
Flexberry ORM ODataService
New Platform Ltd.
New Platform Ltd.
@@ -16,7 +16,7 @@
1. Updated `NewPlatform.Flexberry.ORM` up to `7.1.1-beta01`.
Fixed
- 1. Fixed problem with metadata when inheritance and PublishName is used (for Net Standart 2.0, Net Core 3.1, Net 6.0, Net 7.0).
+ 1. Fixed problem with metadata when inheritance and PublishName is used.
Copyright New Platform Ltd 2023
Flexberry ORM OData ODataService
From 0486e30a3aa5b117c0cdfda51a0ac6676863fec8 Mon Sep 17 00:00:00 2001
From: Anisimova2020 <70688166+Anisimova2020@users.noreply.github.com>
Date: Tue, 18 Apr 2023 17:02:26 +0500
Subject: [PATCH 12/12] Fixed NullReference on closed stream
---
.../ODataApplicationBuilderExtensions.cs | 3 +--
.../Handlers/PostPatchHandler.cs | 27 ++++++++++---------
2 files changed, 15 insertions(+), 15 deletions(-)
diff --git a/NewPlatform.Flexberry.ORM.ODataService/Extensions/ODataApplicationBuilderExtensions.cs b/NewPlatform.Flexberry.ORM.ODataService/Extensions/ODataApplicationBuilderExtensions.cs
index 065a45c6..a18efe34 100644
--- a/NewPlatform.Flexberry.ORM.ODataService/Extensions/ODataApplicationBuilderExtensions.cs
+++ b/NewPlatform.Flexberry.ORM.ODataService/Extensions/ODataApplicationBuilderExtensions.cs
@@ -78,8 +78,7 @@ public static async Task RewriteResponse(HttpContext context, Func next)
await next();
responseBodyStream.Seek(0, SeekOrigin.Begin);
- using StreamReader sr = new StreamReader(responseBodyStream);
- var responseBody = sr.ReadToEnd();
+ var responseBody = new StreamReader(responseBodyStream).ReadToEnd();
//Modify the response in some way.
if (context.Response.ContentType != null &&
diff --git a/NewPlatform.Flexberry.ORM.ODataService/Handlers/PostPatchHandler.cs b/NewPlatform.Flexberry.ORM.ODataService/Handlers/PostPatchHandler.cs
index e8a95c4f..37ceafba 100644
--- a/NewPlatform.Flexberry.ORM.ODataService/Handlers/PostPatchHandler.cs
+++ b/NewPlatform.Flexberry.ORM.ODataService/Handlers/PostPatchHandler.cs
@@ -96,26 +96,27 @@ private static async Task RewriteResponse(HttpResponseMessage response)
{
HttpContent content = response.Content;
Stream contentStream = await content.ReadAsStreamAsync();
- using StreamReader sr = new StreamReader(contentStream);
- string responseStr = sr.ReadToEnd();
-
- responseStr = responseStr
+ string responseStr = new StreamReader(contentStream).ReadToEnd();
+ if (!string.IsNullOrEmpty(responseStr) && responseStr.Length > 3)
+ {
+ responseStr = responseStr
.Replace("(____.", "(")
.Replace("\"____.", "\"")
.Replace("____.", ".")
.Replace(" Namespace=\"____\"", " Namespace=\"\"");
- using (MemoryStream newStream = new MemoryStream())
- {
- using StreamWriter sw = new StreamWriter(newStream);
- sw.Write(responseStr);
- sw.Flush();
- newStream.Seek(0, SeekOrigin.Begin);
+ using (MemoryStream newStream = new MemoryStream())
+ {
+ using StreamWriter sw = new StreamWriter(newStream);
+ sw.Write(responseStr);
+ sw.Flush();
+ newStream.Seek(0, SeekOrigin.Begin);
- contentStream.Position = 0;
- contentStream.SetLength(0);
+ contentStream.Position = 0;
+ contentStream.SetLength(responseStr.Length);
- await newStream.CopyToAsync(contentStream);
+ await newStream.CopyToAsync(contentStream);
+ }
}
}
}