mirror of
https://github.com/DrMboga/WotBlitzStatisticsBlazor.git
synced 2026-10-21 02:17:20 +02:00
feat: operations unit tests
This commit is contained in:
1 parent
e1cc18a888
commit
a9eab26a6d
13 files changed
+672
-2
No files matched your search
@@ -0,0 +1 @@
|
|||||||
|
{"AccountInfoHistoryId":{"AccountId":571050560,"LastBattleTime":1609162559},"AccountId":571050560,"LastBattleTime":1609162559,"Battles":4350,"CapturePoints":1123,"DamageDealt":6471089,"DamageReceived":4879220,"DroppedCapturePoints":3304,"Frags":4023,"Frags8P":1527,"Hits":33400,"Losses":1797,"MaxFrags":7,"MaxFragsTankId":9249,"MaxXp":2307,"MaxXpTankId":64801,"Shots":38400,"Spotted":6960,"SurvivedBattles":1494,"WinAndSurvived":1467,"Wins":2522,"Xp":3904931,"AvgTier":0.0,"Wn7":0.0}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
{"AccountId":571050560,"Realm":1,"CreatedAt":1589961923,"LastBattleTime":1609162559,"Nickname":"mboga","UpdatedAt":1609163016}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
[{"TankInfoId":{"AccountId":571050560,"TankId":19969},"AccountId":571050560,"TankId":19969,"BattleLifeTimeInSeconds":4472,"LastBattleTime":1609162559,"InGarage":null,"MarkOfMastery":2},{"TankInfoId":{"AccountId":571050560,"TankId":20753},"AccountId":571050560,"TankId":20753,"BattleLifeTimeInSeconds":4224,"LastBattleTime":1609161466,"InGarage":null,"MarkOfMastery":3},{"TankInfoId":{"AccountId":571050560,"TankId":10513},"AccountId":571050560,"TankId":10513,"BattleLifeTimeInSeconds":2519,"LastBattleTime":1609161355,"InGarage":null,"MarkOfMastery":2},{"TankInfoId":{"AccountId":571050560,"TankId":3633},"AccountId":571050560,"TankId":3633,"BattleLifeTimeInSeconds":1752,"LastBattleTime":1609160646,"InGarage":null,"MarkOfMastery":2},{"TankInfoId":{"AccountId":571050560,"TankId":13889},"AccountId":571050560,"TankId":13889,"BattleLifeTimeInSeconds":30717,"LastBattleTime":1609066903,"InGarage":null,"MarkOfMastery":3},{"TankInfoId":{"AccountId":571050560,"TankId":13857},"AccountId":571050560,"TankId":13857,"BattleLifeTimeInSeconds":32121,"LastBattleTime":1609066454,"InGarage":null,"MarkOfMastery":3},{"TankInfoId":{"AccountId":571050560,"TankId":20481},"AccountId":571050560,"TankId":20481,"BattleLifeTimeInSeconds":10926,"LastBattleTime":1608999516,"InGarage":null,"MarkOfMastery":2},{"TankInfoId":{"AccountId":571050560,"TankId":49},"AccountId":571050560,"TankId":49,"BattleLifeTimeInSeconds":4437,"LastBattleTime":1608986512,"InGarage":null,"MarkOfMastery":3},{"TankInfoId":{"AccountId":571050560,"TankId":19745},"AccountId":571050560,"TankId":19745,"BattleLifeTimeInSeconds":8279,"LastBattleTime":1608985578,"InGarage":null,"MarkOfMastery":3},{"TankInfoId":{"AccountId":571050560,"TankId":64801},"AccountId":571050560,"TankId":64801,"BattleLifeTimeInSeconds":140212,"LastBattleTime":1608985486,"InGarage":null,"MarkOfMastery":4},{"TankInfoId":{"AccountId":571050560,"TankId":64065},"AccountId":571050560,"TankId":64065,"BattleLifeTimeInSeconds":12837,"LastBattleTime":1608982543,"InGarage":null,"MarkOfMastery":3},{"TankInfoId":{"AccountId":571050560,"TankId":62737},"AccountId":571050560,"TankId":62737,"BattleLifeTimeInSeconds":9532,"LastBattleTime":1608981888,"InGarage":null,"MarkOfMastery":2},{"TankInfoId":{"AccountId":571050560,"TankId":5169},"AccountId":571050560,"TankId":5169,"BattleLifeTimeInSeconds":7735,"LastBattleTime":1608932699,"InGarage":null,"MarkOfMastery":4},{"TankInfoId":{"AccountId":571050560,"TankId":2945},"AccountId":571050560,"TankId":2945,"BattleLifeTimeInSeconds":4606,"LastBattleTime":1608910447,"InGarage":null,"MarkOfMastery":2},{"TankInfoId":{"AccountId":571050560,"TankId":10769},"AccountId":571050560,"TankId":10769,"BattleLifeTimeInSeconds":20685,"LastBattleTime":1608827682,"InGarage":null,"MarkOfMastery":3},{"TankInfoId":{"AccountId":571050560,"TankId":21505},"AccountId":571050560,"TankId":21505,"BattleLifeTimeInSeconds":1773,"LastBattleTime":1608752638,"InGarage":null,"MarkOfMastery":3},{"TankInfoId":{"AccountId":571050560,"TankId":21281},"AccountId":571050560,"TankId":21281,"BattleLifeTimeInSeconds":1779,"LastBattleTime":1608751692,"InGarage":null,"MarkOfMastery":2},{"TankInfoId":{"AccountId":571050560,"TankId":10001},"AccountId":571050560,"TankId":10001,"BattleLifeTimeInSeconds":3603,"LastBattleTime":1608726600,"InGarage":null,"MarkOfMastery":3},{"TankInfoId":{"AccountId":571050560,"TankId":54801},"AccountId":571050560,"TankId":54801,"BattleLifeTimeInSeconds":105,"LastBattleTime":1608712864,"InGarage":null,"MarkOfMastery":0},{"TankInfoId":{"AccountId":571050560,"TankId":20497},"AccountId":571050560,"TankId":20497,"BattleLifeTimeInSeconds":10451,"LastBattleTime":1608583595,"InGarage":null,"MarkOfMastery":3},{"TankInfoId":{"AccountId":571050560,"TankId":53585},"AccountId":571050560,"TankId":53585,"BattleLifeTimeInSeconds":276,"LastBattleTime":1608557237,"InGarage":null,"MarkOfMastery":1},{"TankInfoId":{"AccountId":571050560,"TankId":54273},"AccountId":571050560,"TankId":54273,"BattleLifeTimeInSeconds":608,"LastBattleTime":1608501236,"InGarage":null,"MarkOfMastery":0},{"TankInfoId":{"AccountId":571050560,"TankId":11809},"AccountId":571050560,"TankId":11809,"BattleLifeTimeInSeconds":47483,"LastBattleTime":1608327944,"InGarage":null,"MarkOfMastery":4},{"TankInfoId":{"AccountId":571050560,"TankId":11553},"AccountId":571050560,"TankId":11553,"BattleLifeTimeInSeconds":4494,"LastBattleTime":1608303701,"InGarage":null,"MarkOfMastery":2},{"TankInfoId":{"AccountId":571050560,"TankId":593},"AccountId":571050560,"TankId":593,"BattleLifeTimeInSeconds":4658,"LastBattleTime":1608303184,"InGarage":null,"MarkOfMastery":3},{"TankInfoId":{"AccountId":571050560,"TankId":20049},"AccountId":571050560,"TankId":20049,"BattleLifeTimeInSeconds":20950,"LastBattleTime":1607873699,"InGarage":null,"MarkOfMastery":4},{"TankInfoId":{"AccountId":571050560,"TankId":4657},"AccountId":571050560,"TankId":4657,"BattleLifeTimeInSeconds":2556,"LastBattleTime":1607803559,"InGarage":null,"MarkOfMastery":2},{"TankInfoId":{"AccountId":571050560,"TanLine truncated
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
{"19969":{"TankInfoHistoryId":{"AccountId":571050560,"TankId":19969,"LastBattleTime":1609162559},"AccountId":571050560,"TankId":19969,"LastBattleTime":1609162559,"Battles":28,"CapturePoints":0,"DamageDealt":53479,"DamageReceived":43509,"DroppedCapturePoints":0,"Frags":22,"Frags8P":22,"Hits":231,"Losses":12,"MaxFrags":3,"MaxXp":2142,"Shots":254,"Spotted":61,"SurvivedBattles":10,"WinAndSurvived":10,"Wins":16,"Xp":28300,"Wn7":0.0,"MaxFragsTankId":null,"MaxXpTankId":null,"AvgTier":0.0},"20753":{"TankInfoHistoryId":{"AccountId":571050560,"TankId":20753,"LastBattleTime":1609161466},"AccountId":571050560,"TankId":20753,"LastBattleTime":1609161466,"Battles":22,"CapturePoints":7,"DamageDealt":46526,"DamageReceived":43470,"DroppedCapturePoints":19,"Frags":18,"Frags8P":18,"Hits":130,"Losses":8,"MaxFrags":2,"MaxXp":1927,"Shots":140,"Spotted":27,"SurvivedBattles":10,"WinAndSurvived":10,"Wins":14,"Xp":37747,"Wn7":0.0,"MaxFragsTankId":null,"MaxXpTankId":null,"AvgTier":0.0},"10513":{"TankInfoHistoryId":{"AccountId":571050560,"TankId":10513,"LastBattleTime":1609161355},"AccountId":571050560,"TankId":10513,"LastBattleTime":1609161355,"Battles":16,"CapturePoints":0,"DamageDealt":23374,"DamageReceived":26897,"DroppedCapturePoints":0,"Frags":16,"Frags8P":13,"Hits":100,"Losses":7,"MaxFrags":3,"MaxXp":1533,"Shots":116,"Spotted":22,"SurvivedBattles":6,"WinAndSurvived":5,"Wins":9,"Xp":19035,"Wn7":0.0,"MaxFragsTankId":null,"MaxXpTankId":null,"AvgTier":0.0},"3633":{"TankInfoHistoryId":{"AccountId":571050560,"TankId":3633,"LastBattleTime":1609160646},"AccountId":571050560,"TankId":3633,"LastBattleTime":1609160646,"Battles":10,"CapturePoints":0,"DamageDealt":10968,"DamageReceived":11793,"DroppedCapturePoints":0,"Frags":9,"Frags8P":2,"Hits":48,"Losses":3,"MaxFrags":3,"MaxXp":1381,"Shots":58,"Spotted":18,"SurvivedBattles":5,"WinAndSurvived":5,"Wins":7,"Xp":19421,"Wn7":0.0,"MaxFragsTankId":null,"MaxXpTankId":null,"AvgTier":0.0},"13889":{"TankInfoHistoryId":{"AccountId":571050560,"TankId":13889,"LastBattleTime":1609066903},"AccountId":571050560,"TankId":13889,"LastBattleTime":1609066903,"Battles":180,"CapturePoints":31,"DamageDealt":378225,"DamageReceived":314897,"DroppedCapturePoints":171,"Frags":139,"Frags8P":139,"Hits":865,"Losses":87,"MaxFrags":4,"MaxXp":2023,"Shots":1046,"Spotted":191,"SurvivedBattles":48,"WinAndSurvived":45,"Wins":93,"Xp":152145,"Wn7":0.0,"MaxFragsTankId":null,"MaxXpTankId":null,"AvgTier":0.0},"13857":{"TankInfoHistoryId":{"AccountId":571050560,"TankId":13857,"LastBattleTime":1609066454},"AccountId":571050560,"TankId":13857,"LastBattleTime":1609066454,"Battles":168,"CapturePoints":0,"DamageDealt":391983,"DamageReceived":250993,"DroppedCapturePoints":24,"Frags":138,"Frags8P":138,"Hits":755,"Losses":73,"MaxFrags":4,"MaxXp":2074,"Shots":876,"Spotted":137,"SurvivedBattles":63,"WinAndSurvived":62,"Wins":94,"Xp":154884,"Wn7":0.0,"MaxFragsTankId":null,"MaxXpTankId":null,"AvgTier":0.0},"20481":{"TankInfoHistoryId":{"AccountId":571050560,"TankId":20481,"LastBattleTime":1608999516},"AccountId":571050560,"TankId":20481,"LastBattleTime":1608999516,"Battles":64,"CapturePoints":0,"DamageDealt":128683,"DamageReceived":103999,"DroppedCapturePoints":93,"Frags":51,"Frags8P":36,"Hits":388,"Losses":33,"MaxFrags":4,"MaxXp":1798,"Shots":435,"Spotted":104,"SurvivedBattles":21,"WinAndSurvived":20,"Wins":29,"Xp":58981,"Wn7":0.0,"MaxFragsTankId":null,"MaxXpTankId":null,"AvgTier":0.0},"49":{"TankInfoHistoryId":{"AccountId":571050560,"TankId":49,"LastBattleTime":1608986512},"AccountId":571050560,"TankId":49,"LastBattleTime":1608986512,"Battles":29,"CapturePoints":0,"DamageDealt":41834,"DamageReceived":36284,"DroppedCapturePoints":0,"Frags":17,"Frags8P":10,"Hits":202,"Losses":20,"MaxFrags":5,"MaxXp":1765,"Shots":239,"Spotted":56,"SurvivedBattles":6,"WinAndSurvived":5,"Wins":9,"Xp":21679,"Wn7":0.0,"MaxFragsTankId":null,"MaxXpTankId":null,"AvgTier":0.0},"19745":{"TankInfoHistoryId":{"AccountId":571050560,"TankId":19745,"LastBattleTime":1608985578},"AccountId":571050560,"TankId":19745,"LastBattleTime":1608985578,"Battles":46,"CapturePoints":0,"DamageDealt":87179,"DamageReceived":70589,"DroppedCapturePoints":7,"Frags":48,"Frags8P":30,"Hits":465,"Losses":16,"MaxFrags":6,"MaxXp":2071,"Shots":530,"Spotted":94,"SurvivedBattles":20,"WinAndSurvived":20,"Wins":30,"Xp":48560,"Wn7":0.0,"MaxFragsTankId":null,"MaxXpTankId":null,"AvgTier":0.0},"64801":{"TankInfoHistoryId":{"AccountId":571050560,"TankId":64801,"LastBattleTime":1608985486},"AccountId":571050560,"TankId":64801,"LastBattleTime":1608985486,"Battles":805,"CapturePoints":177,"DamageDealt":1432780,"DamageReceived":1219928,"DroppedCapturePoints":379,"Frags":601,"Frags8P":467,"Hits":4442,"Losses":345,"MaxFrags":5,"MaxXp":2307,"Shots":5117,"Spotted":1241,"SurvivedBattles":306,"WinAndSurvived":297,"Wins":454,"Xp":643616,"Wn7":0.0,"MaxFragsTankId":null,"MaxXpTankId":null,"AvgTier":0.0},"64065":{"TankInfoHistoryId":{"AccountId":571050560,"TankId":64065,"LastBattleTime":1608982543},"AccountId":571050560,"TanLine truncated
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
[{"TankId":1,"Name":[{"Language":0,"Value":"Т-34"},{"Language":1,"Value":"T-34"},{"Language":2,"Value":"T-34"}],"Description":[{"Language":0,"Value":"Легенда советских бронетанковых войск. Самый массовый советский танк Второй мировой войны. С 1940 по 1944 год на различных заводах СССР было изготовлено 33805 машин трёх модификаций."},{"Language":1,"Value":"The legend of the Soviet armored forces and the most widely-produced Soviet tank of World War II, with a total of 33,805 vehicles manufactured. Three variants of this model were produced at several Soviet factories from 1940 through 1944."},{"Language":2,"Value":"Die Legende der sowjetischen Panzertruppe war zugleich der meistgebaute Panzer des Zweiten Weltkriegs. 33.805 Fahrzeuge in drei Ausführungen wurden in mehreren Fabriken der Sowjetunion zwischen 1940 und 1944 gebaut."}],"IsPremium":false,"TypeId":"mediumTank","NationId":"ussr","Tier":5,"PreviewImage":"http://glossary-eu-static.gcdn.co/icons/wotb/current/uploaded/vehicles/hd_thumbnail/T-34.png","NormalImage":"http://glossary-eu-static.gcdn.co/icons/wotb/current/uploaded/vehicles/hd/T-34.png","PriceCredit":400000.0,"PriceGold":0.0,"NexTanksInTree":[{"TankId":2561,"PricesXp":29000},{"TankId":16641,"PricesXp":31000},{"TankId":257,"PricesXp":7000}],"PriceXp":[{"TankId":2049,"PricesXp":11000}],"Engines":[261,5],"Guns":[4,1284,1540,516],"Suspensions":[258,2],"Turrets":[259,3]},{"TankId":2049,"Name":[{"Language":0,"Value":"А-20"},{"Language":1,"Value":"A-20"},{"Language":2,"Value":"A-20"}],"Description":[{"Language":0,"Value":"В декабре 1937 года на Харьковском заводе №138 была начата разработка танка А-20. Данный проект являлся дальнейшим развитием танка БТ-7, и стал предшественником легендарного Т-34. Работу над этой машиной возглавлял Михаил Кошкин. 18 мая 1938 года были утверждены ТТХ для танка под индексом БТ-20. Было построено небольшое количество экземпляров этой версии (с колёсно-гусеничной ходовой) для учебных целей."},{"Language":1,"Value":"Development of the A-20 tank started at Kharkiv Factory No. 183 in December 1937. The project was a further development of the BT-7 tank and became a predecessor of the legendary T-34. Work on the vehicle was led by Mikhail Koshkin. On May 18, 1938, technical characteristics of the tank designated BT-20 were approved. Only a few experimental prototypes, with a wheeled caterpillar suspension, were built for training purposes."},{"Language":2,"Value":"Die Entwicklung des Panzers A-20 wurde Dezember 1937 in der Fabrik Nr. 183 in Charkow in Angriff genommen. Das Projekt war eine Weiterentwicklung des BT-7 und wurde zum Vorgänger des legendären T-34. De Arbeiten wurden von Michael Koschkin geleitet. Am 18, Mai 1938 wurden die technischen Einzelheiten für den als BT-20 bezeichneten Panzer festgelegt. Es wurden nur wenige experimentelle Prototypen mit Raupenfahrwerk für Ausbildungszwecke gebaut."}],"IsPremium":false,"TypeId":"lightTank","NationId":"ussr","Tier":4,"PreviewImage":"http://glossary-eu-static.gcdn.co/icons/wotb/current/uploaded/vehicles/hd_thumbnail/A-20.png","NormalImage":"http://glossary-eu-static.gcdn.co/icons/wotb/current/uploaded/vehicles/hd/A-20.png","PriceCredit":85000.0,"PriceGold":0.0,"NexTanksInTree":[{"TankId":1,"PricesXp":11000},{"TankId":11777,"PricesXp":10000}],"PriceXp":[{"TankId":769,"PricesXp":2500}],"Engines":[261,5],"Guns":[260100,259844],"Suspensions":[4354,4098],"Turrets":[3587,3843]},{"TankId":17,"Name":[{"Language":0,"Value":"Pz.Kpfw. IV Ausf. G"},{"Language":1,"Value":"Pz.Kpfw. IV Ausf. G"},{"Language":2,"Value":"Pz.Kpfw. IV Ausf. G"}],"Description":[{"Language":0,"Value":"Самый массовый танк Панцерваффе. С мая 1942 года начал оснащаться длинноствольной пушкой. Всего с октября 1937 по март 1945 года было изготовлено 8519 машин, не считая командирских."},{"Language":1,"Value":"Produced in greater numbers than any other tank of the Panzerwaffe. Manufactured from October 1937 through March 1945, with a total production of 8,519 tanks plus command vehicles. Beginning in May 1942 this tank was equipped with a long-barreled gun."},{"Language":2,"Value":"Meistgebautes Fahrzeug der Wehrmacht. Ab März 1942 mit langem Geschütz ausgerüstet. Von Oktober 1937 bis März 1945 wurden 8.519 Kampfpanzer und Befehlspanzerwagen gebaut."}],"IsPremium":false,"TypeId":"mediumTank","NationId":"germany","Tier":5,"PreviewImage":"http://glossary-eu-static.gcdn.co/iLine truncated
|
||||||
@@ -0,0 +1,134 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using FluentAssertions;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using WotBlitzStatisticsPro.Logic.AccountInformationPipeline;
|
||||||
|
using WotBlitzStatisticsPro.Logic.AccountInformationPipeline.OperationContext;
|
||||||
|
using WotBlitzStatisticsPro.Logic.AccountInformationPipeline.Operations;
|
||||||
|
|
||||||
|
namespace WotBlitzStatisticsPro.Tests.OperationStepsTests
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class CalculateStatisticsOperationTest : OperationsStepsTestBase
|
||||||
|
{
|
||||||
|
private CalculateStatisticsOperation _operation;
|
||||||
|
private AccountInformationPipelineContextData _contextData;
|
||||||
|
|
||||||
|
private Dictionary<long, double> _expectedTankWn7 = new Dictionary<long, double>();
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void Init()
|
||||||
|
{
|
||||||
|
InitDataAccessors();
|
||||||
|
_operation = new CalculateStatisticsOperation(
|
||||||
|
DictionariesDataAccessorMock.Object);
|
||||||
|
|
||||||
|
_contextData = new AccountInformationPipelineContextData();
|
||||||
|
FillAccountAndTanks(_contextData);
|
||||||
|
FillExpectedTanksWn7();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task ShouldCalculateAppropriateWn7()
|
||||||
|
{
|
||||||
|
var context = new OperationContext(new AccountRequest(AccountId, Realm, Language));
|
||||||
|
context.AddOrReplace(_contextData);
|
||||||
|
|
||||||
|
await _operation.Invoke(context, null);
|
||||||
|
|
||||||
|
_contextData.AccountInfoHistory.AvgTier.Should().Be(7.191034482758621);
|
||||||
|
_contextData.AccountInfoHistory.Wn7.Should().Be(1543.801045341129);
|
||||||
|
|
||||||
|
foreach (var tankInfoHistory in _contextData.TanksHistory)
|
||||||
|
{
|
||||||
|
tankInfoHistory.Value.Wn7.Should().Be(_expectedTankWn7[tankInfoHistory.Key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FillExpectedTanksWn7()
|
||||||
|
{
|
||||||
|
_expectedTankWn7[19969] = 1257.4742368961442;
|
||||||
|
_expectedTankWn7[20753] = 1479.2527009056878;
|
||||||
|
_expectedTankWn7[10513] = 1335.8315220064917;
|
||||||
|
_expectedTankWn7[3633] = 1403.2080206940577;
|
||||||
|
_expectedTankWn7[13889] = 1177.919584692924;
|
||||||
|
_expectedTankWn7[13857] = 1207.3914817088403;
|
||||||
|
_expectedTankWn7[20481] = 1460.9096229341453;
|
||||||
|
_expectedTankWn7[49] = 885.334648079322;
|
||||||
|
_expectedTankWn7[19745] = 1700.0115007383338;
|
||||||
|
_expectedTankWn7[64801] = 1409.8375351552086;
|
||||||
|
_expectedTankWn7[64065] = 912.5457720282066;
|
||||||
|
_expectedTankWn7[62737] = 1099.9442609677085;
|
||||||
|
_expectedTankWn7[5169] = 1416.8311555651755;
|
||||||
|
_expectedTankWn7[2945] = 1321.936828442301;
|
||||||
|
_expectedTankWn7[10769] = 1756.366095722626;
|
||||||
|
_expectedTankWn7[21505] = 1565.0365241922777;
|
||||||
|
_expectedTankWn7[21281] = 1461.271098453194;
|
||||||
|
_expectedTankWn7[10001] = 1463.3184701109435;
|
||||||
|
_expectedTankWn7[54801] = 1246.395740646064;
|
||||||
|
_expectedTankWn7[20497] = 1562.1797289054657;
|
||||||
|
_expectedTankWn7[53585] = 746.9852997700226;
|
||||||
|
_expectedTankWn7[54273] = 1019.264695205361;
|
||||||
|
_expectedTankWn7[11809] = 1642.7563200629793;
|
||||||
|
_expectedTankWn7[11553] = 1468.2884517294874;
|
||||||
|
_expectedTankWn7[593] = 1524.7647933910516;
|
||||||
|
_expectedTankWn7[20049] = 1275.0884403134874;
|
||||||
|
_expectedTankWn7[4657] = 1141.4241226196734;
|
||||||
|
_expectedTankWn7[3121] = 1447.5927743745033;
|
||||||
|
_expectedTankWn7[4401] = 1431.7424068930866;
|
||||||
|
_expectedTankWn7[6705] = 2654.9969533215035;
|
||||||
|
_expectedTankWn7[2353] = 405.5242752732695;
|
||||||
|
_expectedTankWn7[801] = 1577.6468279052697;
|
||||||
|
_expectedTankWn7[11025] = 1221.8557090421527;
|
||||||
|
_expectedTankWn7[5969] = 1213.2503461803756;
|
||||||
|
_expectedTankWn7[2321] = 1949.3224359646974;
|
||||||
|
_expectedTankWn7[8737] = 1430.2853250772769;
|
||||||
|
_expectedTankWn7[4689] = 1365.861303635861;
|
||||||
|
_expectedTankWn7[8209] = 1662.393693050904;
|
||||||
|
_expectedTankWn7[5457] = 1797.503246016517;
|
||||||
|
_expectedTankWn7[14097] = 1415.1205566865408;
|
||||||
|
_expectedTankWn7[3857] = 1627.3465992059669;
|
||||||
|
_expectedTankWn7[1553] = 2134.873378307472;
|
||||||
|
_expectedTankWn7[9249] = 1665.6473444423157;
|
||||||
|
_expectedTankWn7[11073] = 1487.9155359028216;
|
||||||
|
_expectedTankWn7[8049] = 1588.7625100792534;
|
||||||
|
_expectedTankWn7[5393] = 1241.71798249068;
|
||||||
|
_expectedTankWn7[11793] = 1395.8406668374128;
|
||||||
|
_expectedTankWn7[8225] = 1458.9935784877462;
|
||||||
|
_expectedTankWn7[7185] = 1709.6660423373212;
|
||||||
|
_expectedTankWn7[12097] = 1239.1089692851986;
|
||||||
|
_expectedTankWn7[4993] = 2425.6513987658413;
|
||||||
|
_expectedTankWn7[7201] = 1838.404800235748;
|
||||||
|
_expectedTankWn7[10817] = 1654.6653276053528;
|
||||||
|
_expectedTankWn7[17] = 1793.0082687642428;
|
||||||
|
_expectedTankWn7[3361] = 2183.2365308582357;
|
||||||
|
_expectedTankWn7[2897] = 1554.0943507190375;
|
||||||
|
_expectedTankWn7[1041] = 1567.0343944089416;
|
||||||
|
_expectedTankWn7[1105] = 1439.193190859959;
|
||||||
|
_expectedTankWn7[2129] = 1658.7338405959958;
|
||||||
|
_expectedTankWn7[11585] = 1635.061287799197;
|
||||||
|
_expectedTankWn7[6945] = 1619.0991034642295;
|
||||||
|
_expectedTankWn7[17425] = 1346.4376859449808;
|
||||||
|
_expectedTankWn7[1809] = 1231.1825055791373;
|
||||||
|
_expectedTankWn7[10049] = 1647.018567383955;
|
||||||
|
_expectedTankWn7[5409] = 1695.498436870833;
|
||||||
|
_expectedTankWn7[10273] = 1743.2180387821902;
|
||||||
|
_expectedTankWn7[849] = 1505.687700381712;
|
||||||
|
_expectedTankWn7[9793] = 1230.054134651656;
|
||||||
|
_expectedTankWn7[5153] = 2661.6632312029014;
|
||||||
|
_expectedTankWn7[4369] = 3524.7012391482517;
|
||||||
|
_expectedTankWn7[7505] = 2735.2066182490653;
|
||||||
|
_expectedTankWn7[321] = 2764.189396366907;
|
||||||
|
_expectedTankWn7[7761] = 2428.8114326139516;
|
||||||
|
_expectedTankWn7[785] = 2551.3754316824043;
|
||||||
|
_expectedTankWn7[289] = 1660.4991870311142;
|
||||||
|
_expectedTankWn7[5953] = 2217.300182210282;
|
||||||
|
_expectedTankWn7[2065] = 1757.5480391121407;
|
||||||
|
_expectedTankWn7[6993] = 1964.5792598993119;
|
||||||
|
_expectedTankWn7[15937] = 2216.3984069010785;
|
||||||
|
_expectedTankWn7[1825] = 1886.6548546700287;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
using System.IO;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using FluentAssertions;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Moq;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using WotBlitzStatisticsPro.Logic.AccountInformationPipeline;
|
||||||
|
using WotBlitzStatisticsPro.Logic.AccountInformationPipeline.OperationContext;
|
||||||
|
using WotBlitzStatisticsPro.Logic.AccountInformationPipeline.Operations;
|
||||||
|
|
||||||
|
namespace WotBlitzStatisticsPro.Tests.OperationStepsTests
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class CheckLastBattleDateOperationTest: OperationsStepsTestBase
|
||||||
|
{
|
||||||
|
private CheckLastBattleDateOperation _operation;
|
||||||
|
private AccountInformationPipelineContextData _contextData;
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void Init()
|
||||||
|
{
|
||||||
|
_operation = new CheckLastBattleDateOperation(
|
||||||
|
(new Mock<ILogger<CheckLastBattleDateOperation>>()).Object);
|
||||||
|
|
||||||
|
_contextData = new AccountInformationPipelineContextData();
|
||||||
|
FillAccountAndTanks(_contextData);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task ShouldNotSetFlagIfDatesAreEqual()
|
||||||
|
{
|
||||||
|
_contextData.DbAccountInfo = GetAccountInfoFromFixture();
|
||||||
|
var context = new OperationContext(new AccountRequest(AccountId, Realm, Language));
|
||||||
|
context.AddOrReplace(_contextData);
|
||||||
|
|
||||||
|
await _operation.Invoke(context, null);
|
||||||
|
|
||||||
|
_contextData.NeedToSaveData.Should().Be(false);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task ShouldSetFlagIfDbDateIsLessThenWgDate()
|
||||||
|
{
|
||||||
|
_contextData.DbAccountInfo = GetAccountInfoFromFixture();
|
||||||
|
_contextData.DbAccountInfo.LastBattleTime -= 1;
|
||||||
|
var context = new OperationContext(new AccountRequest(AccountId, Realm, Language));
|
||||||
|
context.AddOrReplace(_contextData);
|
||||||
|
|
||||||
|
await _operation.Invoke(context, null);
|
||||||
|
|
||||||
|
_contextData.NeedToSaveData.Should().Be(true);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task ShouldSetFlagIfDbAccountInfoIsNull()
|
||||||
|
{
|
||||||
|
var context = new OperationContext(new AccountRequest(AccountId, Realm, Language));
|
||||||
|
context.AddOrReplace(_contextData);
|
||||||
|
|
||||||
|
await _operation.Invoke(context, null);
|
||||||
|
|
||||||
|
_contextData.NeedToSaveData.Should().Be(true);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
using System.IO;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using FluentAssertions;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Moq;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using WotBlitzStatisticsPro.Common.Model;
|
||||||
|
using WotBlitzStatisticsPro.Logic.AccountInformationPipeline;
|
||||||
|
using WotBlitzStatisticsPro.Logic.AccountInformationPipeline.OperationContext;
|
||||||
|
using WotBlitzStatisticsPro.Logic.AccountInformationPipeline.Operations;
|
||||||
|
|
||||||
|
namespace WotBlitzStatisticsPro.Tests.OperationStepsTests
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class GetAccountInfoOperationTest: OperationsStepsTestBase
|
||||||
|
{
|
||||||
|
private GetAccountInfoOperation _operation;
|
||||||
|
private AccountInformationPipelineContextData _contextData;
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void Init()
|
||||||
|
{
|
||||||
|
InitAutoMapper();
|
||||||
|
InitWgApiClient();
|
||||||
|
_operation = new GetAccountInfoOperation(
|
||||||
|
WargamingApiClient,
|
||||||
|
Mapper,
|
||||||
|
(new Mock<ILogger<GetAccountInfoOperation>>()).Object);
|
||||||
|
|
||||||
|
_contextData = new AccountInformationPipelineContextData();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task ShouldGetAndSaveAccountInfoInformation()
|
||||||
|
{
|
||||||
|
var context = new OperationContext(new AccountRequest(AccountId, Realm, Language));
|
||||||
|
context.AddOrReplace(_contextData);
|
||||||
|
|
||||||
|
await _operation.Invoke(context, null);
|
||||||
|
|
||||||
|
_contextData.AccountInfo.Should().NotBeNull();
|
||||||
|
_contextData.AccountInfoHistory.Should().NotBeNull();
|
||||||
|
|
||||||
|
var accountInfoSerialized = JsonConvert.SerializeObject(_contextData.AccountInfo);
|
||||||
|
var accountInfoHistorySerialized = JsonConvert.SerializeObject(_contextData.AccountInfoHistory);
|
||||||
|
|
||||||
|
var expectedAccountInfo =
|
||||||
|
await File.ReadAllTextAsync($"{TestContext.CurrentContext.TestDirectory}\\Fixtures\\MappedAccountInfo.json");
|
||||||
|
accountInfoSerialized.Should().Be(expectedAccountInfo);
|
||||||
|
var expectedAccountInfoHistory =
|
||||||
|
await File.ReadAllTextAsync($"{TestContext.CurrentContext.TestDirectory}\\Fixtures\\MappedAccountHistory.json");
|
||||||
|
accountInfoHistorySerialized.Should().Be(expectedAccountInfoHistory);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
using System.IO;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using FluentAssertions;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Moq;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using WotBlitzStatisticsPro.Logic.AccountInformationPipeline;
|
||||||
|
using WotBlitzStatisticsPro.Logic.AccountInformationPipeline.OperationContext;
|
||||||
|
using WotBlitzStatisticsPro.Logic.AccountInformationPipeline.Operations;
|
||||||
|
|
||||||
|
namespace WotBlitzStatisticsPro.Tests.OperationStepsTests
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class GetTanksInfoOperationTest: OperationsStepsTestBase
|
||||||
|
{
|
||||||
|
private GetTanksInfoOperation _operation;
|
||||||
|
private AccountInformationPipelineContextData _contextData;
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void Init()
|
||||||
|
{
|
||||||
|
InitAutoMapper();
|
||||||
|
InitWgApiClient();
|
||||||
|
_operation = new GetTanksInfoOperation(
|
||||||
|
WargamingTanksApiClient,
|
||||||
|
Mapper,
|
||||||
|
(new Mock<ILogger<GetTanksInfoOperation>>()).Object);
|
||||||
|
|
||||||
|
_contextData = new AccountInformationPipelineContextData();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task ShouldGetAndSaveTanksInformation()
|
||||||
|
{
|
||||||
|
var context = new OperationContext(new AccountRequest(AccountId, Realm, Language));
|
||||||
|
context.AddOrReplace(_contextData);
|
||||||
|
|
||||||
|
await _operation.Invoke(context, null);
|
||||||
|
|
||||||
|
_contextData.Tanks.Should().NotBeNull();
|
||||||
|
_contextData.TanksHistory.Should().NotBeNull();
|
||||||
|
|
||||||
|
var tanksSerialized = JsonConvert.SerializeObject(_contextData.Tanks);
|
||||||
|
var tanksHistorySerialized = JsonConvert.SerializeObject(_contextData.TanksHistory);
|
||||||
|
|
||||||
|
var expectedTanksInfo =
|
||||||
|
await File.ReadAllTextAsync($"{TestContext.CurrentContext.TestDirectory}\\Fixtures\\MappedTanks.json");
|
||||||
|
tanksSerialized.Should().Be(expectedTanksInfo);
|
||||||
|
var expectedTanksHistory =
|
||||||
|
await File.ReadAllTextAsync($"{TestContext.CurrentContext.TestDirectory}\\Fixtures\\MappedTanksHistory.json");
|
||||||
|
tanksHistorySerialized.Should().Be(expectedTanksHistory);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,145 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using AutoMapper;
|
||||||
|
using Moq;
|
||||||
|
using Moq.Protected;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using WotBlitzStatisticsPro.Common;
|
||||||
|
using WotBlitzStatisticsPro.Common.Dictionaries;
|
||||||
|
using WotBlitzStatisticsPro.Common.Model;
|
||||||
|
using WotBlitzStatisticsPro.DataAccess;
|
||||||
|
using WotBlitzStatisticsPro.DataAccess.Model;
|
||||||
|
using WotBlitzStatisticsPro.DataAccess.Model.Accounts;
|
||||||
|
using WotBlitzStatisticsPro.Logic.AccountInformationPipeline;
|
||||||
|
using WotBlitzStatisticsPro.Logic.Mappers;
|
||||||
|
using WotBlitzStatisticsPro.WgApiClient;
|
||||||
|
using WotBlitzStatisticsPro.WgApiClient.Model;
|
||||||
|
|
||||||
|
namespace WotBlitzStatisticsPro.Tests.OperationStepsTests
|
||||||
|
{
|
||||||
|
public class OperationsStepsTestBase
|
||||||
|
{
|
||||||
|
protected const long AccountId = 571050560;
|
||||||
|
protected const string ApplicationId = "demo";
|
||||||
|
protected const RealmType Realm = RealmType.Eu;
|
||||||
|
protected const RequestLanguage Language = RequestLanguage.En;
|
||||||
|
|
||||||
|
protected IMapper Mapper;
|
||||||
|
protected IWargamingApiClient WargamingApiClient;
|
||||||
|
protected IWargamingTanksApiClient WargamingTanksApiClient;
|
||||||
|
protected Mock<IDictionariesDataAccessor> DictionariesDataAccessorMock;
|
||||||
|
protected Mock<IWargamingAccountDataAccessor> WargamingDataAccessorMock;
|
||||||
|
|
||||||
|
protected void InitAutoMapper()
|
||||||
|
{
|
||||||
|
var config = new MapperConfiguration(cfg => {
|
||||||
|
cfg.AddProfile<AccountDtoProfile>();
|
||||||
|
cfg.AddProfile<AccountInfoProfile>();
|
||||||
|
cfg.AddProfile<AccountInfoStatisticsProfile>();
|
||||||
|
cfg.AddProfile<AccountSearchResponseProfile>();
|
||||||
|
cfg.AddProfile<AchievementDictionaryProfile>();
|
||||||
|
cfg.AddProfile<AchievementOptionProfile>();
|
||||||
|
cfg.AddProfile<ClanSearchResponseProfile>();
|
||||||
|
cfg.AddProfile<DictionaryLanguageMapper>();
|
||||||
|
cfg.AddProfile<ShortStatisticsProfile>();
|
||||||
|
cfg.AddProfile<TankInfoProfile>();
|
||||||
|
cfg.AddProfile<TankInfoStatisticsProfile>();
|
||||||
|
cfg.AddProfile<VehicleDictionaryProfile>();
|
||||||
|
cfg.AddProfile<VehiclePriceProfile>();
|
||||||
|
});
|
||||||
|
|
||||||
|
Mapper = new Mapper(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void InitWgApiClient()
|
||||||
|
{
|
||||||
|
var settingsMock = new Mock<IWargamingApiSettings>();
|
||||||
|
settingsMock.SetupGet(s => s.ApplicationId).Returns(ApplicationId);
|
||||||
|
|
||||||
|
var playerInfoFilePath = $"{TestContext.CurrentContext.TestDirectory}\\Fixtures\\PlayerInfo50.json";
|
||||||
|
var tanksInfoFilePath = $"{TestContext.CurrentContext.TestDirectory}\\Fixtures\\TanksInfo50.json";
|
||||||
|
var playerAchievementsFilePath = $"{TestContext.CurrentContext.TestDirectory}\\Fixtures\\PlayerAchievements50.json";
|
||||||
|
var tanksAchievementsFilePath = $"{TestContext.CurrentContext.TestDirectory}\\Fixtures\\TanksAchievemnts50.json";
|
||||||
|
|
||||||
|
var playerInfoRequestUrl = $"https://api.wotblitz.eu/wotb/account/info/?application_id={ApplicationId}&language=en&account_id={AccountId}";
|
||||||
|
var playerInfoResponse = new HttpResponseMessage
|
||||||
|
{
|
||||||
|
StatusCode = HttpStatusCode.OK,
|
||||||
|
Content = new StringContent(File.ReadAllText(playerInfoFilePath)),
|
||||||
|
};
|
||||||
|
|
||||||
|
var tanksInfoRequestUrl = $"https://api.wotblitz.eu/wotb/tanks/stats/?application_id={ApplicationId}&language=en&account_id={AccountId}";
|
||||||
|
var tanksInfoResponse = new HttpResponseMessage
|
||||||
|
{
|
||||||
|
StatusCode = HttpStatusCode.OK,
|
||||||
|
Content = new StringContent(File.ReadAllText(tanksInfoFilePath)),
|
||||||
|
};
|
||||||
|
|
||||||
|
var handlerMock = new Mock<HttpMessageHandler>();
|
||||||
|
handlerMock
|
||||||
|
.Protected()
|
||||||
|
.Setup<Task<HttpResponseMessage>>(
|
||||||
|
"SendAsync",
|
||||||
|
ItExpr.Is<HttpRequestMessage>(m => m.RequestUri.ToString() == playerInfoRequestUrl),
|
||||||
|
ItExpr.IsAny<CancellationToken>())
|
||||||
|
.ReturnsAsync(playerInfoResponse);
|
||||||
|
handlerMock
|
||||||
|
.Protected()
|
||||||
|
.Setup<Task<HttpResponseMessage>>(
|
||||||
|
"SendAsync",
|
||||||
|
ItExpr.Is<HttpRequestMessage>(m => m.RequestUri.ToString() == tanksInfoRequestUrl),
|
||||||
|
ItExpr.IsAny<CancellationToken>())
|
||||||
|
.ReturnsAsync(tanksInfoResponse);
|
||||||
|
|
||||||
|
var client = new WargamingApiClient(new HttpClient(handlerMock.Object), settingsMock.Object);
|
||||||
|
WargamingApiClient = client;
|
||||||
|
WargamingTanksApiClient = client;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void InitDataAccessors()
|
||||||
|
{
|
||||||
|
var tankopediaFile = File.ReadAllText($"{TestContext.CurrentContext.TestDirectory}\\Fixtures\\Tankopedia.json");
|
||||||
|
var vehicles = JsonConvert.DeserializeObject<List<VehiclesDictionary>>(tankopediaFile);
|
||||||
|
|
||||||
|
var tankTires = vehicles.Select(v => new {TankId = v.TankId, Tier = v.Tier})
|
||||||
|
.ToDictionary(k => k.TankId, v => v.Tier);
|
||||||
|
|
||||||
|
DictionariesDataAccessorMock = new Mock<IDictionariesDataAccessor>();
|
||||||
|
DictionariesDataAccessorMock.Setup(d => d.GetTankTires(It.IsAny<long[]>())).ReturnsAsync(tankTires);
|
||||||
|
|
||||||
|
|
||||||
|
WargamingDataAccessorMock = new Mock<IWargamingAccountDataAccessor>();
|
||||||
|
WargamingDataAccessorMock.Setup(d => d.ReadAccountInfo(AccountId))
|
||||||
|
.ReturnsAsync(GetAccountInfoFromFixture());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void FillAccountAndTanks(AccountInformationPipelineContextData contextData)
|
||||||
|
{
|
||||||
|
var mappedAccountInfoHistory = File.ReadAllText($"{TestContext.CurrentContext.TestDirectory}\\Fixtures\\MappedAccountHistory.json");
|
||||||
|
var mappedTanks = File.ReadAllText($"{TestContext.CurrentContext.TestDirectory}\\Fixtures\\MappedTanks.json");
|
||||||
|
var mappedTanksHistory = File.ReadAllText($"{TestContext.CurrentContext.TestDirectory}\\Fixtures\\MappedTanksHistory.json");
|
||||||
|
|
||||||
|
contextData.AccountInfo = GetAccountInfoFromFixture();
|
||||||
|
contextData.AccountInfoHistory =
|
||||||
|
JsonConvert.DeserializeObject<AccountInfoHistory>(mappedAccountInfoHistory);
|
||||||
|
contextData.Tanks = JsonConvert.DeserializeObject<List<TankInfo>>(mappedTanks);
|
||||||
|
contextData.TanksHistory =
|
||||||
|
JsonConvert.DeserializeObject<Dictionary<long, TankInfoHistory>>(mappedTanksHistory);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected AccountInfo GetAccountInfoFromFixture()
|
||||||
|
{
|
||||||
|
var mappedAccountInfo = File.ReadAllText($"{TestContext.CurrentContext.TestDirectory}\\Fixtures\\MappedAccountInfo.json");
|
||||||
|
return JsonConvert.DeserializeObject<AccountInfo>(mappedAccountInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
using System.IO;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using FluentAssertions;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using WotBlitzStatisticsPro.Logic.AccountInformationPipeline;
|
||||||
|
using WotBlitzStatisticsPro.Logic.AccountInformationPipeline.OperationContext;
|
||||||
|
using WotBlitzStatisticsPro.Logic.AccountInformationPipeline.Operations;
|
||||||
|
|
||||||
|
namespace WotBlitzStatisticsPro.Tests.OperationStepsTests
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class ReadAccountInfoFromDbOperationTest: OperationsStepsTestBase
|
||||||
|
{
|
||||||
|
private ReadAccountInfoFromDbOperation _operation;
|
||||||
|
private AccountInformationPipelineContextData _contextData;
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void Init()
|
||||||
|
{
|
||||||
|
InitDataAccessors();
|
||||||
|
_operation = new ReadAccountInfoFromDbOperation(
|
||||||
|
WargamingDataAccessorMock.Object);
|
||||||
|
|
||||||
|
_contextData = new AccountInformationPipelineContextData();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task ShouldReadAccountInfoFromDataAccessor()
|
||||||
|
{
|
||||||
|
var context = new OperationContext(new AccountRequest(AccountId, Realm, Language));
|
||||||
|
context.AddOrReplace(_contextData);
|
||||||
|
|
||||||
|
await _operation.Invoke(context, null);
|
||||||
|
|
||||||
|
_contextData.DbAccountInfo.Should().NotBeNull();
|
||||||
|
|
||||||
|
var accountInfoSerialized = JsonConvert.SerializeObject(_contextData.DbAccountInfo);
|
||||||
|
|
||||||
|
var expectedAccountInfo =
|
||||||
|
await File.ReadAllTextAsync($"{TestContext.CurrentContext.TestDirectory}\\Fixtures\\MappedAccountInfo.json");
|
||||||
|
accountInfoSerialized.Should().Be(expectedAccountInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,131 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Moq;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using WotBlitzStatisticsPro.DataAccess.Model.Accounts;
|
||||||
|
using WotBlitzStatisticsPro.Logic.AccountInformationPipeline;
|
||||||
|
using WotBlitzStatisticsPro.Logic.AccountInformationPipeline.OperationContext;
|
||||||
|
using WotBlitzStatisticsPro.Logic.AccountInformationPipeline.Operations;
|
||||||
|
|
||||||
|
namespace WotBlitzStatisticsPro.Tests.OperationStepsTests
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
|
||||||
|
public class SaveAccountAntTanksOperationTest: OperationsStepsTestBase
|
||||||
|
{
|
||||||
|
private SaveAccountAndTanksOperation _operation;
|
||||||
|
private AccountInformationPipelineContextData _contextData;
|
||||||
|
|
||||||
|
private Dictionary<long, double> _expectedTankWn7 = new Dictionary<long, double>();
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void Init()
|
||||||
|
{
|
||||||
|
InitDataAccessors();
|
||||||
|
_operation = new SaveAccountAndTanksOperation(
|
||||||
|
WargamingDataAccessorMock.Object,
|
||||||
|
(new Mock<ILogger<SaveAccountAndTanksOperation>>()).Object);
|
||||||
|
|
||||||
|
_contextData = new AccountInformationPipelineContextData();
|
||||||
|
FillAccountAndTanks(_contextData);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task ShouldSaveAccountInfo()
|
||||||
|
{
|
||||||
|
_contextData.NeedToSaveData = true;
|
||||||
|
var context = new OperationContext(new AccountRequest(AccountId, Realm, Language));
|
||||||
|
context.AddOrReplace(_contextData);
|
||||||
|
|
||||||
|
await _operation.Invoke(context, null);
|
||||||
|
|
||||||
|
WargamingDataAccessorMock.Verify(d => d.AddOurUpdateAccountInfo(It.Is<AccountInfo>(a => a.AccountId == AccountId)), Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task ShouldNotSaveAccountInfoIfFlagIsNotSet()
|
||||||
|
{
|
||||||
|
var context = new OperationContext(new AccountRequest(AccountId, Realm, Language));
|
||||||
|
context.AddOrReplace(_contextData);
|
||||||
|
|
||||||
|
await _operation.Invoke(context, null);
|
||||||
|
|
||||||
|
WargamingDataAccessorMock.Verify(d => d.AddOurUpdateAccountInfo(It.Is<AccountInfo>(a => a.AccountId == AccountId)), Times.Never);
|
||||||
|
WargamingDataAccessorMock.Verify(d => d.AddAccountInfoHistory(It.IsAny<AccountInfoHistory>()), Times.Never);
|
||||||
|
WargamingDataAccessorMock.Verify(d => d.AddOrUpdateTankInfo(It.IsAny<TankInfo>()), Times.Never);
|
||||||
|
WargamingDataAccessorMock.Verify(d => d.AddTankInfoHistory(It.IsAny<TankInfoHistory>()), Times.Never);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task ShouldSaveAccountInfoHistory()
|
||||||
|
{
|
||||||
|
_contextData.NeedToSaveData = true;
|
||||||
|
var context = new OperationContext(new AccountRequest(AccountId, Realm, Language));
|
||||||
|
context.AddOrReplace(_contextData);
|
||||||
|
|
||||||
|
await _operation.Invoke(context, null);
|
||||||
|
|
||||||
|
WargamingDataAccessorMock.Verify(d => d.AddAccountInfoHistory(It.Is<AccountInfoHistory>(a => a.AccountId == AccountId)), Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task ShouldSaveAllTanksIfNotTanksInDatabase()
|
||||||
|
{
|
||||||
|
_contextData.NeedToSaveData = true;
|
||||||
|
var context = new OperationContext(new AccountRequest(AccountId, Realm, Language));
|
||||||
|
context.AddOrReplace(_contextData);
|
||||||
|
|
||||||
|
await _operation.Invoke(context, null);
|
||||||
|
|
||||||
|
var tanksCount = _contextData.Tanks.Count;
|
||||||
|
|
||||||
|
WargamingDataAccessorMock.Verify(d => d.AddOrUpdateTankInfo(It.IsAny<TankInfo>()), Times.Exactly(tanksCount));
|
||||||
|
WargamingDataAccessorMock.Verify(d => d.AddTankInfoHistory(It.IsAny<TankInfoHistory>()), Times.Exactly(tanksCount));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task ShouldSaveTanksThatLastDateIsGreaterThenInDatabase()
|
||||||
|
{
|
||||||
|
_contextData.NeedToSaveData = true;
|
||||||
|
var context = new OperationContext(new AccountRequest(AccountId, Realm, Language));
|
||||||
|
context.AddOrReplace(_contextData);
|
||||||
|
|
||||||
|
int outdatedTanksCount = 3;
|
||||||
|
int outdatedTanksIndex = 0;
|
||||||
|
|
||||||
|
foreach (var tank in _contextData.Tanks)
|
||||||
|
{
|
||||||
|
if (outdatedTanksIndex < outdatedTanksCount)
|
||||||
|
{
|
||||||
|
var tankInfo = new TankInfo
|
||||||
|
{
|
||||||
|
TankInfoId = new TankInfoKey
|
||||||
|
{
|
||||||
|
TankId = tank.TankId,
|
||||||
|
AccountId = tank.AccountId,
|
||||||
|
},
|
||||||
|
LastBattleTime = tank.LastBattleTime - 1
|
||||||
|
};
|
||||||
|
WargamingDataAccessorMock.Setup(d => d.ReadTankInfo(tank.AccountId, tank.TankId))
|
||||||
|
.ReturnsAsync(tankInfo);
|
||||||
|
outdatedTanksIndex++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
WargamingDataAccessorMock.Setup(d => d.ReadTankInfo(tank.AccountId, tank.TankId))
|
||||||
|
.ReturnsAsync(tank);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
await _operation.Invoke(context, null);
|
||||||
|
|
||||||
|
var tanksCount = _contextData.Tanks.Count;
|
||||||
|
|
||||||
|
WargamingDataAccessorMock.Verify(d => d.AddOrUpdateTankInfo(It.IsAny<TankInfo>()), Times.Exactly(outdatedTanksCount));
|
||||||
|
WargamingDataAccessorMock.Verify(d => d.AddTankInfoHistory(It.IsAny<TankInfoHistory>()), Times.Exactly(outdatedTanksCount));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,10 +7,12 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="AutoMapper" Version="10.1.1" />
|
||||||
<PackageReference Include="Bogus" Version="32.0.2" />
|
<PackageReference Include="Bogus" Version="32.0.2" />
|
||||||
<PackageReference Include="FluentAssertions" Version="5.10.3" />
|
<PackageReference Include="FluentAssertions" Version="5.10.3" />
|
||||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.1" />
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.1" />
|
||||||
<PackageReference Include="Moq" Version="4.15.2" />
|
<PackageReference Include="Moq" Version="4.15.2" />
|
||||||
|
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||||
<PackageReference Include="nunit" Version="3.12.0" />
|
<PackageReference Include="nunit" Version="3.12.0" />
|
||||||
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
|
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
|
||||||
@@ -22,8 +24,33 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="Fixtures\" />
|
<None Update="Fixtures\MappedAccountHistory.json">
|
||||||
<Folder Include="OperationStepsTests\" />
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
<None Update="Fixtures\MappedAccountInfo.json">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
<None Update="Fixtures\MappedTanks.json">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
<None Update="Fixtures\MappedTanksHistory.json">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
<None Update="Fixtures\PlayerAchievements50.json">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
<None Update="Fixtures\PlayerInfo50.json">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
<None Update="Fixtures\Tankopedia.json">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
<None Update="Fixtures\TanksAchievemnts50.json">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
<None Update="Fixtures\TanksInfo50.json">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
Reference in new issue
Block a user