Skip to content

Commit

Permalink
Removed talkie validations to standard dotnet validations
Browse files Browse the repository at this point in the history
  • Loading branch information
fembina committed Sep 18, 2024
1 parent a99a525 commit b9da946
Show file tree
Hide file tree
Showing 23 changed files with 73 additions and 144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Talkie.Bridges.Telegram.Configurations;
using Talkie.Bridges.Telegram.Models;
using Talkie.Bridges.Telegram.Serialization;
using Talkie.Validations;
using ClientHttpVersion = System.Net.HttpVersion;

namespace Talkie.Bridges.Telegram.Clients;
Expand All @@ -30,7 +29,8 @@ public sealed class TelegramBotApiClient : ITelegramBotApiClient
public TelegramBotApiClient(ServerConfiguration serverConfiguration,
ClientConfiguration? clientConfiguration = null)
{
serverConfiguration.ThrowIf().Null();
ArgumentNullException.ThrowIfNull(serverConfiguration);

clientConfiguration ??= new ClientConfiguration();

_useGzipCompression = clientConfiguration.UseGzipCompression;
Expand All @@ -41,8 +41,8 @@ public TelegramBotApiClient(ServerConfiguration serverConfiguration,
async Task<TResult> ITelegramBotApiClient.SendAsync<TResult, TRequest>(string methodName, TRequest request,
CancellationToken cancellationToken)
{
methodName.ThrowIf().NullOrWhiteSpace();
request.ThrowIf().Null();
ArgumentNullException.ThrowIfNull(request);
ArgumentException.ThrowIfNullOrWhiteSpace(methodName);

using var scopedCancellationTokenSource = CancellationTokenSource
.CreateLinkedTokenSource(_globalCancellationTokenSource.Token, cancellationToken);
Expand All @@ -55,23 +55,23 @@ async Task<TResult> ITelegramBotApiClient.SendAsync<TResult, TRequest>(string me
async Task<TResult> ITelegramBotApiClient.SendAsync<TResult>(string methodName,
CancellationToken cancellationToken)
{
methodName.ThrowIf().NullOrWhiteSpace();
ArgumentException.ThrowIfNullOrWhiteSpace(methodName);

using var scopedCancellationTokenSource = CancellationTokenSource
.CreateLinkedTokenSource(_globalCancellationTokenSource.Token, cancellationToken);

var result = await SendRepeatableRequestAsync<TResult, object>(methodName, null, scopedCancellationTokenSource.Token);

result.ThrowIf().Null();
ArgumentNullException.ThrowIfNull(result);

return result;
}

Task ITelegramBotApiClient.SendAsync<TRequest>(string methodName, TRequest request,
CancellationToken cancellationToken)
{
methodName.ThrowIf().NullOrWhiteSpace();
request.ThrowIf().Null();
ArgumentNullException.ThrowIfNull(request);
ArgumentException.ThrowIfNullOrWhiteSpace(methodName);

using var scopedCancellationTokenSource = CancellationTokenSource
.CreateLinkedTokenSource(_globalCancellationTokenSource.Token, cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Net;
using System.Text;
using Talkie.Bridges.Telegram.Models;
using Talkie.Validations;

namespace Talkie.Bridges.Telegram.Clients;

Expand All @@ -14,8 +13,8 @@ public TelegramBotApiRequestException(ITelegramBotApiClient client, string metho
IReadOnlyDictionary<string, TextOrNumber>? parameters = null,
Exception? innerException = null) : base(null, innerException)
{
client.ThrowIf().Null();
methodName.ThrowIf().NullOrWhiteSpace();
ArgumentNullException.ThrowIfNull(client);
ArgumentException.ThrowIfNullOrWhiteSpace(methodName);

Client = client;
MethodName = methodName;
Expand Down
3 changes: 1 addition & 2 deletions Sources/Falko.Talkie.Bridges.Telegram/Models/TextOrNumber.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using Talkie.Validations;

namespace Talkie.Bridges.Telegram.Models;

Expand All @@ -16,7 +15,7 @@ public readonly struct TextOrNumber

public TextOrNumber(string text)
{
text.ThrowIf().Null();
ArgumentNullException.ThrowIfNull(text);

_text = text;
_containsTextOrNumber = true;
Expand Down
15 changes: 15 additions & 0 deletions Sources/Falko.Talkie.Core/Sequences/SequenceExtensions.AddRange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ public static partial class SequenceExtensions
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void AddRange<T>(this ISequence<T> sequence, IEnumerable<T> values)
{
ArgumentNullException.ThrowIfNull(sequence);
ArgumentNullException.ThrowIfNull(values);

foreach (var value in values)
{
sequence.Add(value);
Expand All @@ -16,6 +19,9 @@ public static void AddRange<T>(this ISequence<T> sequence, IEnumerable<T> values
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void AddRange<T>(this ISequence<T> sequence, IReadOnlyCollection<T> values)
{
ArgumentNullException.ThrowIfNull(sequence);
ArgumentNullException.ThrowIfNull(values);

if (values.Count is 0) return;

foreach (var value in values)
Expand All @@ -27,6 +33,9 @@ public static void AddRange<T>(this ISequence<T> sequence, IReadOnlyCollection<T
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void AddRange<T>(this ISequence<T> sequence, Sequence<T> values)
{
ArgumentNullException.ThrowIfNull(sequence);
ArgumentNullException.ThrowIfNull(values);

if (values.Count is 0) return;

foreach (var value in values)
Expand All @@ -38,6 +47,9 @@ public static void AddRange<T>(this ISequence<T> sequence, Sequence<T> values)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void AddRange<T>(this ISequence<T> sequence, RemovableSequence<T> values)
{
ArgumentNullException.ThrowIfNull(sequence);
ArgumentNullException.ThrowIfNull(values);

if (values.Count is 0) return;

foreach (var value in values)
Expand All @@ -49,6 +61,9 @@ public static void AddRange<T>(this ISequence<T> sequence, RemovableSequence<T>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void AddRange<T>(this ISequence<T> sequence, FrozenSequence<T> values)
{
ArgumentNullException.ThrowIfNull(sequence);
ArgumentNullException.ThrowIfNull(values);

if (values.Count is 0) return;

foreach (var value in values)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Runtime.CompilerServices;
using Talkie.Validations;

namespace Talkie.Sequences;

Expand All @@ -8,8 +7,8 @@ public static partial class SequenceExtensions
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ForEach<T>(this IReadOnlySequence<T> sequence, Action<T> action) where T : notnull
{
sequence.ThrowIf().Null();
action.ThrowIf().Null();
ArgumentNullException.ThrowIfNull(sequence);
ArgumentNullException.ThrowIfNull(action);

if (sequence.Count is 0) return;

Expand All @@ -22,8 +21,8 @@ public static void ForEach<T>(this IReadOnlySequence<T> sequence, Action<T> acti
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ForEach<T>(this Sequence<T> sequence, Action<T> action) where T : notnull
{
sequence.ThrowIf().Null();
action.ThrowIf().Null();
ArgumentNullException.ThrowIfNull(sequence);
ArgumentNullException.ThrowIfNull(action);

if (sequence.Count is 0) return;

Expand All @@ -36,8 +35,8 @@ public static void ForEach<T>(this Sequence<T> sequence, Action<T> action) where
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ForEach<T>(this RemovableSequence<T> sequence, Action<T> action) where T : notnull
{
sequence.ThrowIf().Null();
action.ThrowIf().Null();
ArgumentNullException.ThrowIfNull(sequence);
ArgumentNullException.ThrowIfNull(action);

if (sequence.Count is 0) return;

Expand All @@ -50,8 +49,8 @@ public static void ForEach<T>(this RemovableSequence<T> sequence, Action<T> acti
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ForEach<T>(this FrozenSequence<T> sequence, Action<T> action) where T : notnull
{
sequence.ThrowIf().Null();
action.ThrowIf().Null();
ArgumentNullException.ThrowIfNull(sequence);
ArgumentNullException.ThrowIfNull(action);

if (sequence.Count is 0) return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ public static partial class SequenceExtensions
{
public static FrozenSequence<T> ToFrozenSequence<T>(this IEnumerable<T> values)
{
ArgumentNullException.ThrowIfNull(values);

if (values is FrozenSequence<T> sequence) return sequence;

return new FrozenSequence<T>(values);
}

public static FrozenSequence<T> ToFrozenSequence<T>(this IReadOnlyCollection<T> values)
{
ArgumentNullException.ThrowIfNull(values);

if (values.Count is 0) return FrozenSequence<T>.Empty;

if (values is FrozenSequence<T> sequence) return sequence;
Expand All @@ -23,6 +27,8 @@ public static FrozenSequence<T> ToFrozenSequence<T>(this IReadOnlyCollection<T>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static FrozenSequence<T> ToFrozenSequence<T>(this FrozenSequence<T> values)
{
ArgumentNullException.ThrowIfNull(values);

return values;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@ namespace Talkie.Sequences;

public static partial class SequenceExtensions
{
public static RemovableSequence<T> ToRemovableSequence<T>(this IEnumerable<T> enumerable) where T : notnull
public static RemovableSequence<T> ToRemovableSequence<T>(this IEnumerable<T> values) where T : notnull
{
ArgumentNullException.ThrowIfNull(values);

var sequence = new RemovableSequence<T>();

sequence.AddRange(enumerable);
sequence.AddRange(values);

return sequence;
}

public static RemovableSequence<T> ToRemovableSequence<T>(this IReadOnlyCollection<T> values) where T : notnull
{
ArgumentNullException.ThrowIfNull(values);

if (values.Count is 0) return [];

var sequence = new RemovableSequence<T>();
Expand All @@ -24,6 +28,8 @@ public static RemovableSequence<T> ToRemovableSequence<T>(this IReadOnlyCollecti

public static RemovableSequence<T> ToRemovableSequence<T>(this Sequence<T> values) where T : notnull
{
ArgumentNullException.ThrowIfNull(values);

if (values.Count is 0) return [];

var sequence = new RemovableSequence<T>();
Expand All @@ -35,6 +41,8 @@ public static RemovableSequence<T> ToRemovableSequence<T>(this Sequence<T> value

public static RemovableSequence<T> ToRemovableSequence<T>(this RemovableSequence<T> values) where T : notnull
{
ArgumentNullException.ThrowIfNull(values);

if (values.Count is 0) return [];

var sequence = new RemovableSequence<T>();
Expand All @@ -46,6 +54,8 @@ public static RemovableSequence<T> ToRemovableSequence<T>(this RemovableSequence

public static RemovableSequence<T> ToRemovableSequence<T>(this FrozenSequence<T> values) where T : notnull
{
ArgumentNullException.ThrowIfNull(values);

if (values.Count is 0) return [];

var sequence = new RemovableSequence<T>();
Expand Down
10 changes: 0 additions & 10 deletions Sources/Falko.Talkie.Core/Validations/Throwable.cs

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using Talkie.Models.Profiles;
using Talkie.Platforms;
using Talkie.Sequences;
using Talkie.Validations;

namespace Talkie.Connections;

Expand All @@ -23,8 +22,8 @@ public sealed class TelegramSignalConnection(ISignalFlow flow,

protected override async Task WhenInitializingAsync(CancellationToken cancellationToken)
{
serverConfiguration.ThrowIf().Null();
clientConfiguration.ThrowIf().Null();
ArgumentNullException.ThrowIfNull(serverConfiguration);
ArgumentNullException.ThrowIfNull(clientConfiguration);

var client = new TelegramBotApiClient(serverConfiguration, clientConfiguration);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using Talkie.Models.Messages.Outgoing;
using Talkie.Platforms;
using Talkie.Sequences;
using Talkie.Validations;

namespace Talkie.Controllers.MessageControllers;

Expand All @@ -20,7 +19,10 @@ public async Task<IIncomingMessage> PublishMessageAsync(IOutgoingMessage message
MessagePublishingFeatures features = default,
CancellationToken cancellationToken = default)
{
message.Content.ThrowIf().Null();
if (message.Content.IsEmpty)
{
throw new ArgumentException("Message content is required.");
}

if (environmentProfileIdentifier.TryGetValue(out long receiverId) is not true)
{
Expand Down
Loading

0 comments on commit b9da946

Please sign in to comment.