mirror of
https://github.com/DrMboga/WotBlitzStatisticsBlazor.git
synced 2026-10-28 04:40:07 +01:00
Static dictionaries updater tests
This commit is contained in:
1 parent
71c0240437
commit
cacc60fc7f
8 files changed
+485
-7
No files matched your search
@@ -1,11 +1,32 @@
|
|||||||
using System.Threading.Tasks;
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using AutoMapper;
|
||||||
using WotBlitzStatisticsPro.Common.Model;
|
using WotBlitzStatisticsPro.Common.Model;
|
||||||
|
using WotBlitzStatisticsPro.DataAccess;
|
||||||
|
using WotBlitzStatisticsPro.WgApiClient;
|
||||||
|
|
||||||
namespace WotBlitzStatisticsPro.Logic.Dictionaries
|
namespace WotBlitzStatisticsPro.Logic.Dictionaries
|
||||||
{
|
{
|
||||||
public class AchievementsDictionaryUpdater : IDictionaryUpdater
|
public class AchievementsDictionaryUpdater : IDictionaryUpdater
|
||||||
{
|
{
|
||||||
public Task<UpdateDictionariesResponseItem> Update()
|
private readonly IWargamingDictionariesApiClient _wargamingDictionariesApiClient;
|
||||||
|
private readonly IDictionariesDataAccessor _dataAccessor;
|
||||||
|
private readonly IMapper _mapper;
|
||||||
|
|
||||||
|
[Obsolete("Parameter-less constructor only for unit tests")]
|
||||||
|
public AchievementsDictionaryUpdater()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public AchievementsDictionaryUpdater(IWargamingDictionariesApiClient wargamingDictionariesApiClient, IDictionariesDataAccessor dataAccessor, IMapper mapper)
|
||||||
|
{
|
||||||
|
_wargamingDictionariesApiClient = wargamingDictionariesApiClient;
|
||||||
|
_dataAccessor = dataAccessor;
|
||||||
|
_mapper = mapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual Task<UpdateDictionariesResponseItem> Update()
|
||||||
{
|
{
|
||||||
throw new System.NotImplementedException();
|
throw new System.NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,12 @@ namespace WotBlitzStatisticsPro.Logic.Dictionaries
|
|||||||
private readonly IDictionariesDataAccessor _dataAccessor;
|
private readonly IDictionariesDataAccessor _dataAccessor;
|
||||||
private readonly IMapper _mapper;
|
private readonly IMapper _mapper;
|
||||||
|
|
||||||
|
[Obsolete("Parameter-less constructor only for unit tests")]
|
||||||
|
public StaticDictionariesUpdater()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public StaticDictionariesUpdater(
|
public StaticDictionariesUpdater(
|
||||||
IWargamingDictionariesApiClient wargamingDictionariesApiClient,
|
IWargamingDictionariesApiClient wargamingDictionariesApiClient,
|
||||||
IDictionariesDataAccessor dataAccessor,
|
IDictionariesDataAccessor dataAccessor,
|
||||||
@@ -26,7 +32,7 @@ namespace WotBlitzStatisticsPro.Logic.Dictionaries
|
|||||||
_dataAccessor = dataAccessor;
|
_dataAccessor = dataAccessor;
|
||||||
_mapper = mapper;
|
_mapper = mapper;
|
||||||
}
|
}
|
||||||
public async Task<UpdateDictionariesResponseItem> Update()
|
public virtual async Task<UpdateDictionariesResponseItem> Update()
|
||||||
{
|
{
|
||||||
var (
|
var (
|
||||||
languages,
|
languages,
|
||||||
@@ -41,8 +47,6 @@ namespace WotBlitzStatisticsPro.Logic.Dictionaries
|
|||||||
await _dataAccessor.UpdateClanRoles(clanRoles);
|
await _dataAccessor.UpdateClanRoles(clanRoles);
|
||||||
await _dataAccessor.UpdateAchievementsSections(achievementsSections);
|
await _dataAccessor.UpdateAchievementsSections(achievementsSections);
|
||||||
|
|
||||||
// ToDo: create unit tests
|
|
||||||
|
|
||||||
return new UpdateDictionariesResponseItem
|
return new UpdateDictionariesResponseItem
|
||||||
{
|
{
|
||||||
DictionaryType = DictionaryType.StaticDictionaries,
|
DictionaryType = DictionaryType.StaticDictionaries,
|
||||||
|
|||||||
@@ -1,11 +1,32 @@
|
|||||||
using System.Threading.Tasks;
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using AutoMapper;
|
||||||
using WotBlitzStatisticsPro.Common.Model;
|
using WotBlitzStatisticsPro.Common.Model;
|
||||||
|
using WotBlitzStatisticsPro.DataAccess;
|
||||||
|
using WotBlitzStatisticsPro.WgApiClient;
|
||||||
|
|
||||||
namespace WotBlitzStatisticsPro.Logic.Dictionaries
|
namespace WotBlitzStatisticsPro.Logic.Dictionaries
|
||||||
{
|
{
|
||||||
public class VehiclesDictionaryUpdater : IDictionaryUpdater
|
public class VehiclesDictionaryUpdater : IDictionaryUpdater
|
||||||
{
|
{
|
||||||
public Task<UpdateDictionariesResponseItem> Update()
|
private readonly IWargamingDictionariesApiClient _wargamingDictionariesApiClient;
|
||||||
|
private readonly IDictionariesDataAccessor _dataAccessor;
|
||||||
|
private readonly IMapper _mapper;
|
||||||
|
|
||||||
|
[Obsolete("Parameter-less constructor only for unit tests")]
|
||||||
|
public VehiclesDictionaryUpdater()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public VehiclesDictionaryUpdater(IWargamingDictionariesApiClient wargamingDictionariesApiClient, IDictionariesDataAccessor dataAccessor, IMapper mapper)
|
||||||
|
{
|
||||||
|
_wargamingDictionariesApiClient = wargamingDictionariesApiClient;
|
||||||
|
_dataAccessor = dataAccessor;
|
||||||
|
_mapper = mapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual Task<UpdateDictionariesResponseItem> Update()
|
||||||
{
|
{
|
||||||
throw new System.NotImplementedException();
|
throw new System.NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
using AutoMapper;
|
using AutoMapper;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using WotBlitzStatisticsPro.Common.Model;
|
using WotBlitzStatisticsPro.Common.Model;
|
||||||
@@ -6,6 +7,7 @@ using WotBlitzStatisticsPro.DataAccess;
|
|||||||
using WotBlitzStatisticsPro.Logic.Dictionaries;
|
using WotBlitzStatisticsPro.Logic.Dictionaries;
|
||||||
using WotBlitzStatisticsPro.WgApiClient;
|
using WotBlitzStatisticsPro.WgApiClient;
|
||||||
|
|
||||||
|
[assembly: InternalsVisibleTo("WotBlitzStatisticsPro.Tests")]
|
||||||
namespace WotBlitzStatisticsPro.Logic
|
namespace WotBlitzStatisticsPro.Logic
|
||||||
{
|
{
|
||||||
public static class WotBlitzStatisticsLogicInstaller
|
public static class WotBlitzStatisticsLogicInstaller
|
||||||
@@ -29,6 +31,11 @@ namespace WotBlitzStatisticsPro.Logic
|
|||||||
services.AddTransient<AchievementsDictionaryUpdater>();
|
services.AddTransient<AchievementsDictionaryUpdater>();
|
||||||
services.AddTransient<VehiclesDictionaryUpdater>();
|
services.AddTransient<VehiclesDictionaryUpdater>();
|
||||||
|
|
||||||
|
RegisterFactoryMethod(services);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static void RegisterFactoryMethod(IServiceCollection services)
|
||||||
|
{
|
||||||
services.AddTransient<DictionariesUpdaterResolver>(serviceProvider => dictionaryType =>
|
services.AddTransient<DictionariesUpdaterResolver>(serviceProvider => dictionaryType =>
|
||||||
{
|
{
|
||||||
switch (dictionaryType)
|
switch (dictionaryType)
|
||||||
|
|||||||
@@ -0,0 +1,101 @@
|
|||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Moq;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using WotBlitzStatisticsPro.Common.Model;
|
||||||
|
using WotBlitzStatisticsPro.Logic;
|
||||||
|
using WotBlitzStatisticsPro.Logic.Dictionaries;
|
||||||
|
|
||||||
|
namespace WotBlitzStatisticsPro.Tests.DictionariesTests
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class DictionariesServiceTests
|
||||||
|
{
|
||||||
|
private Mock<StaticDictionariesUpdater> _staticDictionaryUpdaterMock;
|
||||||
|
private Mock<AchievementsDictionaryUpdater> _achievementsDictionaryUpdaterMock;
|
||||||
|
private Mock<VehiclesDictionaryUpdater> _vehiclesDictionaryUpdaterMock;
|
||||||
|
|
||||||
|
private IWargamingDictionaries _wargamingDictionaries;
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void Init()
|
||||||
|
{
|
||||||
|
_staticDictionaryUpdaterMock = new Mock<StaticDictionariesUpdater>();
|
||||||
|
_achievementsDictionaryUpdaterMock = new Mock<AchievementsDictionaryUpdater>();
|
||||||
|
_vehiclesDictionaryUpdaterMock = new Mock<VehiclesDictionaryUpdater>();
|
||||||
|
|
||||||
|
|
||||||
|
_staticDictionaryUpdaterMock.Setup(d => d.Update()).ReturnsAsync(new UpdateDictionariesResponseItem());
|
||||||
|
_achievementsDictionaryUpdaterMock.Setup(d => d.Update())
|
||||||
|
.ReturnsAsync(new UpdateDictionariesResponseItem());
|
||||||
|
_vehiclesDictionaryUpdaterMock.Setup(d => d.Update()).ReturnsAsync(new UpdateDictionariesResponseItem());
|
||||||
|
|
||||||
|
var serviceProvider = new ServiceCollection();
|
||||||
|
|
||||||
|
serviceProvider.AddSingleton(_staticDictionaryUpdaterMock.Object);
|
||||||
|
serviceProvider.AddSingleton(_achievementsDictionaryUpdaterMock.Object);
|
||||||
|
serviceProvider.AddSingleton(_vehiclesDictionaryUpdaterMock.Object);
|
||||||
|
|
||||||
|
WotBlitzStatisticsLogicInstaller.RegisterFactoryMethod(serviceProvider);
|
||||||
|
|
||||||
|
var services = serviceProvider.BuildServiceProvider();
|
||||||
|
|
||||||
|
_wargamingDictionaries = new WargamingDictionaries(services.GetService<DictionariesUpdaterResolver>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task ShouldCallOnlyStaticDictionariesUpdater()
|
||||||
|
{
|
||||||
|
var updateResult = await _wargamingDictionaries.UpdateDictionaries(new UpdateDictionariesRequest
|
||||||
|
{DictionaryTypes = DictionaryType.StaticDictionaries});
|
||||||
|
|
||||||
|
_staticDictionaryUpdaterMock.Verify(u => u.Update(), Times.Once);
|
||||||
|
_achievementsDictionaryUpdaterMock.Verify(u => u.Update(), Times.Never);
|
||||||
|
_vehiclesDictionaryUpdaterMock.Verify(u => u.Update(), Times.Never);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task ShouldCallOnlyAchievementsDictionariesUpdater()
|
||||||
|
{
|
||||||
|
var updateResult = await _wargamingDictionaries.UpdateDictionaries(new UpdateDictionariesRequest
|
||||||
|
{DictionaryTypes = DictionaryType.Achievements});
|
||||||
|
|
||||||
|
_staticDictionaryUpdaterMock.Verify(u => u.Update(), Times.Never);
|
||||||
|
_achievementsDictionaryUpdaterMock.Verify(u => u.Update(), Times.Once);
|
||||||
|
_vehiclesDictionaryUpdaterMock.Verify(u => u.Update(), Times.Never);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task ShouldCallOnlyVehiclesDictionariesUpdater()
|
||||||
|
{
|
||||||
|
var updateResult = await _wargamingDictionaries.UpdateDictionaries(new UpdateDictionariesRequest
|
||||||
|
{DictionaryTypes = DictionaryType.Vehicles});
|
||||||
|
|
||||||
|
_staticDictionaryUpdaterMock.Verify(u => u.Update(), Times.Never);
|
||||||
|
_achievementsDictionaryUpdaterMock.Verify(u => u.Update(), Times.Never);
|
||||||
|
_vehiclesDictionaryUpdaterMock.Verify(u => u.Update(), Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task ShouldCallOnlyVehiclesAndAchievementsDictionariesUpdater()
|
||||||
|
{
|
||||||
|
var updateResult = await _wargamingDictionaries.UpdateDictionaries(new UpdateDictionariesRequest
|
||||||
|
{DictionaryTypes = DictionaryType.AchievementsAndVehicles});
|
||||||
|
|
||||||
|
_staticDictionaryUpdaterMock.Verify(u => u.Update(), Times.Never);
|
||||||
|
_achievementsDictionaryUpdaterMock.Verify(u => u.Update(), Times.Once);
|
||||||
|
_vehiclesDictionaryUpdaterMock.Verify(u => u.Update(), Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task ShouldCallAllDictionariesUpdater()
|
||||||
|
{
|
||||||
|
var updateResult = await _wargamingDictionaries.UpdateDictionaries(new UpdateDictionariesRequest
|
||||||
|
{DictionaryTypes = DictionaryType.All});
|
||||||
|
|
||||||
|
_staticDictionaryUpdaterMock.Verify(u => u.Update(), Times.Once);
|
||||||
|
_achievementsDictionaryUpdaterMock.Verify(u => u.Update(), Times.Once);
|
||||||
|
_vehiclesDictionaryUpdaterMock.Verify(u => u.Update(), Times.Once);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,293 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using AutoMapper;
|
||||||
|
using AutoMapper.Configuration;
|
||||||
|
using Bogus;
|
||||||
|
using FluentAssertions;
|
||||||
|
using Moq;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using WotBlitzStatisticsPro.Common.Dictionaries;
|
||||||
|
using WotBlitzStatisticsPro.Common.Model;
|
||||||
|
using WotBlitzStatisticsPro.DataAccess;
|
||||||
|
using WotBlitzStatisticsPro.Logic.Dictionaries;
|
||||||
|
using WotBlitzStatisticsPro.Logic.Mappers;
|
||||||
|
using WotBlitzStatisticsPro.WgApiClient;
|
||||||
|
using WotBlitzStatisticsPro.WgApiClient.Model;
|
||||||
|
|
||||||
|
namespace WotBlitzStatisticsPro.Tests.DictionariesTests
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class StaticDictionaryUpdaterTests
|
||||||
|
{
|
||||||
|
private StaticDictionariesUpdater _staticDictionariesUpdater;
|
||||||
|
|
||||||
|
private Mock<IWargamingDictionariesApiClient> _wargamingDictionariesApiClientMock;
|
||||||
|
private Mock<IDictionariesDataAccessor> _dataAccessorMock;
|
||||||
|
|
||||||
|
private readonly WotEncyclopediaInfoResponse[] _encyclopediaInfoResponse = new WotEncyclopediaInfoResponse[3];
|
||||||
|
|
||||||
|
private readonly WotClanMembersDictionaryResponse[] _clanMembersDictionary = new WotClanMembersDictionaryResponse[3];
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void Init()
|
||||||
|
{
|
||||||
|
// Generating fake data
|
||||||
|
_encyclopediaInfoResponse[0] = GetEncyclopediaInfoResponse("en");
|
||||||
|
_encyclopediaInfoResponse[1] = GetEncyclopediaInfoResponse("ru", _encyclopediaInfoResponse[0]);
|
||||||
|
_encyclopediaInfoResponse[2] = GetEncyclopediaInfoResponse("de", _encyclopediaInfoResponse[0]);
|
||||||
|
|
||||||
|
_clanMembersDictionary[0] = GetClanMembersDictionaryResponse("en");
|
||||||
|
_clanMembersDictionary[1] = GetClanMembersDictionaryResponse("ru", _clanMembersDictionary[0]);
|
||||||
|
_clanMembersDictionary[2] = GetClanMembersDictionaryResponse("de", _clanMembersDictionary[0]);
|
||||||
|
|
||||||
|
// Real mapper instance
|
||||||
|
var configurationExp = new MapperConfigurationExpression();
|
||||||
|
configurationExp.AddProfile<DictionaryLanguageMapper>();
|
||||||
|
var mapperConfiguration = new MapperConfiguration(configurationExp);
|
||||||
|
IMapper mapper = new Mapper(mapperConfiguration);
|
||||||
|
|
||||||
|
// Wargaming client mock
|
||||||
|
_wargamingDictionariesApiClientMock = new Mock<IWargamingDictionariesApiClient>();
|
||||||
|
_wargamingDictionariesApiClientMock.Setup(w =>
|
||||||
|
w.GetStaticDictionariesAsync(It.IsAny<RealmType>(), RequestLanguage.En))
|
||||||
|
.ReturnsAsync((_encyclopediaInfoResponse[0], _clanMembersDictionary[0]));
|
||||||
|
_wargamingDictionariesApiClientMock.Setup(w =>
|
||||||
|
w.GetStaticDictionariesAsync(It.IsAny<RealmType>(), RequestLanguage.Ru))
|
||||||
|
.ReturnsAsync((_encyclopediaInfoResponse[1], _clanMembersDictionary[1]));
|
||||||
|
_wargamingDictionariesApiClientMock.Setup(w =>
|
||||||
|
w.GetStaticDictionariesAsync(It.IsAny<RealmType>(), RequestLanguage.De))
|
||||||
|
.ReturnsAsync((_encyclopediaInfoResponse[2], _clanMembersDictionary[2]));
|
||||||
|
|
||||||
|
// MongoDb data accessor mock
|
||||||
|
_dataAccessorMock = new Mock<IDictionariesDataAccessor>();
|
||||||
|
|
||||||
|
_staticDictionariesUpdater = new StaticDictionariesUpdater(
|
||||||
|
_wargamingDictionariesApiClientMock.Object,
|
||||||
|
_dataAccessorMock.Object,
|
||||||
|
mapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task ShouldCallWargamingApi3Times()
|
||||||
|
{
|
||||||
|
await _staticDictionariesUpdater.Update();
|
||||||
|
|
||||||
|
// Should call wargaming API once for each language
|
||||||
|
_wargamingDictionariesApiClientMock.Verify(d => d.GetStaticDictionariesAsync(It.IsAny<RealmType>(), RequestLanguage.En), Times.Once);
|
||||||
|
_wargamingDictionariesApiClientMock.Verify(d => d.GetStaticDictionariesAsync(It.IsAny<RealmType>(), RequestLanguage.Ru), Times.Once);
|
||||||
|
_wargamingDictionariesApiClientMock.Verify(d => d.GetStaticDictionariesAsync(It.IsAny<RealmType>(), RequestLanguage.De), Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task ShouldSaveAppropriateLanguagesDictionary()
|
||||||
|
{
|
||||||
|
List<LanguageDictionary> languageDictionary = null;
|
||||||
|
_dataAccessorMock
|
||||||
|
.Setup(d => d.UpdateLanguages(It.IsAny<List<LanguageDictionary>>()))
|
||||||
|
.Callback((List<LanguageDictionary> dictionary) => languageDictionary = dictionary);
|
||||||
|
|
||||||
|
await _staticDictionariesUpdater.Update();
|
||||||
|
|
||||||
|
var sourceLanguages = _encyclopediaInfoResponse[0].Languages.ToArray();
|
||||||
|
|
||||||
|
languageDictionary.Should().NotBeNull();
|
||||||
|
languageDictionary.Should().HaveCount(sourceLanguages.Length);
|
||||||
|
for (int i = 0; i < sourceLanguages.Length; i++)
|
||||||
|
{
|
||||||
|
languageDictionary[i].LanguageId.Should().Be(sourceLanguages[i].Key);
|
||||||
|
languageDictionary[i].LanguageName.Should()
|
||||||
|
.Be(sourceLanguages[i].Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task ShouldSaveAppropriateNationsDictionary()
|
||||||
|
{
|
||||||
|
List<NationDictionary> nations = null;
|
||||||
|
_dataAccessorMock
|
||||||
|
.Setup(d => d.UpdateNations(It.IsAny<List<NationDictionary>>()))
|
||||||
|
.Callback((List<NationDictionary> dictionary) => nations = dictionary);
|
||||||
|
|
||||||
|
await _staticDictionariesUpdater.Update();
|
||||||
|
|
||||||
|
var sourceNationsEn = _encyclopediaInfoResponse[0].VehicleNations.ToArray();
|
||||||
|
var sourceNationsRu = _encyclopediaInfoResponse[1].VehicleNations.ToArray();
|
||||||
|
var sourceNationsDe = _encyclopediaInfoResponse[2].VehicleNations.ToArray();
|
||||||
|
|
||||||
|
nations.Should().NotBeNull();
|
||||||
|
nations.Should().HaveCount(sourceNationsEn.Length);
|
||||||
|
for (int i = 0; i < sourceNationsEn.Length; i++)
|
||||||
|
{
|
||||||
|
nations[i].NationId.Should().Be(sourceNationsEn[i].Key);
|
||||||
|
nations[i].NationNames.First(n => n.Language == RequestLanguage.En).Value.Should()
|
||||||
|
.Be(sourceNationsEn[i].Value);
|
||||||
|
nations[i].NationNames.First(n => n.Language == RequestLanguage.Ru).Value.Should()
|
||||||
|
.Be(sourceNationsRu[i].Value);
|
||||||
|
nations[i].NationNames.First(n => n.Language == RequestLanguage.De).Value.Should()
|
||||||
|
.Be(sourceNationsDe[i].Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task ShouldSaveAppropriateVehicleTypesDictionary()
|
||||||
|
{
|
||||||
|
List<VehicleTypeDictionary> vehicleTypes = null;
|
||||||
|
_dataAccessorMock
|
||||||
|
.Setup(d => d.UpdateVehicleTypes(It.IsAny<List<VehicleTypeDictionary>>()))
|
||||||
|
.Callback((List<VehicleTypeDictionary> dictionary) => vehicleTypes = dictionary);
|
||||||
|
|
||||||
|
await _staticDictionariesUpdater.Update();
|
||||||
|
|
||||||
|
var vehicleTypesEn = _encyclopediaInfoResponse[0].VehicleTypes.ToArray();
|
||||||
|
var vehicleTypesRu = _encyclopediaInfoResponse[1].VehicleTypes.ToArray();
|
||||||
|
var vehicleTypesDe = _encyclopediaInfoResponse[2].VehicleTypes.ToArray();
|
||||||
|
|
||||||
|
vehicleTypes.Should().NotBeNull();
|
||||||
|
vehicleTypes.Should().HaveCount(vehicleTypesEn.Length);
|
||||||
|
for (int i = 0; i < vehicleTypesEn.Length; i++)
|
||||||
|
{
|
||||||
|
vehicleTypes[i].VehicleTypeId.Should().Be(vehicleTypesEn[i].Key);
|
||||||
|
vehicleTypes[i].VehicleTypeNames.First(n => n.Language == RequestLanguage.En).Value.Should()
|
||||||
|
.Be(vehicleTypesEn[i].Value);
|
||||||
|
vehicleTypes[i].VehicleTypeNames.First(n => n.Language == RequestLanguage.Ru).Value.Should()
|
||||||
|
.Be(vehicleTypesRu[i].Value);
|
||||||
|
vehicleTypes[i].VehicleTypeNames.First(n => n.Language == RequestLanguage.De).Value.Should()
|
||||||
|
.Be(vehicleTypesDe[i].Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task ShouldSaveAppropriateClanRolesDictionary()
|
||||||
|
{
|
||||||
|
List<ClanRoleDictionary> clanRoles = null;
|
||||||
|
_dataAccessorMock
|
||||||
|
.Setup(d => d.UpdateClanRoles(It.IsAny<List<ClanRoleDictionary>>()))
|
||||||
|
.Callback((List<ClanRoleDictionary> dictionary) => clanRoles = dictionary);
|
||||||
|
|
||||||
|
await _staticDictionariesUpdater.Update();
|
||||||
|
|
||||||
|
var clanRoleEn = _clanMembersDictionary[0].ClanRoles.ToArray();
|
||||||
|
var clanRoleRu = _clanMembersDictionary[1].ClanRoles.ToArray();
|
||||||
|
var clanRoleDe = _clanMembersDictionary[2].ClanRoles.ToArray();
|
||||||
|
|
||||||
|
clanRoles.Should().NotBeNull();
|
||||||
|
clanRoles.Should().HaveCount(clanRoleEn.Length);
|
||||||
|
for (int i = 0; i < clanRoleEn.Length; i++)
|
||||||
|
{
|
||||||
|
clanRoles[i].ClanRoleId.Should().Be(clanRoleEn[i].Key);
|
||||||
|
clanRoles[i].ClanRoleNames.First(n => n.Language == RequestLanguage.En).Value.Should()
|
||||||
|
.Be(clanRoleEn[i].Value);
|
||||||
|
clanRoles[i].ClanRoleNames.First(n => n.Language == RequestLanguage.Ru).Value.Should()
|
||||||
|
.Be(clanRoleRu[i].Value);
|
||||||
|
clanRoles[i].ClanRoleNames.First(n => n.Language == RequestLanguage.De).Value.Should()
|
||||||
|
.Be(clanRoleDe[i].Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task ShouldSaveAppropriateAchievementsSectionsDictionary()
|
||||||
|
{
|
||||||
|
List<AchievementSectionDictionary> achievementsSections = null;
|
||||||
|
_dataAccessorMock
|
||||||
|
.Setup(d => d.UpdateAchievementsSections(It.IsAny<List<AchievementSectionDictionary>>()))
|
||||||
|
.Callback((List<AchievementSectionDictionary> dictionary) => achievementsSections = dictionary);
|
||||||
|
|
||||||
|
await _staticDictionariesUpdater.Update();
|
||||||
|
|
||||||
|
var asEn = _encyclopediaInfoResponse[0].AchievementSections.ToArray();
|
||||||
|
var asRu = _encyclopediaInfoResponse[1].AchievementSections.ToArray();
|
||||||
|
var asDe = _encyclopediaInfoResponse[2].AchievementSections.ToArray();
|
||||||
|
|
||||||
|
achievementsSections.Should().NotBeNull();
|
||||||
|
achievementsSections.Should().HaveCount(asEn.Length);
|
||||||
|
for (int i = 0; i < asEn.Length; i++)
|
||||||
|
{
|
||||||
|
achievementsSections[i].AchievementSectionId.Should().Be(asEn[i].Key);
|
||||||
|
achievementsSections[i].AchievementSectionNames.First(n => n.Language == RequestLanguage.En).Value.Should()
|
||||||
|
.Be(asEn[i].Value.Name);
|
||||||
|
achievementsSections[i].AchievementSectionNames.First(n => n.Language == RequestLanguage.Ru).Value.Should()
|
||||||
|
.Be(asRu[i].Value.Name);
|
||||||
|
achievementsSections[i].AchievementSectionNames.First(n => n.Language == RequestLanguage.De).Value.Should()
|
||||||
|
.Be(asDe[i].Value.Name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Fixtures
|
||||||
|
|
||||||
|
private static WotEncyclopediaInfoResponse GetEncyclopediaInfoResponse(string language, WotEncyclopediaInfoResponse baseEncyclopedia = null)
|
||||||
|
{
|
||||||
|
return new WotEncyclopediaInfoResponse
|
||||||
|
{
|
||||||
|
AchievementSections = baseEncyclopedia == null ? FakeAchievementSections(16, language) : FakeAchievementSections(language, baseEncyclopedia.AchievementSections),
|
||||||
|
Languages = baseEncyclopedia == null ? FakeDictionary(14) : baseEncyclopedia.Languages,
|
||||||
|
VehicleNations = baseEncyclopedia == null ? FakeDictionary(8, language) : FakeDictionary(language, baseEncyclopedia.VehicleNations),
|
||||||
|
VehicleTypes = baseEncyclopedia == null ? FakeDictionary(4, language) : FakeDictionary(language, baseEncyclopedia.VehicleTypes)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private static WotClanMembersDictionaryResponse GetClanMembersDictionaryResponse(string language, WotClanMembersDictionaryResponse baseClanRoles = null)
|
||||||
|
{
|
||||||
|
return new WotClanMembersDictionaryResponse
|
||||||
|
{
|
||||||
|
ClanRoles = baseClanRoles == null ? FakeDictionary(3, language) : FakeDictionary(language, baseClanRoles.ClanRoles)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Dictionary<string, string> FakeDictionary(int elementsCount, string language = "en")
|
||||||
|
{
|
||||||
|
var result = new Dictionary<string, string>();
|
||||||
|
var faker = new Faker(language);
|
||||||
|
|
||||||
|
for (int i = 0; i < elementsCount; i++)
|
||||||
|
{
|
||||||
|
result[faker.Lorem.Word()] = faker.Lorem.Word();
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Dictionary<string, string> FakeDictionary(string language,
|
||||||
|
Dictionary<string, string> baseDictionary)
|
||||||
|
{
|
||||||
|
var result = new Dictionary<string, string>();
|
||||||
|
var faker = new Faker(language);
|
||||||
|
|
||||||
|
foreach (var baseValue in baseDictionary)
|
||||||
|
{
|
||||||
|
result[baseValue.Key] = faker.Lorem.Word();
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Dictionary<string, WotEncyclopediaInfoAchievementSection> FakeAchievementSections(int elementsCount, string language = "en")
|
||||||
|
{
|
||||||
|
var result = new Dictionary<string, WotEncyclopediaInfoAchievementSection>();
|
||||||
|
var faker = new Faker(language);
|
||||||
|
|
||||||
|
for (int i = 0; i < elementsCount; i++)
|
||||||
|
{
|
||||||
|
result[faker.Lorem.Word()] = new WotEncyclopediaInfoAchievementSection {Name = faker.Lorem.Word()};
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Dictionary<string, WotEncyclopediaInfoAchievementSection> FakeAchievementSections(string language,
|
||||||
|
Dictionary<string, WotEncyclopediaInfoAchievementSection> baseDictionary)
|
||||||
|
{
|
||||||
|
var result = new Dictionary<string, WotEncyclopediaInfoAchievementSection>();
|
||||||
|
var faker = new Faker(language);
|
||||||
|
|
||||||
|
foreach (var baseValue in baseDictionary)
|
||||||
|
{
|
||||||
|
result[baseValue.Key] = new WotEncyclopediaInfoAchievementSection { Name = faker.Lorem.Word() };
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
|
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Bogus" Version="29.0.2" />
|
||||||
|
<PackageReference Include="FluentAssertions" Version="5.10.3" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.4" />
|
||||||
|
<PackageReference Include="Moq" Version="4.14.1" />
|
||||||
|
<PackageReference Include="nunit" Version="3.12.0" />
|
||||||
|
<PackageReference Include="NUnit3TestAdapter" Version="3.15.1" />
|
||||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\WotBlitzStatisticsPro.Common\WotBlitzStatisticsPro.Common.csproj" />
|
||||||
|
<ProjectReference Include="..\WotBlitzStatisticsPro.Logic\WotBlitzStatisticsPro.Logic.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@@ -15,6 +15,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WotBlitzStatisticsPro.Graph
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WotBlitzStatisticsPro.DataAccess", "WotBlitzStatisticsPro.DataAccess\WotBlitzStatisticsPro.DataAccess.csproj", "{19B1EDE4-1B83-49E2-A666-6CFE3A4A732E}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WotBlitzStatisticsPro.DataAccess", "WotBlitzStatisticsPro.DataAccess\WotBlitzStatisticsPro.DataAccess.csproj", "{19B1EDE4-1B83-49E2-A666-6CFE3A4A732E}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WotBlitzStatisticsPro.Tests", "WotBlitzStatisticsPro.Tests\WotBlitzStatisticsPro.Tests.csproj", "{551C3088-C6EA-45E1-A665-7C924C8407EB}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@@ -41,6 +43,10 @@ Global
|
|||||||
{19B1EDE4-1B83-49E2-A666-6CFE3A4A732E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{19B1EDE4-1B83-49E2-A666-6CFE3A4A732E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{19B1EDE4-1B83-49E2-A666-6CFE3A4A732E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{19B1EDE4-1B83-49E2-A666-6CFE3A4A732E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{19B1EDE4-1B83-49E2-A666-6CFE3A4A732E}.Release|Any CPU.Build.0 = Release|Any CPU
|
{19B1EDE4-1B83-49E2-A666-6CFE3A4A732E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{551C3088-C6EA-45E1-A665-7C924C8407EB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{551C3088-C6EA-45E1-A665-7C924C8407EB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{551C3088-C6EA-45E1-A665-7C924C8407EB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{551C3088-C6EA-45E1-A665-7C924C8407EB}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
@@ -49,6 +55,7 @@ Global
|
|||||||
{E1AB7997-C2A1-433B-A4F5-F8E9C4B73515} = {5095AE8F-F1D4-4BC0-95FD-B3DB0D3AED15}
|
{E1AB7997-C2A1-433B-A4F5-F8E9C4B73515} = {5095AE8F-F1D4-4BC0-95FD-B3DB0D3AED15}
|
||||||
{A79103B3-4F04-4090-803E-B7AABFCC93B1} = {5095AE8F-F1D4-4BC0-95FD-B3DB0D3AED15}
|
{A79103B3-4F04-4090-803E-B7AABFCC93B1} = {5095AE8F-F1D4-4BC0-95FD-B3DB0D3AED15}
|
||||||
{19B1EDE4-1B83-49E2-A666-6CFE3A4A732E} = {5095AE8F-F1D4-4BC0-95FD-B3DB0D3AED15}
|
{19B1EDE4-1B83-49E2-A666-6CFE3A4A732E} = {5095AE8F-F1D4-4BC0-95FD-B3DB0D3AED15}
|
||||||
|
{551C3088-C6EA-45E1-A665-7C924C8407EB} = {5095AE8F-F1D4-4BC0-95FD-B3DB0D3AED15}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
SolutionGuid = {295179CC-53B9-4A2F-8051-A6B033EED16E}
|
SolutionGuid = {295179CC-53B9-4A2F-8051-A6B033EED16E}
|
||||||
|
|||||||
Reference in new issue
Block a user