Skip to content

Commit

Permalink
Optimize class summary and optimize code structure (#229)
Browse files Browse the repository at this point in the history
* Add build script

* reactivate one unit test

* Update SmtpServerTests.cs

* Reactivate all unit tests

* Update SmtpServerTests.cs

* Update summary informations, coptimize code structure

* Reset SampleApp

* Optimize summary

* Fix unit tests warning

Support for 'async void' unit tests is being removed from xUnit.net v3.
  • Loading branch information
tinohager authored Sep 3, 2024
1 parent 3f7dbe2 commit f47a84e
Show file tree
Hide file tree
Showing 98 changed files with 283 additions and 201 deletions.
5 changes: 1 addition & 4 deletions Examples/SampleApp/Examples/CommonPortsExample.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using System;
using SmtpServer;
using System.Security.Cryptography.X509Certificates;
using System.Threading;
using SmtpServer;
using SmtpServer.ComponentModel;

namespace SampleApp.Examples
{
Expand Down
2 changes: 1 addition & 1 deletion Examples/SampleApp/SampleMailClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@ public SmtpResponse SendUnknownCommand(string command, CancellationToken cancell
}
}
}
}
}
2 changes: 1 addition & 1 deletion Examples/SampleApp/SampleMailboxFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ public override async Task<bool> CanDeliverToAsync(
return true;
}
}
}
}
2 changes: 1 addition & 1 deletion Examples/SampleApp/SampleMessageStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ public override async Task<SmtpResponse> SaveAsync(ISessionContext context, IMes
return SmtpResponse.Ok;
}
}
}
}
2 changes: 1 addition & 1 deletion Examples/SampleApp/SampleUserAuthenticator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ public override Task<bool> AuthenticateAsync(
return Task.FromResult(user == "user" && password == "password");
}
}
}
}
2 changes: 1 addition & 1 deletion Examples/SampleApp/TaskExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ public static void WaitWithoutException(this Task task)
}
}
}
}
}
2 changes: 1 addition & 1 deletion Examples/WorkerService/ConsoleMessageStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ public override async Task<SmtpResponse> SaveAsync(ISessionContext context, IMes
return SmtpResponse.Ok;
}
}
}
}
2 changes: 1 addition & 1 deletion Examples/WorkerService/Worker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ protected override Task ExecuteAsync(CancellationToken stoppingToken)
return _smtpServer.StartAsync(stoppingToken);
}
}
}
}
2 changes: 1 addition & 1 deletion Src/SmtpServer.Benchmarks/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ public static void Main(string[] args)
.With(ConfigOptions.DisableOptimizationsValidator));
}
}
}
}
2 changes: 1 addition & 1 deletion Src/SmtpServer.Benchmarks/ThroughputBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@ public void Send4()
_smtpClient.Send(Message4);
}
}
}
}
2 changes: 1 addition & 1 deletion Src/SmtpServer.Benchmarks/TokenizerBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ static IReadOnlyList<ArraySegment<byte>> Tokenize(params string[] text)
return text.Select(t => new ArraySegment<byte>(Encoding.ASCII.GetBytes(t))).ToList();
}
}
}
}
2 changes: 1 addition & 1 deletion Src/SmtpServer.Tests/MailClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,4 @@ public SmtpResponse SendUnknownCommand(string command, CancellationToken cancell
return SendCommand(command, cancellationToken);
}
}
}
}
10 changes: 5 additions & 5 deletions Src/SmtpServer.Tests/PipeReaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ static PipeReader CreatePipeReader(string text)

[Fact]
// ReSharper disable once InconsistentNaming
public async void CanReadLineAndRemoveTrailingCRLF()
public async Task CanReadLineAndRemoveTrailingCRLF()
{
// arrange
var reader = CreatePipeReader("abcde\r\n");
Expand All @@ -34,7 +34,7 @@ public async void CanReadLineAndRemoveTrailingCRLF()

[Fact]
// ReSharper disable once InconsistentNaming
public async void CanReadLinesWithInconsistentCRLF()
public async Task CanReadLinesWithInconsistentCRLF()
{
// arrange
var reader = CreatePipeReader("ab\rcd\ne\r\n");
Expand All @@ -49,7 +49,7 @@ public async void CanReadLinesWithInconsistentCRLF()

[Fact]
// ReSharper disable once InconsistentNaming
public async void CanReadMultipleLines()
public async Task CanReadMultipleLines()
{
// arrange
var reader = CreatePipeReader("abcde\r\nfghij\r\nklmno\r\n");
Expand All @@ -66,7 +66,7 @@ public async void CanReadMultipleLines()
}

[Fact]
public async void CanReadBlockWithDotStuffingRemoved()
public async Task CanReadBlockWithDotStuffingRemoved()
{
// arrange
var reader = CreatePipeReader("abcd\r\n..1234\r\n.\r\n");
Expand All @@ -85,4 +85,4 @@ await reader.ReadDotBlockAsync(
Assert.Equal("abcd\r\n.1234", text);
}
}
}
}
2 changes: 1 addition & 1 deletion Src/SmtpServer.Tests/SmtpParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -689,4 +689,4 @@ public void CanNotMakeIPv6AddressLiteral(string input)
Assert.False(result);
}
}
}
}
2 changes: 1 addition & 1 deletion Src/SmtpServer.Tests/SmtpServerDisposable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ public void Dispose()
/// </summary>
public SmtpServer Server { get; }
}
}
}
2 changes: 1 addition & 1 deletion Src/SmtpServer.Tests/SmtpServerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -494,4 +494,4 @@ SmtpServerDisposable CreateServer(
/// </summary>
public CancellationTokenSource CancellationTokenSource { get; }
}
}
}
2 changes: 1 addition & 1 deletion Src/SmtpServer.Tests/TokenReaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,4 @@ static bool TryMakeNumber(ref TokenReader r)
}
}
}
}
}
2 changes: 1 addition & 1 deletion Src/SmtpServer/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

[assembly: InternalsVisibleTo("SmtpServer.Tests")]
[assembly: InternalsVisibleTo("SmtpServer.Benchmarks")]
[assembly: InternalsVisibleTo("SampleApp")]
[assembly: InternalsVisibleTo("SampleApp")]
5 changes: 4 additions & 1 deletion Src/SmtpServer/Authentication/DelegatingUserAuthenticator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

namespace SmtpServer.Authentication
{
/// <summary>
/// Delegating User Authenticator
/// </summary>
public sealed class DelegatingUserAuthenticator : UserAuthenticator
{
readonly Func<ISessionContext, string, string, bool> _delegate;
Expand Down Expand Up @@ -71,4 +74,4 @@ public override Task<bool> AuthenticateAsync(
return Task.FromResult(_delegate(context, user, password));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@

namespace SmtpServer.Authentication
{
/// <summary>
/// Delegating User Authenticator Factory
/// </summary>
public sealed class DelegatingUserAuthenticatorFactory : IUserAuthenticatorFactory
{
readonly Func<ISessionContext, IUserAuthenticator> _delegate;

/// <summary>
/// Delegating User Authenticator Factory
/// </summary>
/// <param name="delegate"></param>
public DelegatingUserAuthenticatorFactory(Func<ISessionContext, IUserAuthenticator> @delegate)
{
_delegate = @delegate;
Expand All @@ -21,4 +28,4 @@ public IUserAuthenticator CreateInstance(ISessionContext context)
return _delegate(context);
}
}
}
}
5 changes: 4 additions & 1 deletion Src/SmtpServer/Authentication/IUserAuthenticator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

namespace SmtpServer.Authentication
{
/// <summary>
/// User Authenticator Interface
/// </summary>
public interface IUserAuthenticator
{
/// <summary>
Expand All @@ -15,4 +18,4 @@ public interface IUserAuthenticator
/// <returns>true if the user is authenticated, false if not.</returns>
Task<bool> AuthenticateAsync(ISessionContext context, string user, string password, CancellationToken cancellationToken);
}
}
}
5 changes: 4 additions & 1 deletion Src/SmtpServer/Authentication/IUserAuthenticatorFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@

namespace SmtpServer.Authentication
{
/// <summary>
/// User Authenticator Factory Interface
/// </summary>
public interface IUserAuthenticatorFactory : ISessionContextInstanceFactory<IUserAuthenticator> { }
}
}
5 changes: 4 additions & 1 deletion Src/SmtpServer/Authentication/UserAuthenticator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

namespace SmtpServer.Authentication
{
/// <summary>
/// User Authenticator
/// </summary>
public abstract class UserAuthenticator : IUserAuthenticator
{
public static readonly IUserAuthenticator Default = new DefaultUserAuthenticator();

Check warning on line 11 in Src/SmtpServer/Authentication/UserAuthenticator.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'UserAuthenticator.Default'
Expand Down Expand Up @@ -41,4 +44,4 @@ public override Task<bool> AuthenticateAsync(
}
}
}
}
}
5 changes: 4 additions & 1 deletion Src/SmtpServer/AuthenticationContext.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
namespace SmtpServer
{
/// <summary>
/// Authentication Context
/// </summary>
public sealed class AuthenticationContext
{
public static readonly AuthenticationContext Unauthenticated = new AuthenticationContext();

Check warning on line 8 in Src/SmtpServer/AuthenticationContext.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'AuthenticationContext.Unauthenticated'
Expand Down Expand Up @@ -32,4 +35,4 @@ public AuthenticationContext(string user)
/// </summary>
public bool IsAuthenticated { get; }
}
}
}
2 changes: 1 addition & 1 deletion Src/SmtpServer/ComponentModel/DisposableContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ public void Dispose()
/// </summary>
internal TInstance Instance { get; }
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
namespace SmtpServer.ComponentModel
{
/// <summary>
/// SessionContext Instance Factory Interface
/// </summary>
/// <typeparam name="TInstance"></typeparam>
public interface ISessionContextInstanceFactory<out TInstance>
{
/// <summary>
Expand All @@ -9,4 +13,4 @@ public interface ISessionContextInstanceFactory<out TInstance>
/// <returns>The service instance for the session context.</returns>
TInstance CreateInstance(ISessionContext context);
}
}
}
10 changes: 8 additions & 2 deletions Src/SmtpServer/ComponentModel/ServiceProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

namespace SmtpServer.ComponentModel
{
/// <summary>
/// Service Provider
/// </summary>
public sealed class ServiceProvider : IServiceProvider
{
public static readonly IServiceProvider Default = new ServiceProvider();

Check warning on line 14 in Src/SmtpServer/ComponentModel/ServiceProvider.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'ServiceProvider.Default'
Expand All @@ -15,7 +18,10 @@ public sealed class ServiceProvider : IServiceProvider
ISmtpCommandFactory _smtpCommandFactory;
IMailboxFilterFactory _mailboxFilterFactory;
IMessageStoreFactory _messageStoreFactory;


/// <summary>
/// Service Provider
/// </summary>
public ServiceProvider()
{
Add(UserAuthenticator.Default);
Expand Down Expand Up @@ -130,4 +136,4 @@ public object GetService(Type serviceType)
throw new NotSupportedException(serviceType.ToString());
}
}
}
}
2 changes: 1 addition & 1 deletion Src/SmtpServer/ComponentModel/ServiceProviderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ internal static TService GetService<TServiceFactory, TService>(this IServiceProv
return serviceProvider.GetServiceOrDefault(@default);
}
}
}
}
5 changes: 4 additions & 1 deletion Src/SmtpServer/EndpointDefinitionBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

namespace SmtpServer
{
/// <summary>
/// Endpoint Definition Builder
/// </summary>
public sealed class EndpointDefinitionBuilder
{
readonly List<Action<EndpointDefinition>> _setters = new List<Action<EndpointDefinition>>();
Expand Down Expand Up @@ -207,4 +210,4 @@ public X509Certificate GetServerCertificate(ISessionContext sessionContext)

#endregion
}
}
}
5 changes: 4 additions & 1 deletion Src/SmtpServer/Extensions/TaskExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

namespace SmtpServer
{
/// <summary>
/// Task Extensions
/// </summary>
static class TaskExtensions
{
/// <summary>
Expand Down Expand Up @@ -49,4 +52,4 @@ public static async Task<T> WithCancellation<T>(this Task<T> task, CancellationT
return await task.ConfigureAwait(false);
}
}
}
}
3 changes: 3 additions & 0 deletions Src/SmtpServer/ICertificateFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace SmtpServer
{
/// <summary>
/// Certificate Factory Interface
/// </summary>
public interface ICertificateFactory
{
/// <summary>
Expand Down
6 changes: 4 additions & 2 deletions Src/SmtpServer/IEndpointDefinition.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System;
using System.Net;
using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;

namespace SmtpServer
{
/// <summary>
/// Endpoint Definition Interface
/// </summary>
public interface IEndpointDefinition
{
/// <summary>
Expand Down Expand Up @@ -42,4 +44,4 @@ public interface IEndpointDefinition
/// </summary>
SslProtocols SupportedSslProtocols { get; }
}
}
}
Loading

0 comments on commit f47a84e

Please sign in to comment.