Skip to content

Commit

Permalink
More tests and some config adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
khanjal committed Dec 1, 2024
1 parent 46073bb commit 0a0978a
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using FluentAssertions;
using RLE.Core.Extensions;
using RLE.Stock.Entities;
using RLE.Stock.Enums;
using RLE.Stock.Mappers;
using RLE.Stock.Tests.Data;
using RLE.Test.Helpers;
using Xunit;

namespace RLE.Stock.Tests.Mappers.MapFromRangeData;

[Collection("Google Data collection")]
public class TickerMapFromRangeDataTests
{
readonly GoogleDataFixture fixture;
private static IList<IList<object>>? _values;
private static List<TickerEntity>? _entities;

public TickerMapFromRangeDataTests(GoogleDataFixture fixture)
{
this.fixture = fixture;
_values = this.fixture.valueRanges?.Where(x => x.DataFilters[0].A1Range == SheetEnum.TICKERS.GetDescription()).First().ValueRange.Values;
_entities = TickerMapper.MapFromRangeData(_values!);
}

[Fact]
public void GivenAccountSheetData_ThenReturnRangeData()
{
var nonEmptyValues = _values!.Where(x => !string.IsNullOrEmpty(x[0].ToString())).ToList();
_entities.Should().HaveCount(nonEmptyValues.Count - 1);

foreach (var entity in _entities!)
{
entity.Id.Should().NotBe(0);
entity.Ticker.Should().NotBeNullOrEmpty();
entity.Name.Should().NotBeNullOrEmpty();
entity.Shares.Should().BeGreaterThanOrEqualTo(0);
entity.AverageCost.Should().BeGreaterThanOrEqualTo(0);
entity.CostTotal.Should().BeGreaterThanOrEqualTo(0);
entity.CurrentPrice.Should().BeGreaterThanOrEqualTo(0);
entity.CurrentTotal.Should().BeGreaterThanOrEqualTo(0);
entity.WeekHigh52.Should().BeGreaterThanOrEqualTo(0);
entity.WeekLow52.Should().BeGreaterThanOrEqualTo(0);
entity.MaxHigh.Should().BeGreaterThanOrEqualTo(0);
entity.MinLow.Should().BeGreaterThanOrEqualTo(0);
}
}

[Fact]
public void GivenAccountSheetDataColumnOrderRandomized_ThenReturnSameRangeData()
{
var sheetOrder = new int[] { 0 }.Concat([.. RandomHelpers.GetRandomOrder(1, _values![0].Count - 1)]).ToArray();
var randomValues = RandomHelpers.RandomizeValues(_values, sheetOrder);

var randomEntities = TickerMapper.MapFromRangeData(randomValues);
var nonEmptyRandomValues = randomValues!.Where(x => !string.IsNullOrEmpty(x[0].ToString())).ToList();
randomEntities.Should().HaveCount(nonEmptyRandomValues.Count - 1);

for (int i = 0; i < randomEntities.Count; i++)
{
var entity = _entities![i];
var randomEntity = randomEntities[i];

entity.Id.Should().Be(randomEntity.Id);
entity.Ticker.Should().BeEquivalentTo(randomEntity.Ticker);
entity.Name.Should().BeEquivalentTo(randomEntity.Name);
entity.Shares.Should().Be(randomEntity.Shares);
entity.AverageCost.Should().Be(randomEntity.AverageCost);
entity.CostTotal.Should().Be(randomEntity.CostTotal);
entity.CurrentPrice.Should().Be(randomEntity.CurrentPrice);
entity.CurrentTotal.Should().Be(randomEntity.CurrentTotal);
entity.Return.Should().Be(randomEntity.Return);
entity.PeRatio.Should().Be(randomEntity.PeRatio);
entity.WeekHigh52.Should().Be(randomEntity.WeekHigh52);
entity.WeekLow52.Should().Be(randomEntity.WeekLow52);
entity.MaxHigh.Should().Be(randomEntity.MaxHigh);
entity.MinLow.Should().Be(randomEntity.MinLow);
}
}
}
47 changes: 47 additions & 0 deletions RLE.Stock.Tests/Mappers/MapperGetSheetTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using FluentAssertions;
using RLE.Core.Models.Google;
using RLE.Stock.Constants;
using RLE.Stock.Mappers;
using Xunit;

namespace RLE.Stock.Tests.Mappers;

public class MapperGetSheetTests
{
public static IEnumerable<object[]> Sheets =>
[
[AccountMapper.GetSheet(), SheetsConfig.AccountSheet],
[StockMapper.GetSheet(), SheetsConfig.StockSheet],
[TickerMapper.GetSheet(), SheetsConfig.TickerSheet],
];

[Theory]
[MemberData(nameof(Sheets))]
public void GivenGetSheetConfig_ThenReturnSheet(SheetModel result, SheetModel sheetConfig)
{
result.CellColor.Should().Be(sheetConfig.CellColor);
result.FreezeColumnCount.Should().Be(sheetConfig.FreezeColumnCount);
result.FreezeRowCount.Should().Be(sheetConfig.FreezeRowCount);
result.Headers.Count.Should().Be(sheetConfig.Headers.Count);
result.Name.Should().Be(sheetConfig.Name);
result.ProtectSheet.Should().Be(sheetConfig.ProtectSheet);
result.TabColor.Should().Be(sheetConfig.TabColor);

foreach (var configHeader in sheetConfig.Headers)
{
var resultHeader = result.Headers.First(x => x.Name == configHeader.Name);
resultHeader.Column.Should().NotBeNullOrWhiteSpace();

if (result.ProtectSheet)
resultHeader.Formula.Should().NotBeNullOrWhiteSpace();
}
}

//GetDataValidation

//GetSheetForRange

//GetCommonShiftGroupSheetHeaders

//GetCommonTripGroupSheetHeaders
}
21 changes: 16 additions & 5 deletions RLE.Stock/Constants/SheetsConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public static class SheetsConfig
new SheetCellModel { Name = HeaderEnum.ACCOUNT.GetDescription() },
new SheetCellModel { Name = HeaderEnum.STOCKS.GetDescription() },
.. CommonCostSheetHeaders,
.. CommonReturnSheetHeaders
]
};

Expand All @@ -35,8 +36,8 @@ public static class SheetsConfig
new SheetCellModel { Name = HeaderEnum.TICKER.GetDescription() },
new SheetCellModel { Name = HeaderEnum.NAME.GetDescription() },
new SheetCellModel { Name = HeaderEnum.ACCOUNT.GetDescription() },
.. CommonCostSheetHeaders,
.. CommonPriceSheetHeaders
.. CommonPriceSheetHeaders,
.. CommonHistorySheetHeaders
]
};

Expand All @@ -52,8 +53,8 @@ .. CommonPriceSheetHeaders
new SheetCellModel { Name = HeaderEnum.TICKER.GetDescription() },
new SheetCellModel { Name = HeaderEnum.NAME.GetDescription() },
new SheetCellModel { Name = HeaderEnum.ACCOUNTS.GetDescription() },
.. CommonCostSheetHeaders,
.. CommonPriceSheetHeaders
.. CommonPriceSheetHeaders,
.. CommonHistorySheetHeaders
]
};

Expand All @@ -62,12 +63,22 @@ .. CommonPriceSheetHeaders
new SheetCellModel { Name = HeaderEnum.SHARES.GetDescription() },
new SheetCellModel { Name = HeaderEnum.AVERAGE_COST.GetDescription() },
new SheetCellModel { Name = HeaderEnum.COST_TOTAL.GetDescription() },
];

private static List<SheetCellModel> CommonPriceSheetHeaders =>
[
.. CommonCostSheetHeaders,
new SheetCellModel { Name = HeaderEnum.CURRENT_PRICE.GetDescription() },
.. CommonReturnSheetHeaders,
];

private static List<SheetCellModel> CommonReturnSheetHeaders =>
[
new SheetCellModel { Name = HeaderEnum.CURRENT_TOTAL.GetDescription() },
new SheetCellModel { Name = HeaderEnum.RETURN.GetDescription() },
];

private static List<SheetCellModel> CommonPriceSheetHeaders =>
private static List<SheetCellModel> CommonHistorySheetHeaders =>
[
new SheetCellModel { Name = HeaderEnum.PE_RATIO.GetDescription() },
new SheetCellModel { Name = HeaderEnum.WEEK_HIGH_52.GetDescription() },
Expand Down

0 comments on commit 0a0978a

Please sign in to comment.