From a1ca437d5042d43d7fd167c595b24f108e5c44c5 Mon Sep 17 00:00:00 2001 From: Oleg Rakhmatulin Date: Mon, 4 Mar 2024 10:25:18 +0100 Subject: [PATCH] Cleaned up code a bit with help of R# solution analysis. --- .../AlpacaTradingClientTest.Account.cs | 12 +++++++----- .../AlpacaTradingClientTest.Assets.cs | 4 +++- .../AlpacaTradingClientTest.Options.cs | 2 ++ Alpaca.Markets.Tests/HistoricalDataHelpers.cs | 8 +++++--- Alpaca.Markets.Tests/MockClientsFactory.cs | 2 ++ Alpaca.Markets/Messages/JsonOptionQuote.cs | 4 +--- .../Parameters/HistoricalOptionBarsRequest.cs | 6 +++--- .../Parameters/HistoricalOptionTradesRequest.cs | 4 ++-- 8 files changed, 25 insertions(+), 17 deletions(-) diff --git a/Alpaca.Markets.Tests/AlpacaTradingClientTest.Account.cs b/Alpaca.Markets.Tests/AlpacaTradingClientTest.Account.cs index c85f135a..4cf8eaf7 100644 --- a/Alpaca.Markets.Tests/AlpacaTradingClientTest.Account.cs +++ b/Alpaca.Markets.Tests/AlpacaTradingClientTest.Account.cs @@ -9,7 +9,9 @@ public sealed partial class AlpacaTradingClientTest private const Decimal Price = 1234.56M; [Fact] +#pragma warning disable IDE0079 // Remove unnecessary suppression [SuppressMessage("ReSharper", "StringLiteralTypo")] +#pragma warning restore IDE0079 // Remove unnecessary suppression public async Task GetAccountAsyncWorks() { const Decimal cash = 10_000M; @@ -67,11 +69,11 @@ public async Task GetAccountAsyncWorks() Assert.Equal(transfer, account.AccruedFees); Assert.Equal(cash, account.OptionsBuyingPower); - Assert.True(account.LastMaintenanceMargin != 0M); - Assert.True(account.MaintenanceMargin != 0M); - Assert.True(account.TradableCash != 0M); - Assert.True(account.LastEquity != 0M); - Assert.True(account.Sma != 0M); + Assert.NotEqual(0M, account.LastMaintenanceMargin); + Assert.NotEqual(0M, account.MaintenanceMargin); + Assert.NotEqual(0M, account.TradableCash); + Assert.NotEqual(0M, account.LastEquity); + Assert.NotEqual(0M, account.Sma); Assert.NotNull(account.AccountNumber); diff --git a/Alpaca.Markets.Tests/AlpacaTradingClientTest.Assets.cs b/Alpaca.Markets.Tests/AlpacaTradingClientTest.Assets.cs index ac3e03aa..1c95075a 100644 --- a/Alpaca.Markets.Tests/AlpacaTradingClientTest.Assets.cs +++ b/Alpaca.Markets.Tests/AlpacaTradingClientTest.Assets.cs @@ -67,7 +67,9 @@ private static JObject createAsset( new JProperty("name", symbol), new JProperty("id", assetId)); +#pragma warning disable IDE0079 [SuppressMessage("ReSharper", "ParameterOnlyUsedForPreconditionCheck.Local")] +#pragma warning restore IDE0079 private static void validateAsset( IAsset asset, Guid assetId, @@ -91,6 +93,6 @@ private static void validateAsset( Assert.NotNull(asset.MaintenanceMarginRequirement); Assert.Single(asset.Attributes); - Assert.Equal(AssetAttributes.PtpNoException, asset.Attributes.First()); + Assert.Equal(AssetAttributes.PtpNoException, asset.Attributes[0]); } } diff --git a/Alpaca.Markets.Tests/AlpacaTradingClientTest.Options.cs b/Alpaca.Markets.Tests/AlpacaTradingClientTest.Options.cs index 91ee59f1..e8a1b4b8 100644 --- a/Alpaca.Markets.Tests/AlpacaTradingClientTest.Options.cs +++ b/Alpaca.Markets.Tests/AlpacaTradingClientTest.Options.cs @@ -88,7 +88,9 @@ private static JObject createOptionContract( new JProperty("name", symbol), new JProperty("size", 100)); +#pragma warning disable IDE0079 [SuppressMessage("ReSharper", "ParameterOnlyUsedForPreconditionCheck.Local")] +#pragma warning restore IDE0079 private static void validateOptionContract( IOptionContract optionContract, Guid contractId, diff --git a/Alpaca.Markets.Tests/HistoricalDataHelpers.cs b/Alpaca.Markets.Tests/HistoricalDataHelpers.cs index d6840b34..e625f05a 100644 --- a/Alpaca.Markets.Tests/HistoricalDataHelpers.cs +++ b/Alpaca.Markets.Tests/HistoricalDataHelpers.cs @@ -2,8 +2,10 @@ namespace Alpaca.Markets.Tests; +#pragma warning disable IDE0079 // Remove unnecessary suppression [SuppressMessage("ReSharper", "ParameterOnlyUsedForPreconditionCheck.Global")] [SuppressMessage("ReSharper", "ParameterOnlyUsedForPreconditionCheck.Local")] +#pragma warning restore IDE0079 // Remove unnecessary suppression internal static class HistoricalDataHelpers { private static readonly String _condition = Guid.NewGuid().ToString("D"); @@ -189,9 +191,9 @@ public static Boolean Validate( Assert.InRange(bar.Open, bar.Low, bar.High); Assert.True(bar.TimeUtc <= DateTime.UtcNow); - Assert.True(bar.TradeCount != 0); - Assert.True(bar.Volume != 0M); - Assert.True(bar.Vwap != 0M); + Assert.NotEqual(0UL, bar.TradeCount); + Assert.NotEqual(0M, bar.Volume); + Assert.NotEqual(0M, bar.Vwap); return true; } diff --git a/Alpaca.Markets.Tests/MockClientsFactory.cs b/Alpaca.Markets.Tests/MockClientsFactory.cs index ac78ca74..5a20daf0 100644 --- a/Alpaca.Markets.Tests/MockClientsFactory.cs +++ b/Alpaca.Markets.Tests/MockClientsFactory.cs @@ -4,7 +4,9 @@ namespace Alpaca.Markets.Tests; +#pragma warning disable IDE0079 // Remove unnecessary suppression [SuppressMessage("ReSharper", "ClassNeverInstantiated.Global")] +#pragma warning restore IDE0079 // Remove unnecessary suppression public sealed class MockClientsFactoryFixture { private readonly SecurityKey _secretKey = new SecretKey( diff --git a/Alpaca.Markets/Messages/JsonOptionQuote.cs b/Alpaca.Markets/Messages/JsonOptionQuote.cs index ea00fd1e..84512abf 100644 --- a/Alpaca.Markets/Messages/JsonOptionQuote.cs +++ b/Alpaca.Markets/Messages/JsonOptionQuote.cs @@ -1,6 +1,4 @@ -using Newtonsoft.Json.Linq; - -namespace Alpaca.Markets; +namespace Alpaca.Markets; [DebuggerDisplay("{DebuggerDisplay,nq}", Type = nameof(IQuote))] [SuppressMessage( diff --git a/Alpaca.Markets/Parameters/HistoricalOptionBarsRequest.cs b/Alpaca.Markets/Parameters/HistoricalOptionBarsRequest.cs index e06144c6..1b6358d3 100644 --- a/Alpaca.Markets/Parameters/HistoricalOptionBarsRequest.cs +++ b/Alpaca.Markets/Parameters/HistoricalOptionBarsRequest.cs @@ -39,7 +39,7 @@ public HistoricalOptionBarsRequest( String symbol, BarTimeFrame timeFrame, Interval timeInterval) - : this(new[] { symbol.EnsureNotNull() }, timeInterval, timeFrame) + : this([ symbol.EnsureNotNull() ], timeInterval, timeFrame) { } @@ -127,7 +127,7 @@ internal override QueryBuilder AddParameters( HistoricalOptionBarsRequest IHistoricalRequest.GetValidatedRequestWithoutPageToken() => new HistoricalOptionBarsRequest(Symbols, TimeInterval, TimeFrame) { - SortDirection = SortDirection, + SortDirection = SortDirection } .WithPageSize(this.GetPageSize()); -} \ No newline at end of file +} diff --git a/Alpaca.Markets/Parameters/HistoricalOptionTradesRequest.cs b/Alpaca.Markets/Parameters/HistoricalOptionTradesRequest.cs index 4ac9e5c7..da18b5d1 100644 --- a/Alpaca.Markets/Parameters/HistoricalOptionTradesRequest.cs +++ b/Alpaca.Markets/Parameters/HistoricalOptionTradesRequest.cs @@ -107,7 +107,7 @@ public HistoricalOptionTradesRequest( HistoricalOptionTradesRequest IHistoricalRequest.GetValidatedRequestWithoutPageToken() => new HistoricalOptionTradesRequest(Symbols, TimeInterval) { - SortDirection = SortDirection, + SortDirection = SortDirection } .WithPageSize(this.GetPageSize()); -} \ No newline at end of file +}