Skip to content

Commit

Permalink
Resolved some warnings around virtual calls in constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
niemyjski committed May 3, 2023
1 parent 01afbe7 commit a683cf6
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 39 deletions.
4 changes: 2 additions & 2 deletions src/Exceptionless/Logging/FileExceptionlessLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ public FileExceptionlessLog(string filePath, bool append = false) {
MinimumLogLevel = LogLevel.Trace;
_append = append;

Init();
Initialize();

// flush the log every 3 seconds instead of on every write
_flushTimer = new Timer(OnFlushTimer, null, TimeSpan.FromSeconds(3), TimeSpan.FromSeconds(3));
}

protected virtual void Init() {
protected virtual void Initialize() {
if (!Path.IsPathRooted(FilePath))
FilePath = Path.GetFullPath(FilePath);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Exceptionless.Logging {
public class IsolatedStorageFileExceptionlessLog : FileExceptionlessLog {
public IsolatedStorageFileExceptionlessLog(string filePath, bool append = false) : base(filePath, append) {}

protected override void Init() {}
protected override void Initialize() {}

private IsolatedStorageFile GetStore() {
#if NETSTANDARD
Expand Down
2 changes: 1 addition & 1 deletion src/Platforms/Exceptionless.NLog/ExceptionlessTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace Exceptionless.NLog {
[Target("Exceptionless")]
public class ExceptionlessTarget : TargetWithLayout {
public sealed class ExceptionlessTarget : TargetWithLayout {
private ExceptionlessClient _client = ExceptionlessClient.Default;

public Layout ApiKey { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,8 @@

namespace Exceptionless.MessagePack.Tests {
public class MessagePackStorageSerializerTests : StorageSerializerTestBase {
protected override void Initialize(IDependencyResolver resolver) {
base.Initialize(resolver);
resolver.Register<IStorageSerializer>(new MessagePackStorageSerializer(resolver));
}

protected override IStorageSerializer GetSerializer(IDependencyResolver resolver) {
return resolver.Resolve<IStorageSerializer>();
public MessagePackStorageSerializerTests() {
Resolver.Register<IStorageSerializer>(new MessagePackStorageSerializer(Resolver));
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,16 @@

namespace Exceptionless.Tests.Serializer {
public abstract class StorageSerializerTestBase {
private readonly IDependencyResolver _resolver;
protected readonly IDependencyResolver Resolver = new DefaultDependencyResolver();

public StorageSerializerTestBase() {
_resolver = new DefaultDependencyResolver();
_resolver.Register<IObjectStorage, InMemoryObjectStorage>();
_resolver.Register<IJsonSerializer, DefaultJsonSerializer>();
_resolver.Register<IExceptionlessLog, InMemoryExceptionlessLog>();
_resolver.Register<IEnvironmentInfoCollector, DefaultEnvironmentInfoCollector>();
_resolver.Register<ExceptionlessConfiguration>(new ExceptionlessConfiguration(_resolver));
Initialize(_resolver);
Resolver.Register<IObjectStorage, InMemoryObjectStorage>();
Resolver.Register<IJsonSerializer, DefaultJsonSerializer>();
Resolver.Register<IExceptionlessLog, InMemoryExceptionlessLog>();
Resolver.Register<IEnvironmentInfoCollector, DefaultEnvironmentInfoCollector>();
Resolver.Register<ExceptionlessConfiguration>(new ExceptionlessConfiguration(Resolver));
}

protected virtual void Initialize(IDependencyResolver resolver) { }

protected abstract IStorageSerializer GetSerializer(IDependencyResolver resolver);

private Event CreateSimpleEvent() {
var ev= new Event {
Date = DateTime.Now,
Expand All @@ -47,17 +42,17 @@ private Event CreateSimpleEvent() {
}

private void AssertEventSerialize(Event evt) {
var serializer = GetSerializer(_resolver);
var serializer = Resolver.Resolve<IStorageSerializer>();
Event newEvent;
using (var memory = new MemoryStream()) {
serializer.Serialize(evt, memory);
memory.Position = 0;
newEvent = serializer.Deserialize<Event>(memory);
}

var jsonSerializer = _resolver.GetJsonSerializer();
var expected = jsonSerializer.Serialize(evt);
var actual = jsonSerializer.Serialize(newEvent);
var jsonSerializer = Resolver.GetJsonSerializer();
string expected = jsonSerializer.Serialize(evt);
string actual = jsonSerializer.Serialize(newEvent);

Assert.Equal(expected, actual);
}
Expand All @@ -78,13 +73,13 @@ public virtual void CanSerializeSimpleDataValues() {

public virtual void CanSerializeTags() {
var evt = CreateSimpleEvent();
evt.AddTags("Critial", "Startup", "AspNetCore");
evt.AddTags("Critical", "Startup", "AspNetCore");
AssertEventSerialize(evt);
}

public virtual void CanSerializeEnvironmentInfo() {
var evt = CreateSimpleEvent();
evt.Data[Event.KnownDataKeys.EnvironmentInfo] = _resolver.Resolve<IEnvironmentInfoCollector>().GetEnvironmentInfo();
evt.Data[Event.KnownDataKeys.EnvironmentInfo] = Resolver.Resolve<IEnvironmentInfoCollector>().GetEnvironmentInfo();
AssertEventSerialize(evt);
}

Expand Down Expand Up @@ -142,7 +137,7 @@ public virtual void CanSerializeManualStackingInfo() {
}

public virtual void CanSerializeSimpleError() {
var client = new ExceptionlessClient(new ExceptionlessConfiguration(_resolver));
var client = new ExceptionlessClient(new ExceptionlessConfiguration(Resolver));
var exception = new ArgumentException("The argument cannot be null or empty", "value");

var evt = CreateSimpleEvent();
Expand All @@ -151,7 +146,7 @@ public virtual void CanSerializeSimpleError() {
}

public virtual void CanSerializeError() {
var client = new ExceptionlessClient(new ExceptionlessConfiguration(_resolver));
var client = new ExceptionlessClient(new ExceptionlessConfiguration(Resolver));
var exception = new ArgumentException("The argument cannot be null or empty", "value");

var evt = CreateSimpleEvent();
Expand Down
2 changes: 1 addition & 1 deletion test/Exceptionless.Tests/Plugins/PluginTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected struct TestStruct {
public int Id { get; set; }
}

public class MyApplicationException : Exception {
public sealed class MyApplicationException : Exception {
public MyApplicationException(string message) : base(message) {
SetsDataProperty = Data;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,8 @@

namespace Exceptionless.Tests.Serializer {
public class JsonStorageSerializerTests : StorageSerializerTestBase {
protected override void Initialize(IDependencyResolver resolver) {
base.Initialize(resolver);
resolver.Register<IStorageSerializer, DefaultJsonSerializer>();
}

protected override IStorageSerializer GetSerializer(IDependencyResolver resolver) {
return resolver.Resolve<IStorageSerializer>();
public JsonStorageSerializerTests() {
Resolver.Register<IStorageSerializer, DefaultJsonSerializer>();
}

[Fact(Skip = "The json serializer deserialize anonymous(object) types as dictionary.")]
Expand Down

0 comments on commit a683cf6

Please sign in to comment.