Skip to content

Commit

Permalink
chore: fix several small findings
Browse files Browse the repository at this point in the history
  • Loading branch information
BEagle1984 committed Aug 29, 2021
1 parent 94f83bc commit 98c8139
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 28 deletions.
6 changes: 2 additions & 4 deletions src/Silverback.Core/Util/Check.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ public static string NotEmpty(

public static IReadOnlyCollection<T> HasNoNulls<T>(
IReadOnlyCollection<T?>? value,
[InvokerParameterName] [System.Diagnostics.CodeAnalysis.NotNull]
string parameterName)
[InvokerParameterName] string parameterName)
where T : class
{
value = NotNull(value, parameterName);
Expand All @@ -99,8 +98,7 @@ [InvokerParameterName] [System.Diagnostics.CodeAnalysis.NotNull]

public static IReadOnlyCollection<string?> HasNoEmpties(
IReadOnlyCollection<string?>? value,
[InvokerParameterName] [System.Diagnostics.CodeAnalysis.NotNull]
string parameterName)
[InvokerParameterName] string parameterName)
{
value = NotNull(value, parameterName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public Task RollbackAsync()

private static IBrokerMessageOffset InstantiateOffset(string clrType, string key, string value)
{
var offsetType = TypesCache.GetType(clrType)!;
var offsetType = TypesCache.GetType(clrType);
var offset = (IBrokerMessageOffset)Activator.CreateInstance(
offsetType,
key,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ public GenericOutboundHeadersEnricher(
/// <inheritdoc cref="IOutboundMessageEnricher.Enrich" />
public void Enrich(IOutboundEnvelope envelope)
{
if (envelope == null || envelope is not IOutboundEnvelope<TMessage> typedEnvelope)
Check.NotNull(envelope, nameof(envelope));

if (envelope is not IOutboundEnvelope<TMessage> typedEnvelope)
return;

envelope.Headers.AddOrReplace(_name, _valueProvider.Invoke(typedEnvelope));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ private async Task<bool> RollbackTransactionAndNotifyProcessingCompletedAsync(Ex
}
catch (Exception newException)
{
((ISequenceImplementation)this).NotifyProcessingFailed(newException!);
((ISequenceImplementation)this).NotifyProcessingFailed(newException);
}

return done;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public MessageValidationException(string message, Exception innerException)
/// destination.
/// </param>
protected MessageValidationException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Silverback.Core.Tests/Util/TypesCacheTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void GetType_WrongAssemblyVersion_TypeReturned()

var type = TypesCache.GetType(typeName);

type!.AssemblyQualifiedName.Should().Be(typeof(TestEventOne).AssemblyQualifiedName);
type.AssemblyQualifiedName.Should().Be(typeof(TestEventOne).AssemblyQualifiedName);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void Store_ExistingEntity_NewEventsSaved()
var person = repo.Find(p => p.Id == 12);

person!.ChangeName("Sergio");
person!.ChangeAge(35);
person.ChangeAge(35);

repo.Store(person);
_dbContext.SaveChanges();
Expand All @@ -109,7 +109,7 @@ public async Task StoreAsync_ExistingEntity_NewEventsSaved()
var person = await repo.FindAsync(p => p.Id == 12);

person!.ChangeName("Sergio");
person!.ChangeAge(35);
person.ChangeAge(35);

await repo.StoreAsync(person);
await _dbContext.SaveChangesAsync();
Expand Down Expand Up @@ -164,7 +164,7 @@ public void Store_ExistingEntity_VersionIncremented()
var person = repo.Find(p => p.Id == 12);

person!.ChangeName("Sergio");
person!.ChangeAge(35);
person.ChangeAge(35);

repo.Store(person);

Expand All @@ -189,7 +189,7 @@ public async Task StoreAsync_ExistingEntity_VersionIncremented()
var person = repo.Find(p => p.Id == 12);

person!.ChangeName("Sergio");
person!.ChangeAge(35);
person.ChangeAge(35);

await repo.StoreAsync(person);

Expand All @@ -215,9 +215,9 @@ public void Store_ConcurrentlyModifyExistingEntity_ExceptionThrown()
var person2 = repo.Find(p => p.Id == 12);

person!.ChangeName("Sergio");
person!.ChangeAge(35);
person.ChangeAge(35);
person2!.ChangeName("Sergio");
person2!.ChangeAge(35);
person2.ChangeAge(35);

repo.Store(person);
Action act = () => repo.Store(person2);
Expand All @@ -244,9 +244,9 @@ public async Task StoreAsync_ConcurrentlyModifyExistingEntity_ExceptionThrown()
var person2 = repo.Find(p => p.Id == 12);

person!.ChangeName("Sergio");
person!.ChangeAge(35);
person.ChangeAge(35);
person2!.ChangeName("Sergio");
person2!.ChangeAge(35);
person2.ChangeAge(35);

await repo.StoreAsync(person);
Func<Task> act = async () => await repo.StoreAsync(person2);
Expand Down Expand Up @@ -301,7 +301,7 @@ public void Find_ExistingId_EventsApplied()

entity.Should().NotBeNull();
entity!.Name.Should().Be("Silverback");
entity!.Age.Should().Be(35);
entity.Age.Should().Be(35);
}

[Fact]
Expand Down Expand Up @@ -364,7 +364,7 @@ public void Find_EventsWithLegacySerialization_EventsApplied()

entity.Should().NotBeNull();
entity!.Name.Should().Be("Silverback");
entity!.Age.Should().Be(35);
entity.Age.Should().Be(35);
}

[Fact]
Expand Down Expand Up @@ -424,7 +424,7 @@ public async Task FindAsync_ExistingId_EventsApplied()

entity.Should().NotBeNull();
entity!.Name.Should().Be("Silverback");
entity!.Age.Should().Be(35);
entity.Age.Should().Be(35);
}

[Fact]
Expand Down Expand Up @@ -487,7 +487,7 @@ public async Task FindAsync_EventsWithLegacySerialization_EventsApplied()

entity.Should().NotBeNull();
entity!.Name.Should().Be("Silverback");
entity!.Age.Should().Be(35);
entity.Age.Should().Be(35);
}

[Fact]
Expand Down Expand Up @@ -545,7 +545,7 @@ public void Find_ExistingIdWithPastSnapshot_OnlyRelevantEventsApplied()

entity.Should().NotBeNull();
entity!.Name.Should().Be("Sergio");
entity!.Age.Should().Be(16);
entity.Age.Should().Be(16);
}

[Fact]
Expand Down Expand Up @@ -595,7 +595,7 @@ public async Task FindAsync_ExistingIdWithPastSnapshot_OnlyRelevantEventsApplied

entity.Should().NotBeNull();
entity!.Name.Should().Be("Sergio");
entity!.Age.Should().Be(16);
entity.Age.Should().Be(16);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public async Task GetSequence_FirstChunk_SequenceReturned()
var sequence = await new ChunkSequenceReader().GetSequenceAsync(context);

sequence.Should().NotBeNull();
sequence!.TotalLength.Should().Be(4);
sequence.TotalLength.Should().Be(4);
sequence.IsNew.Should().BeTrue();
}

Expand Down Expand Up @@ -126,7 +126,7 @@ public async Task GetSequence_ChunkForExistingSequence_SequenceReturned()

sequence1.Should().NotBeNull();
sequence1.Should().BeOfType<ChunkSequence>();
sequence1!.TotalLength.Should().Be(4);
sequence1.TotalLength.Should().Be(4);
sequence1.IsNew.Should().BeTrue();

var context2 = ConsumerPipelineContextHelper.CreateSubstitute(
Expand All @@ -137,7 +137,7 @@ public async Task GetSequence_ChunkForExistingSequence_SequenceReturned()

sequence2.Should().NotBeNull();
sequence2.Should().BeSameAs(sequence1);
sequence2!.IsNew.Should().BeFalse();
sequence2.IsNew.Should().BeFalse();
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public async Task AddAsyncAndGetAsync_Sequence_IsNewFlagAutomaticallyHandled()

sequence = (await store.GetAsync<ChunkSequence>("abc"))!;

sequence!.IsNew.Should().BeFalse();
sequence.IsNew.Should().BeFalse();
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) 2020 Sergio Aquilini
// This code is licensed under MIT license (see LICENSE file for details)

using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics.CodeAnalysis;
using BenchmarkDotNet.Attributes;
using Silverback.Messaging.Validation;
Expand Down

0 comments on commit 98c8139

Please sign in to comment.