Skip to content

Commit

Permalink
Add global usings and disabled nullable
Browse files Browse the repository at this point in the history
  • Loading branch information
cmendible committed Mar 29, 2024
1 parent 48796c4 commit d379a13
Show file tree
Hide file tree
Showing 25 changed files with 2,237 additions and 2,320 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/netDumbster.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ jobs:
- name: Push to NuGet
run: dotnet nuget push "*.nupkg" --api-key ${{secrets.NUGET_API_KEY}} --source https://api.nuget.org/v3/index.json
if: matrix.os == 'linux-latest' && github.event_name != 'pull_request' && startswith(github.ref, 'refs/tags/v')


15 changes: 15 additions & 0 deletions netDumbster.Test/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
global using System;
global using System.Collections.Generic;
global using System.IO;
global using System.Linq;
global using System.Net;
global using System.Net.Sockets;
global using System.Reflection;
global using System.Text;
global using System.Threading.Tasks;
global using netDumbster.smtp;
global using netDumbster.smtp.Logging;
global using MimeKit;
global using MailKit.Net.Smtp;
global using Xunit;
global using Xunit.Sdk;
36 changes: 16 additions & 20 deletions netDumbster.Test/LoopbackAdapterTests.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
// Copyright (c) 2010, Hexasystems Corporation
// All rights reserved.
namespace netDumbster.Test
{
using System.Net;
using netDumbster.smtp;
namespace netDumbster.Test;

public class LoopbackAdapterTests : TestsBase
public class LoopbackAdapterTests : TestsBase
{
protected override SimpleSmtpServer StartServer()
{
protected override SimpleSmtpServer StartServer()
{
return Configuration.Configure()
.WithAddress(IPAddress.Loopback)
.Build();
}

protected override SimpleSmtpServer StartServer(int port)
{
return Configuration.Configure()
.WithAddress(IPAddress.Loopback)
.WithPort(port)
.Build();
}
return Configuration.Configure()
.WithAddress(IPAddress.Loopback)
.Build();
}

protected override SimpleSmtpServer StartServer(int port)
{
return Configuration.Configure()
.WithAddress(IPAddress.Loopback)
.WithPort(port)
.Build();
}
}

}
108 changes: 50 additions & 58 deletions netDumbster.Test/MailKitTests.cs
Original file line number Diff line number Diff line change
@@ -1,77 +1,69 @@
namespace netDumbster.Test
namespace netDumbster.Test;

public class MailKitTests : IDisposable
{
using MailKit.Net.Smtp;
using MimeKit;
using netDumbster.smtp;
using netDumbster.smtp.Logging;
using System;
using System.Threading.Tasks;
using Xunit;

public class MailKitTests : IDisposable
private bool _disposed;
private readonly SimpleSmtpServer _server;

public MailKitTests()
{
private bool _disposed;
private readonly SimpleSmtpServer _server;
LogManager.GetLogger = type => new ConsoleLogger(type);

public MailKitTests()
{
LogManager.GetLogger = type => new ConsoleLogger(type);
_server = Configuration.Configure()
.WithRandomPort()
.Build();
}

_server = Configuration.Configure()
.WithRandomPort()
.Build();
}
/// <summary>
/// As reported: <see href="https://github.com/cmendible/netDumbster/issues/26"/>
/// </summary>
[Fact]
public async Task Send_WithMailKit_WholeBodyMessageIsPreserved()
{
var expectedBody = $"this is the body{Environment.NewLine}line2{Environment.NewLine}line3";

/// <summary>
/// As reported: <see href="https://github.com/cmendible/netDumbster/issues/26"/>
/// </summary>
[Fact]
public async Task Send_WithMailKit_WholeBodyMessageIsPreserved()
using var client = new SmtpClient
{
var expectedBody = $"this is the body{Environment.NewLine}line2{Environment.NewLine}line3";
ServerCertificateValidationCallback = (_, __, ___, ____) => true
};

using var client = new SmtpClient
{
ServerCertificateValidationCallback = (_, __, ___, ____) => true
};
await client.ConnectAsync("localhost", _server.Configuration.Port, false).ConfigureAwait(true);
client.AuthenticationMechanisms.Remove("XOAUTH2");

await client.ConnectAsync("localhost", _server.Configuration.Port, false).ConfigureAwait(false);
client.AuthenticationMechanisms.Remove("XOAUTH2");
var from = new MailboxAddress("from", "[email protected]");
var to = new MailboxAddress("to", "[email protected]");

var from = new MailboxAddress("from", "[email protected]");
var to = new MailboxAddress("to", "[email protected]");
var message = new MimeMessage();

var message = new MimeMessage();
message.From.Add(from);
message.To.Add(to);
message.Subject = "test";
message.Body = new TextPart("plain") { Text = expectedBody };
message.Headers.Add("empty-value", string.Empty);

message.From.Add(from);
message.To.Add(to);
message.Subject = "test";
message.Body = new TextPart("plain") { Text = expectedBody };
message.Headers.Add("empty-value", string.Empty);
client.Send(message);

client.Send(message);
Assert.Equal(1, _server.ReceivedEmailCount);
Assert.Equal(expectedBody, _server.ReceivedEmail[0].MessageParts[0].BodyData);
}

Assert.Equal(1, _server.ReceivedEmailCount);
Assert.Equal(expectedBody, _server.ReceivedEmail[0].MessageParts[0].BodyData);
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (_disposed)
return;

protected virtual void Dispose(bool disposing)
if (disposing)
{
if (_disposed)
return;

if (disposing)
{
_server.Stop();
}

_disposed = true;
_server.Stop();
}

_disposed = true;
}
}

37 changes: 15 additions & 22 deletions netDumbster.Test/RepeatAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,33 +1,26 @@
// Copyright (c) 2010, Hexasystems Corporation
// All rights reserved.

namespace netDumbster.Test
namespace netDumbster.Test;

public class RepeatAttribute : DataAttribute
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Xunit.Sdk;
private readonly int times;

public class RepeatAttribute : DataAttribute
public RepeatAttribute(int count)
{
private readonly int times;

public RepeatAttribute(int count)
if (count < 1)
{
if (count < 1)
{
throw new ArgumentOutOfRangeException(
nameof(count),
"Repeat count must be greater than 0.");
}
times = count;
throw new ArgumentOutOfRangeException(
nameof(count),
"Repeat count must be greater than 0.");
}
times = count;
}

public override IEnumerable<object[]> GetData(MethodInfo testMethod)
{
return Enumerable.Repeat(Array.Empty<object>(), times);
}
public override IEnumerable<object[]> GetData(MethodInfo testMethod)
{
return Enumerable.Repeat(Array.Empty<object>(), times);
}
}

}
Loading

0 comments on commit d379a13

Please sign in to comment.