Browse Source

Tests fixed.

pull/303/head
Sebastian 8 years ago
parent
commit
6b9e7c7dfa
  1. 7
      src/Squidex.Infrastructure/Log/Adapter/SemanticLogLoggerProvider.cs
  2. 7
      tests/Squidex.Domain.Apps.Entities.Tests/TestHelpers/AssertHelper.cs
  3. 5
      tests/Squidex.Domain.Apps.Entities.Tests/TestHelpers/ValidationAssert.cs
  4. 6
      tests/Squidex.Infrastructure.Tests/Http/DumpFormatterTests.cs
  5. 11
      tests/Squidex.Infrastructure.Tests/Log/SemanticLogAdapterTests.cs

7
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;
}

7
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<T>(this T result, T value)
public static void ShouldBeEquivalent<T>(this J<T> lhs, T rhs)
{
result.Should().BeEquivalentTo(value, o => o.IncludingAllDeclaredProperties());
lhs.Value.Should().BeEquivalentTo(rhs, o => o.IncludingProperties());
}
}
}

5
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)
{

6
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",

11
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<SemanticLog>(() => new SemanticLog(channels, new List<ILogAppender>(), () => 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()
{

Loading…
Cancel
Save