Skip to content

Commit

Permalink
Merge pull request #373 from SapiensAnatis/develop
Browse files Browse the repository at this point in the history
Merge develop into master
  • Loading branch information
SapiensAnatis authored Aug 6, 2023
2 parents a1386a3 + 3a63bba commit b938cdb
Show file tree
Hide file tree
Showing 304 changed files with 92,365 additions and 54,220 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/test-report.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: "test-report"

on:
workflow_run:
workflows: ["test"]
types:
- completed

jobs:
report:
runs-on: ubuntu-latest
steps:
- uses: dorny/test-reporter@v1
with:
artifact: test-results
name: test report
path: "*.trx"
reporter: dotnet-trx
15 changes: 6 additions & 9 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,13 @@ jobs:
run: dotnet restore ${{ matrix.project }}
- name: Test
run: >
dotnet test ${{ matrix.project }}
dotnet test ${{ matrix.project }}
--no-restore
--logger "console;verbosity=detailed"
-p:CollectCoverage=true
-p:CoverletOutputFormat="cobertura"
-p:CoverletOutput="coverage_report.xml"
-p:Exclude=\"[*.Test]*,[DragaliaAPI.Test.Utils]*,[DragaliaAPI.Photon.Plugin]*,[DragaliaAPI.Database]DragaliaAPI.Database.Migrations.*,[DragaliaAPI]DragaliaAPI.Models.Generated.*\"
- name: Upload coverage reports
--logger "trx;LogFileName=${{ matrix.project }}.trx"
- name: Upload test report
uses: actions/upload-artifact@v3
if: success() || failure() # run this step even if previous step failed
with:
name: ${{ matrix.project }} coverage report
path: ${{ matrix.project }}/coverage_report.xml
retention-days: 2
name: test-results
path: ${{ matrix.project }}/TestResults/${{ matrix.project }}.trx
7 changes: 5 additions & 2 deletions DragaliaAPI.Database.Test/DbTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ public DbTestFixture()
.Options;

this.ApiContext = new ApiContext(options);
Mock<ILogger<SavefileService>> mockLogger = new(MockBehavior.Loose);
// Unused for creating saves
Mock<ILogger<SavefileService>> mockLogger = new(MockBehavior.Loose);
Mock<IDistributedCache> mockCache = new(MockBehavior.Loose);
// Used but we probably don't want it to actually add characters?
Mock<IUnitRepository> mockUnitRepository = new(MockBehavior.Loose);

SavefileService savefileService =
new(
Expand All @@ -41,7 +43,8 @@ public DbTestFixture()
).CreateMapper(),
mockLogger.Object,
IdentityTestUtils.MockPlayerDetailsService.Object,
Enumerable.Empty<ISavefileUpdate>()
Enumerable.Empty<ISavefileUpdate>(),
mockUnitRepository.Object
);
savefileService.Create().Wait();
}
Expand Down
60 changes: 58 additions & 2 deletions DragaliaAPI.Database.Test/Repositories/FortRepositoryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,7 @@ public async Task AddDojos_AddsDojos()
FortPlants.BowDojo,
FortPlants.DaggerDojo,
FortPlants.LanceDojo,
FortPlants.SwordDojo,
FortPlants.ManacasterDojo,
FortPlants.SwordDojo,
FortPlants.StaffDojo,
FortPlants.WandDojo
};
Expand All @@ -354,4 +352,62 @@ public async Task AddDojos_AddsDojos()

this.mockPlayerIdentityService.VerifyAll();
}

[Fact]
public async Task AddToStorage_IsTotalQuantity_AddsBuilds()
{
this.mockPlayerIdentityService.SetupGet(x => x.AccountId).Returns("account id");

this.fixture.ApiContext.PlayerFortBuilds.AddRange(
new List<DbFortBuild>()
{
new() { DeviceAccountId = "some other id", PlantId = FortPlants.FlameDracolith, }
}
);
await this.fixture.ApiContext.SaveChangesAsync();

await this.fortRepository.AddToStorage(
FortPlants.FlameDracolith,
quantity: 1,
isTotalQuantity: true,
level: 4
);
await this.fixture.ApiContext.SaveChangesAsync();

this.fixture.ApiContext.PlayerFortBuilds
.Should()
.Contain(
x =>
x.DeviceAccountId == "account id"
&& x.Level == 4
&& x.PositionX == -1
&& x.PositionZ == -1
);
}

[Fact]
public async Task AddToStorage_IsTotalQuantity_AlreadyOwned_DoesNotAddBuilds()
{
this.mockPlayerIdentityService.SetupGet(x => x.AccountId).Returns("account id");

this.fixture.ApiContext.PlayerFortBuilds.AddRange(
new List<DbFortBuild>()
{
new() { DeviceAccountId = "account id", PlantId = FortPlants.WindDracolith, }
}
);
await this.fixture.ApiContext.SaveChangesAsync();

await this.fortRepository.AddToStorage(
FortPlants.WindDracolith,
quantity: 1,
isTotalQuantity: true,
level: 4
);
await this.fixture.ApiContext.SaveChangesAsync();

this.fixture.ApiContext.PlayerFortBuilds
.Should()
.ContainSingle(x => x.PlantId == FortPlants.WindDracolith);
}
}
6 changes: 3 additions & 3 deletions DragaliaAPI.Database.Test/Repositories/QuestRepositoryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ public async Task CompleteQuest_CompletesQuest()
DeviceAccountId = "id",
QuestId = 3,
State = 3,
IsMissionClear1 = true,
IsMissionClear2 = true,
IsMissionClear3 = true,
IsMissionClear1 = false,
IsMissionClear2 = false,
IsMissionClear3 = false,
PlayCount = 1,
DailyPlayCount = 1,
WeeklyPlayCount = 1,
Expand Down
5 changes: 3 additions & 2 deletions DragaliaAPI.Database.Test/Repositories/UnitRepositoryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,14 @@ public async Task CheckHasDragons_NotAllOwnedList_ReturnsFalse()
[Fact]
public async Task AddCharas_CorrectlyMarksDuplicates()
{
List<Charas> idList = new() { Charas.ThePrince, Charas.Chrom, Charas.Chrom };
List<Charas> idList =
new() { Charas.Chrom, Charas.Chrom, Charas.Panther, Charas.Izumo, Charas.Izumo };

(await this.unitRepository.AddCharas(idList))
.Where(x => x.isNew)
.Select(x => x.id)
.Should()
.BeEquivalentTo(new List<Charas>() { Charas.Chrom });
.BeEquivalentTo(new List<Charas>() { Charas.Chrom, Charas.Panther, Charas.Izumo });
}

[Fact]
Expand Down
26 changes: 26 additions & 0 deletions DragaliaAPI.Database/ApiContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,5 +156,31 @@ but EF Core doesn't like this and the client probably stops you anyway?

public DbSet<DbPlayerTrade> PlayerTrades { get; set; }

public DbSet<DbPlayerEventData> PlayerEventData { get; set; }

public DbSet<DbPlayerEventItem> PlayerEventItems { get; set; }

public DbSet<DbPlayerEventReward> PlayerEventRewards { get; set; }

public DbSet<DbPlayerEventPassive> PlayerEventPassives { get; set; }

public DbSet<DbQuestClearPartyUnit> QuestClearPartyUnits { get; set; }

public DbSet<DbPlayerDmodeInfo> PlayerDmodeInfos { get; set; }

public DbSet<DbPlayerDmodeChara> PlayerDmodeCharas { get; set; }

public DbSet<DbPlayerDmodeDungeon> PlayerDmodeDungeons { get; set; }

public DbSet<DbPlayerDmodeServitorPassive> PlayerDmodeServitorPassives { get; set; }

public DbSet<DbPlayerDmodeExpedition> PlayerDmodeExpeditions { get; set; }

public DbSet<DbPlayerUseItem> PlayerUseItems { get; set; }

public DbSet<DbLoginBonus> LoginBonuses { get; set; }

public DbSet<DbSummonTicket> PlayerSummonTickets { get; set; }

public DbSet<DbEmblem> Emblems { get; set; }
}
26 changes: 26 additions & 0 deletions DragaliaAPI.Database/Entities/DbEmblem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.ComponentModel.DataAnnotations.Schema;
using DragaliaAPI.Shared.Definitions.Enums;
using Microsoft.EntityFrameworkCore;

namespace DragaliaAPI.Database.Entities;

[Index(nameof(DeviceAccountId))]
[PrimaryKey(nameof(DeviceAccountId), nameof(EmblemId))]
public class DbEmblem : IDbHasAccountId
{
/// <inheritdoc />
public virtual DbPlayer? Owner { get; set; }

/// <inheritdoc />
[ForeignKey(nameof(Owner))]
public required string DeviceAccountId { get; set; }

[Column("EmblemId")]
public required Emblems EmblemId { get; set; }

[Column("IsNew")]
public bool IsNew { get; set; }

[Column("GetTime")]
public DateTimeOffset GetTime { get; set; } = DateTimeOffset.UnixEpoch;
}
28 changes: 28 additions & 0 deletions DragaliaAPI.Database/Entities/DbLoginBonus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;

namespace DragaliaAPI.Database.Entities;

[PrimaryKey(nameof(DeviceAccountId), nameof(Id))]
public class DbLoginBonus : IDbHasAccountId
{
public virtual DbPlayer? Owner { get; set; }

[ForeignKey(nameof(Owner))]
public required string DeviceAccountId { get; set; }

/// <summary>
/// Gets or sets the ID of the login bonus.
/// </summary>
public int Id { get; set; }

/// <summary>
/// Gets or sets the most recent day earned for this login bonus.
/// </summary>
public int CurrentDay { get; set; }

/// <summary>
/// Gets or sets a value indicating whether the login bonus has been completed.
/// </summary>
public bool IsComplete { get; set; }
}
12 changes: 12 additions & 0 deletions DragaliaAPI.Database/Entities/DbPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,17 @@ public class DbPlayer
public virtual ICollection<DbPlayerPresentHistory> PresentHistory { get; set; } =
new List<DbPlayerPresentHistory>();

public virtual ICollection<DbPlayerDmodeChara> DmodeCharas { get; set; } =
new List<DbPlayerDmodeChara>();

public virtual DbPlayerDmodeDungeon? DmodeDungeon { get; set; }

public virtual DbPlayerDmodeExpedition? DmodeExpedition { get; set; }

public virtual DbPlayerDmodeInfo? DmodeInfo { get; set; }

public virtual ICollection<DbPlayerDmodeServitorPassive> DmodeServitorPassives { get; set; } =
new List<DbPlayerDmodeServitorPassive>();

public virtual DbPlayerShopInfo? ShopInfo { get; set; }
}
40 changes: 40 additions & 0 deletions DragaliaAPI.Database/Entities/DbPlayerDmodeChara.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using DragaliaAPI.Shared.Definitions.Enums;
using Microsoft.EntityFrameworkCore;

namespace DragaliaAPI.Database.Entities;

[Index(nameof(DeviceAccountId))]
[PrimaryKey(nameof(DeviceAccountId), nameof(CharaId))]
public class DbPlayerDmodeChara : IDbHasAccountId
{
/// <inheritdoc />
public virtual DbPlayer? Owner { get; set; }

/// <inheritdoc />
[ForeignKey(nameof(Owner))]
[Required]
public required string DeviceAccountId { get; set; }

[Column("CharaId")]
public required Charas CharaId { get; set; }

[Column("MaxFloor")]
public int MaxFloor { get; set; }

[Column("MaxScore")]
public int MaxScore { get; set; }

[Column("SelectedServitorId")]
public int SelectedServitorId { get; set; }

[Column("SelectEditSkillCharaId1")]
public Charas SelectEditSkillCharaId1 { get; set; }

[Column("SelectEditSkillCharaId2")]
public Charas SelectEditSkillCharaId2 { get; set; }

[Column("SelectEditSkillCharaId3")]
public Charas SelectEditSkillCharaId3 { get; set; }
}
46 changes: 46 additions & 0 deletions DragaliaAPI.Database/Entities/DbPlayerDmodeDungeon.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using DragaliaAPI.Shared.Definitions.Enums;
using Microsoft.EntityFrameworkCore;

namespace DragaliaAPI.Database.Entities;

[PrimaryKey(nameof(DeviceAccountId))]
public class DbPlayerDmodeDungeon : IDbHasAccountId
{
/// <inheritdoc />
public virtual DbPlayer? Owner { get; set; }

/// <inheritdoc />
[ForeignKey(nameof(Owner))]
[Required]
public required string DeviceAccountId { get; set; }

[Column("CharaId")]
public Charas CharaId { get; set; }

[Column("Floor")]
public int Floor { get; set; }

[Column("QuestTime")]
public int QuestTime { get; set; }

[Column("DungeonScore")]
public int DungeonScore { get; set; }

[Column("IsPlayEnd")]
public bool IsPlayEnd { get; set; }

[Column("State")]
public DungeonState State { get; set; } = DungeonState.Waiting;

public void Clear()
{
CharaId = 0;
Floor = 0;
QuestTime = 0;
DungeonScore = 0;
IsPlayEnd = false;
State = DungeonState.Waiting;
}
}
Loading

0 comments on commit b938cdb

Please sign in to comment.