From 6b9e7c7dfa25d193b01758f8244a6c79f8aaaace Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 25 Jun 2018 19:02:30 +0200 Subject: [PATCH] Tests fixed. --- .../Log/Adapter/SemanticLogLoggerProvider.cs | 7 ++++++- .../TestHelpers/AssertHelper.cs | 7 ++++--- .../TestHelpers/ValidationAssert.cs | 5 +++-- .../Http/DumpFormatterTests.cs | 6 +++--- .../Log/SemanticLogAdapterTests.cs | 11 ++++++++++- 5 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/Squidex.Infrastructure/Log/Adapter/SemanticLogLoggerProvider.cs b/src/Squidex.Infrastructure/Log/Adapter/SemanticLogLoggerProvider.cs index 153ebc464..524145b0f 100644 --- a/src/Squidex.Infrastructure/Log/Adapter/SemanticLogLoggerProvider.cs +++ b/src/Squidex.Infrastructure/Log/Adapter/SemanticLogLoggerProvider.cs @@ -28,9 +28,14 @@ namespace Squidex.Infrastructure.Log.Adapter this.log = log; } + public static SemanticLogLoggerProvider ForTesting(ISemanticLog log) + { + return new SemanticLogLoggerProvider(log); + } + public ILogger CreateLogger(string categoryName) { - if (log == null) + if (log == null && services != null) { log = services.GetService(typeof(ISemanticLog)) as ISemanticLog; } diff --git a/tests/Squidex.Domain.Apps.Entities.Tests/TestHelpers/AssertHelper.cs b/tests/Squidex.Domain.Apps.Entities.Tests/TestHelpers/AssertHelper.cs index 66f07000d..cb0bf466e 100644 --- a/tests/Squidex.Domain.Apps.Entities.Tests/TestHelpers/AssertHelper.cs +++ b/tests/Squidex.Domain.Apps.Entities.Tests/TestHelpers/AssertHelper.cs @@ -9,6 +9,7 @@ using System.Collections.Generic; using System.Linq; using FluentAssertions; using Squidex.Infrastructure.EventSourcing; +using Squidex.Infrastructure.Orleans; namespace Squidex.Domain.Apps.Entities.TestHelpers { @@ -33,7 +34,7 @@ namespace Squidex.Domain.Apps.Entities.TestHelpers { lhs.Should().BeOfType(rhs.GetType()); - ((object)lhs).Should().BeEquivalentTo(rhs, o => o.IncludingAllDeclaredProperties()); + ((object)lhs).Should().BeEquivalentTo(rhs, o => o.IncludingAllRuntimeProperties()); } public static void ShouldBeSameEventType(this IEvent lhs, IEvent rhs) @@ -41,9 +42,9 @@ namespace Squidex.Domain.Apps.Entities.TestHelpers lhs.Should().BeOfType(rhs.GetType()); } - public static void ShouldBeEquivalent(this T result, T value) + public static void ShouldBeEquivalent(this J lhs, T rhs) { - result.Should().BeEquivalentTo(value, o => o.IncludingAllDeclaredProperties()); + lhs.Value.Should().BeEquivalentTo(rhs, o => o.IncludingProperties()); } } } diff --git a/tests/Squidex.Domain.Apps.Entities.Tests/TestHelpers/ValidationAssert.cs b/tests/Squidex.Domain.Apps.Entities.Tests/TestHelpers/ValidationAssert.cs index 1b3d62108..0383318b8 100644 --- a/tests/Squidex.Domain.Apps.Entities.Tests/TestHelpers/ValidationAssert.cs +++ b/tests/Squidex.Domain.Apps.Entities.Tests/TestHelpers/ValidationAssert.cs @@ -8,6 +8,7 @@ using System; using System.Linq; using System.Threading.Tasks; +using FluentAssertions; using Squidex.Infrastructure; using Xunit; using Xunit.Sdk; @@ -26,7 +27,7 @@ namespace Squidex.Domain.Apps.Entities.TestHelpers } catch (ValidationException ex) { - ex.Errors.ToArray().ShouldBeEquivalent(errors); + ex.Errors.ToArray().Should().BeEquivalentTo(errors); } catch (XunitException) { @@ -48,7 +49,7 @@ namespace Squidex.Domain.Apps.Entities.TestHelpers } catch (ValidationException ex) { - ex.Errors.ToArray().ShouldBeEquivalent(errors); + ex.Errors.ToArray().Should().BeEquivalentTo(errors); } catch (XunitException) { diff --git a/tests/Squidex.Infrastructure.Tests/Http/DumpFormatterTests.cs b/tests/Squidex.Infrastructure.Tests/Http/DumpFormatterTests.cs index 0a0262065..e84f11584 100644 --- a/tests/Squidex.Infrastructure.Tests/Http/DumpFormatterTests.cs +++ b/tests/Squidex.Infrastructure.Tests/Http/DumpFormatterTests.cs @@ -27,7 +27,7 @@ namespace Squidex.Infrastructure.Http var expected = CreateExpectedDump( "Request:", - "POST: https://cloud.squidex.io/ HTTP/1.1", + "POST: https://cloud.squidex.io/ HTTP/2.0", "User-Agent: Squidex/1.0", "Accept-Language: de; en", "Accept-Encoding: UTF-8", @@ -49,7 +49,7 @@ namespace Squidex.Infrastructure.Http var expected = CreateExpectedDump( "Request:", - "POST: https://cloud.squidex.io/ HTTP/1.1", + "POST: https://cloud.squidex.io/ HTTP/2.0", "User-Agent: Squidex/1.0", "Accept-Language: de; en", "Accept-Encoding: UTF-8", @@ -75,7 +75,7 @@ namespace Squidex.Infrastructure.Http var expected = CreateExpectedDump( "Request:", - "POST: https://cloud.squidex.io/ HTTP/1.1", + "POST: https://cloud.squidex.io/ HTTP/2.0", "User-Agent: Squidex/1.0", "Accept-Language: de; en", "Accept-Encoding: UTF-8", diff --git a/tests/Squidex.Infrastructure.Tests/Log/SemanticLogAdapterTests.cs b/tests/Squidex.Infrastructure.Tests/Log/SemanticLogAdapterTests.cs index 9f5d9fef3..b08b3262d 100644 --- a/tests/Squidex.Infrastructure.Tests/Log/SemanticLogAdapterTests.cs +++ b/tests/Squidex.Infrastructure.Tests/Log/SemanticLogAdapterTests.cs @@ -9,6 +9,7 @@ using System; using System.Collections.Generic; using FakeItEasy; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; using Squidex.Infrastructure.Log.Adapter; using Xunit; @@ -39,7 +40,7 @@ namespace Squidex.Infrastructure.Log log = new Lazy(() => new SemanticLog(channels, new List(), () => new JsonLogWriter())); - sut = new SemanticLogLoggerProvider(log.Value); + sut = SemanticLogLoggerProvider.ForTesting(log.Value); } [Fact] @@ -48,6 +49,14 @@ namespace Squidex.Infrastructure.Log sut.Dispose(); } + [Fact] + public void Should_provide_null_logger_when_no_log_provided() + { + var provider = SemanticLogLoggerProvider.ForTesting(null); + + Assert.Same(provider.CreateLogger("test"), NullLogger.Instance); + } + [Fact] public void Should_provide_a_scope() {