mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
Update tests with guids
This commit is contained in:
parent
73f4187087
commit
b2e0363594
@ -186,7 +186,6 @@ namespace Kyoo.Abstractions.Models
|
||||
// foreach (PeopleRole link in People)
|
||||
// link.Show = this;
|
||||
// }
|
||||
|
||||
if (Seasons != null)
|
||||
{
|
||||
foreach (Season season in Seasons)
|
||||
|
@ -85,7 +85,7 @@ namespace Kyoo.Tests.Database
|
||||
};
|
||||
await _repository.Create(collection);
|
||||
|
||||
Collection retrieved = await _repository.Get(2);
|
||||
Collection retrieved = await _repository.Get(2.AsGuid());
|
||||
Assert.Equal(2, retrieved.ExternalId.Count);
|
||||
KAssert.DeepEqual(collection.ExternalId.First(), retrieved.ExternalId.First());
|
||||
KAssert.DeepEqual(collection.ExternalId.Last(), retrieved.ExternalId.Last());
|
||||
|
@ -53,36 +53,36 @@ namespace Kyoo.Tests.Database
|
||||
[Fact]
|
||||
public async Task SlugEditTest()
|
||||
{
|
||||
Episode episode = await _repository.Get(1);
|
||||
Episode episode = await _repository.Get(1.AsGuid());
|
||||
Assert.Equal($"{TestSample.Get<Show>().Slug}-s1e1", episode.Slug);
|
||||
await Repositories.LibraryManager.Shows.Patch(episode.ShowId, (x) =>
|
||||
{
|
||||
x.Slug = "new-slug";
|
||||
return Task.FromResult(true);
|
||||
});
|
||||
episode = await _repository.Get(1);
|
||||
episode = await _repository.Get(1.AsGuid());
|
||||
Assert.Equal("new-slug-s1e1", episode.Slug);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task SeasonNumberEditTest()
|
||||
{
|
||||
Episode episode = await _repository.Get(1);
|
||||
Episode episode = await _repository.Get(1.AsGuid());
|
||||
Assert.Equal($"{TestSample.Get<Show>().Slug}-s1e1", episode.Slug);
|
||||
episode = await _repository.Patch(1, (x) =>
|
||||
episode = await _repository.Patch(1.AsGuid(), (x) =>
|
||||
{
|
||||
x.SeasonNumber = 2;
|
||||
return Task.FromResult(true);
|
||||
});
|
||||
Assert.Equal($"{TestSample.Get<Show>().Slug}-s2e1", episode.Slug);
|
||||
episode = await _repository.Get(1);
|
||||
episode = await _repository.Get(1.AsGuid());
|
||||
Assert.Equal($"{TestSample.Get<Show>().Slug}-s2e1", episode.Slug);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EpisodeNumberEditTest()
|
||||
{
|
||||
Episode episode = await _repository.Get(1);
|
||||
Episode episode = await _repository.Get(1.AsGuid());
|
||||
Assert.Equal($"{TestSample.Get<Show>().Slug}-s1e1", episode.Slug);
|
||||
episode = await Repositories.LibraryManager.Episodes.Patch(episode.Id, (x) =>
|
||||
{
|
||||
@ -90,7 +90,7 @@ namespace Kyoo.Tests.Database
|
||||
return Task.FromResult(true);
|
||||
});
|
||||
Assert.Equal($"{TestSample.Get<Show>().Slug}-s1e2", episode.Slug);
|
||||
episode = await _repository.Get(1);
|
||||
episode = await _repository.Get(1.AsGuid());
|
||||
Assert.Equal($"{TestSample.Get<Show>().Slug}-s1e2", episode.Slug);
|
||||
}
|
||||
|
||||
@ -98,7 +98,7 @@ namespace Kyoo.Tests.Database
|
||||
public async Task EpisodeCreationSlugTest()
|
||||
{
|
||||
Episode model = TestSample.Get<Episode>();
|
||||
model.Id = 0;
|
||||
model.Id = 0.AsGuid();
|
||||
model.ShowId = TestSample.Get<Show>().Id;
|
||||
model.SeasonNumber = 2;
|
||||
model.EpisodeNumber = 4;
|
||||
@ -129,7 +129,7 @@ namespace Kyoo.Tests.Database
|
||||
x.Slug = "new-slug";
|
||||
return Task.FromResult(true);
|
||||
});
|
||||
episode = await _repository.Get(2);
|
||||
episode = await _repository.Get(2.AsGuid());
|
||||
Assert.Equal($"new-slug-3", episode.Slug);
|
||||
}
|
||||
|
||||
@ -137,13 +137,13 @@ namespace Kyoo.Tests.Database
|
||||
public async Task AbsoluteNumberEditTest()
|
||||
{
|
||||
await _repository.Create(TestSample.GetAbsoluteEpisode());
|
||||
Episode episode = await _repository.Patch(2, (x) =>
|
||||
Episode episode = await _repository.Patch(2.AsGuid(), (x) =>
|
||||
{
|
||||
x.AbsoluteNumber = 56;
|
||||
return Task.FromResult(true);
|
||||
});
|
||||
Assert.Equal($"{TestSample.Get<Show>().Slug}-56", episode.Slug);
|
||||
episode = await _repository.Get(2);
|
||||
episode = await _repository.Get(2.AsGuid());
|
||||
Assert.Equal($"{TestSample.Get<Show>().Slug}-56", episode.Slug);
|
||||
}
|
||||
|
||||
@ -151,26 +151,26 @@ namespace Kyoo.Tests.Database
|
||||
public async Task AbsoluteToNormalEditTest()
|
||||
{
|
||||
await _repository.Create(TestSample.GetAbsoluteEpisode());
|
||||
Episode episode = await _repository.Patch(2, (x) =>
|
||||
Episode episode = await _repository.Patch(2.AsGuid(), (x) =>
|
||||
{
|
||||
x.SeasonNumber = 1;
|
||||
x.EpisodeNumber = 2;
|
||||
return Task.FromResult(true);
|
||||
});
|
||||
Assert.Equal($"{TestSample.Get<Show>().Slug}-s1e2", episode.Slug);
|
||||
episode = await _repository.Get(2);
|
||||
episode = await _repository.Get(2.AsGuid());
|
||||
Assert.Equal($"{TestSample.Get<Show>().Slug}-s1e2", episode.Slug);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task NormalToAbsoluteEditTest()
|
||||
{
|
||||
Episode episode = await _repository.Get(1);
|
||||
Episode episode = await _repository.Get(1.AsGuid());
|
||||
episode.SeasonNumber = null;
|
||||
episode.AbsoluteNumber = 12;
|
||||
episode = await _repository.Edit(episode);
|
||||
Assert.Equal($"{TestSample.Get<Show>().Slug}-12", episode.Slug);
|
||||
episode = await _repository.Get(1);
|
||||
episode = await _repository.Get(1.AsGuid());
|
||||
Assert.Equal($"{TestSample.Get<Show>().Slug}-12", episode.Slug);
|
||||
}
|
||||
|
||||
@ -193,7 +193,7 @@ namespace Kyoo.Tests.Database
|
||||
};
|
||||
await _repository.Create(value);
|
||||
|
||||
Episode retrieved = await _repository.Get(2);
|
||||
Episode retrieved = await _repository.Get(2.AsGuid());
|
||||
Assert.Equal(2, retrieved.ExternalId.Count);
|
||||
KAssert.DeepEqual(value.ExternalId.First(), retrieved.ExternalId.First());
|
||||
KAssert.DeepEqual(value.ExternalId.Last(), retrieved.ExternalId.Last());
|
||||
@ -278,7 +278,7 @@ namespace Kyoo.Tests.Database
|
||||
public async Task SearchTest(string query)
|
||||
{
|
||||
Episode value = TestSample.Get<Episode>();
|
||||
value.Id = 0;
|
||||
value.Id = 0.AsGuid();
|
||||
value.Name = "This is a test super title";
|
||||
value.EpisodeNumber = 56;
|
||||
await _repository.Create(value);
|
||||
@ -293,7 +293,7 @@ namespace Kyoo.Tests.Database
|
||||
await _repository.Delete(TestSample.Get<Episode>());
|
||||
|
||||
Episode expected = TestSample.Get<Episode>();
|
||||
expected.Id = 0;
|
||||
expected.Id = 0.AsGuid();
|
||||
expected.ShowId = (await Repositories.LibraryManager.Shows.Create(TestSample.Get<Show>())).Id;
|
||||
expected.SeasonId = (await Repositories.LibraryManager.Seasons.Create(TestSample.Get<Season>())).Id;
|
||||
await _repository.Create(expected);
|
||||
|
@ -1,161 +0,0 @@
|
||||
// Kyoo - A portable and vast media library solution.
|
||||
// Copyright (c) Kyoo.
|
||||
//
|
||||
// See AUTHORS.md and LICENSE file in the project root for full license information.
|
||||
//
|
||||
// Kyoo is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// any later version.
|
||||
//
|
||||
// Kyoo is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Kyoo.Abstractions.Controllers;
|
||||
using Kyoo.Abstractions.Models;
|
||||
using Kyoo.Postgresql;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace Kyoo.Tests.Database
|
||||
{
|
||||
namespace PostgreSQL
|
||||
{
|
||||
[Collection(nameof(Postgresql))]
|
||||
public class PeopleTests : APeopleTests
|
||||
{
|
||||
public PeopleTests(PostgresFixture postgres, ITestOutputHelper output)
|
||||
: base(new RepositoryActivator(output, postgres)) { }
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class APeopleTests : RepositoryTests<People>
|
||||
{
|
||||
private readonly IRepository<People> _repository;
|
||||
|
||||
protected APeopleTests(RepositoryActivator repositories)
|
||||
: base(repositories)
|
||||
{
|
||||
_repository = Repositories.LibraryManager.People;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CreateWithExternalIdTest()
|
||||
{
|
||||
People value = TestSample.GetNew<People>();
|
||||
value.ExternalId = new Dictionary<string, MetadataId>
|
||||
{
|
||||
["2"] = new()
|
||||
{
|
||||
Link = "link",
|
||||
DataId = "id"
|
||||
},
|
||||
["1"] = new()
|
||||
{
|
||||
Link = "new-provider-link",
|
||||
DataId = "new-id"
|
||||
}
|
||||
};
|
||||
await _repository.Create(value);
|
||||
|
||||
People retrieved = await _repository.Get(2);
|
||||
Assert.Equal(2, retrieved.ExternalId.Count);
|
||||
KAssert.DeepEqual(value.ExternalId.First(), retrieved.ExternalId.First());
|
||||
KAssert.DeepEqual(value.ExternalId.Last(), retrieved.ExternalId.Last());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EditTest()
|
||||
{
|
||||
People value = await _repository.Get(TestSample.Get<People>().Slug);
|
||||
value.Name = "New Name";
|
||||
value.Poster = new Image("poster");
|
||||
await _repository.Edit(value);
|
||||
|
||||
await using DatabaseContext database = Repositories.Context.New();
|
||||
People retrieved = await database.People.FirstAsync();
|
||||
|
||||
KAssert.DeepEqual(value, retrieved);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EditMetadataTest()
|
||||
{
|
||||
People value = await _repository.Get(TestSample.Get<People>().Slug);
|
||||
value.ExternalId = new Dictionary<string, MetadataId>
|
||||
{
|
||||
["toto"] = new()
|
||||
{
|
||||
Link = "link",
|
||||
DataId = "id"
|
||||
},
|
||||
};
|
||||
await _repository.Edit(value);
|
||||
|
||||
await using DatabaseContext database = Repositories.Context.New();
|
||||
People retrieved = await database.People.FirstAsync();
|
||||
|
||||
KAssert.DeepEqual(value, retrieved);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AddMetadataTest()
|
||||
{
|
||||
People value = await _repository.Get(TestSample.Get<People>().Slug);
|
||||
value.ExternalId = new Dictionary<string, MetadataId>
|
||||
{
|
||||
["1"] = new()
|
||||
{
|
||||
Link = "link",
|
||||
DataId = "id"
|
||||
},
|
||||
};
|
||||
await _repository.Edit(value);
|
||||
|
||||
{
|
||||
await using DatabaseContext database = Repositories.Context.New();
|
||||
People retrieved = await database.People.FirstAsync();
|
||||
KAssert.DeepEqual(value, retrieved);
|
||||
}
|
||||
|
||||
value.ExternalId.Add("toto", new MetadataId
|
||||
{
|
||||
Link = "link",
|
||||
DataId = "id"
|
||||
});
|
||||
await _repository.Edit(value);
|
||||
|
||||
{
|
||||
await using DatabaseContext database = Repositories.Context.New();
|
||||
People retrieved = await database.People.FirstAsync();
|
||||
|
||||
KAssert.DeepEqual(value, retrieved);
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("Me")]
|
||||
[InlineData("me")]
|
||||
[InlineData("na")]
|
||||
public async Task SearchTest(string query)
|
||||
{
|
||||
People value = new()
|
||||
{
|
||||
Slug = "slug",
|
||||
Name = "name",
|
||||
};
|
||||
await _repository.Create(value);
|
||||
ICollection<People> ret = await _repository.Search(query);
|
||||
KAssert.DeepEqual(value, ret.First());
|
||||
}
|
||||
}
|
||||
}
|
@ -51,21 +51,21 @@ namespace Kyoo.Tests.Database
|
||||
[Fact]
|
||||
public async Task SlugEditTest()
|
||||
{
|
||||
Season season = await _repository.Get(1);
|
||||
Season season = await _repository.Get(1.AsGuid());
|
||||
Assert.Equal("anohana-s1", season.Slug);
|
||||
await Repositories.LibraryManager.Shows.Patch(season.ShowId, (x) =>
|
||||
{
|
||||
x.Slug = "new-slug";
|
||||
return Task.FromResult(true);
|
||||
});
|
||||
season = await _repository.Get(1);
|
||||
season = await _repository.Get(1.AsGuid());
|
||||
Assert.Equal("new-slug-s1", season.Slug);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task SeasonNumberEditTest()
|
||||
{
|
||||
Season season = await _repository.Get(1);
|
||||
Season season = await _repository.Get(1.AsGuid());
|
||||
Assert.Equal("anohana-s1", season.Slug);
|
||||
await _repository.Patch(season.Id, (x) =>
|
||||
{
|
||||
@ -73,7 +73,7 @@ namespace Kyoo.Tests.Database
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
);
|
||||
season = await _repository.Get(1);
|
||||
season = await _repository.Get(1.AsGuid());
|
||||
Assert.Equal("anohana-s2", season.Slug);
|
||||
}
|
||||
|
||||
@ -107,7 +107,7 @@ namespace Kyoo.Tests.Database
|
||||
};
|
||||
await _repository.Create(season);
|
||||
|
||||
Season retrieved = await _repository.Get(2);
|
||||
Season retrieved = await _repository.Get(2.AsGuid());
|
||||
Assert.Equal(2, retrieved.ExternalId.Count);
|
||||
KAssert.DeepEqual(season.ExternalId.First(), retrieved.ExternalId.First());
|
||||
KAssert.DeepEqual(season.ExternalId.Last(), retrieved.ExternalId.Last());
|
||||
@ -194,7 +194,7 @@ namespace Kyoo.Tests.Database
|
||||
Season value = new()
|
||||
{
|
||||
Name = "This is a test super title",
|
||||
ShowId = 1
|
||||
ShowId = 1.AsGuid()
|
||||
};
|
||||
await _repository.Create(value);
|
||||
ICollection<Season> ret = await _repository.Search(query);
|
||||
|
@ -19,7 +19,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using FluentAssertions;
|
||||
using Kyoo.Abstractions.Controllers;
|
||||
using Kyoo.Abstractions.Models;
|
||||
using Kyoo.Postgresql;
|
||||
@ -132,40 +131,40 @@ namespace Kyoo.Tests.Database
|
||||
Assert.Equal(value.Aliases, show.Aliases);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EditPeopleTest()
|
||||
{
|
||||
Show value = await _repository.Get(TestSample.Get<Show>().Slug);
|
||||
value.People = new[]
|
||||
{
|
||||
new PeopleRole
|
||||
{
|
||||
Show = value,
|
||||
People = TestSample.Get<People>(),
|
||||
ForPeople = false,
|
||||
Type = "Actor",
|
||||
Role = "NiceCharacter"
|
||||
}
|
||||
};
|
||||
Show edited = await _repository.Edit(value);
|
||||
|
||||
Assert.Equal(value.Slug, edited.Slug);
|
||||
Assert.Equal(edited.People!.First().ShowID, value.Id);
|
||||
Assert.Equal(
|
||||
value.People.Select(x => new { x.Role, x.Slug, x.People.Name }),
|
||||
edited.People.Select(x => new { x.Role, x.Slug, x.People.Name }));
|
||||
|
||||
await using DatabaseContext database = Repositories.Context.New();
|
||||
Show show = await database.Shows
|
||||
.Include(x => x.People)
|
||||
.ThenInclude(x => x.People)
|
||||
.FirstAsync();
|
||||
|
||||
Assert.Equal(value.Slug, show.Slug);
|
||||
Assert.Equal(
|
||||
value.People.Select(x => new { x.Role, x.Slug, x.People.Name }),
|
||||
show.People!.Select(x => new { x.Role, x.Slug, x.People.Name }));
|
||||
}
|
||||
// [Fact]
|
||||
// public async Task EditPeopleTest()
|
||||
// {
|
||||
// Show value = await _repository.Get(TestSample.Get<Show>().Slug);
|
||||
// value.People = new[]
|
||||
// {
|
||||
// new PeopleRole
|
||||
// {
|
||||
// Show = value,
|
||||
// People = TestSample.Get<People>(),
|
||||
// ForPeople = false,
|
||||
// Type = "Actor",
|
||||
// Role = "NiceCharacter"
|
||||
// }
|
||||
// };
|
||||
// Show edited = await _repository.Edit(value);
|
||||
//
|
||||
// Assert.Equal(value.Slug, edited.Slug);
|
||||
// Assert.Equal(edited.People!.First().ShowID, value.Id);
|
||||
// Assert.Equal(
|
||||
// value.People.Select(x => new { x.Role, x.Slug, x.People.Name }),
|
||||
// edited.People.Select(x => new { x.Role, x.Slug, x.People.Name }));
|
||||
//
|
||||
// await using DatabaseContext database = Repositories.Context.New();
|
||||
// Show show = await database.Shows
|
||||
// .Include(x => x.People)
|
||||
// .ThenInclude(x => x.People)
|
||||
// .FirstAsync();
|
||||
//
|
||||
// Assert.Equal(value.Slug, show.Slug);
|
||||
// Assert.Equal(
|
||||
// value.People.Select(x => new { x.Role, x.Slug, x.People.Name }),
|
||||
// show.People!.Select(x => new { x.Role, x.Slug, x.People.Name }));
|
||||
// }
|
||||
|
||||
[Fact]
|
||||
public async Task EditExternalIDsTest()
|
||||
@ -194,7 +193,7 @@ namespace Kyoo.Tests.Database
|
||||
public async Task CreateWithRelationsTest()
|
||||
{
|
||||
Show expected = TestSample.Get<Show>();
|
||||
expected.Id = 0;
|
||||
expected.Id = 0.AsGuid();
|
||||
expected.Slug = "created-relation-test";
|
||||
expected.ExternalId = new Dictionary<string, MetadataId>
|
||||
{
|
||||
@ -204,44 +203,44 @@ namespace Kyoo.Tests.Database
|
||||
}
|
||||
};
|
||||
expected.Genres = new List<Genre>() { Genre.Action };
|
||||
expected.People = new[]
|
||||
{
|
||||
new PeopleRole
|
||||
{
|
||||
People = TestSample.Get<People>(),
|
||||
Show = expected,
|
||||
ForPeople = false,
|
||||
Role = "actor",
|
||||
Type = "actor"
|
||||
}
|
||||
};
|
||||
// expected.People = new[]
|
||||
// {
|
||||
// new PeopleRole
|
||||
// {
|
||||
// People = TestSample.Get<People>(),
|
||||
// Show = expected,
|
||||
// ForPeople = false,
|
||||
// Role = "actor",
|
||||
// Type = "actor"
|
||||
// }
|
||||
// };
|
||||
expected.Studio = new Studio("studio");
|
||||
Show created = await _repository.Create(expected);
|
||||
KAssert.DeepEqual(expected, created);
|
||||
|
||||
await using DatabaseContext context = Repositories.Context.New();
|
||||
Show retrieved = await context.Shows
|
||||
.Include(x => x.People)
|
||||
.ThenInclude(x => x.People)
|
||||
// .Include(x => x.People)
|
||||
// .ThenInclude(x => x.People)
|
||||
.Include(x => x.Studio)
|
||||
.FirstAsync(x => x.Id == created.Id);
|
||||
retrieved.People.ForEach(x =>
|
||||
{
|
||||
x.Show = null;
|
||||
x.People.Roles = null;
|
||||
x.People.Poster = null;
|
||||
x.People.Thumbnail = null;
|
||||
x.People.Logo = null;
|
||||
});
|
||||
// retrieved.People.ForEach(x =>
|
||||
// {
|
||||
// x.Show = null;
|
||||
// x.People.Roles = null;
|
||||
// x.People.Poster = null;
|
||||
// x.People.Thumbnail = null;
|
||||
// x.People.Logo = null;
|
||||
// });
|
||||
retrieved.Studio!.Shows = null;
|
||||
expected.People.ForEach(x =>
|
||||
{
|
||||
x.Show = null;
|
||||
x.People.Roles = null;
|
||||
x.People.Poster = null;
|
||||
x.People.Thumbnail = null;
|
||||
x.People.Logo = null;
|
||||
});
|
||||
// expected.People.ForEach(x =>
|
||||
// {
|
||||
// x.Show = null;
|
||||
// x.People.Roles = null;
|
||||
// x.People.Poster = null;
|
||||
// x.People.Thumbnail = null;
|
||||
// x.People.Logo = null;
|
||||
// });
|
||||
|
||||
KAssert.DeepEqual(retrieved, expected);
|
||||
}
|
||||
@ -250,7 +249,7 @@ namespace Kyoo.Tests.Database
|
||||
public async Task CreateWithExternalID()
|
||||
{
|
||||
Show expected = TestSample.Get<Show>();
|
||||
expected.Id = 0;
|
||||
expected.Id = 0.AsGuid();
|
||||
expected.Slug = "created-relation-test";
|
||||
expected.ExternalId = new Dictionary<string, MetadataId>
|
||||
{
|
||||
@ -272,7 +271,7 @@ namespace Kyoo.Tests.Database
|
||||
public async Task SlugDuplicationTest()
|
||||
{
|
||||
Show test = TestSample.Get<Show>();
|
||||
test.Id = 0;
|
||||
test.Id = 0.AsGuid();
|
||||
test.Slug = "300";
|
||||
Show created = await _repository.Create(test);
|
||||
Assert.Equal("300!", created.Slug);
|
||||
|
@ -31,7 +31,7 @@ namespace Kyoo.Tests
|
||||
typeof(Collection),
|
||||
() => new Collection
|
||||
{
|
||||
Id = 2,
|
||||
Id = 2.AsGuid(),
|
||||
Slug = "new-collection",
|
||||
Name = "New Collection",
|
||||
Overview = "A collection created by new sample",
|
||||
@ -42,7 +42,7 @@ namespace Kyoo.Tests
|
||||
typeof(Show),
|
||||
() => new Show
|
||||
{
|
||||
Id = 2,
|
||||
Id = 2.AsGuid(),
|
||||
Slug = "new-show",
|
||||
Name = "New Show",
|
||||
Overview = "overview",
|
||||
@ -59,8 +59,8 @@ namespace Kyoo.Tests
|
||||
typeof(Season),
|
||||
() => new Season
|
||||
{
|
||||
Id = 2,
|
||||
ShowId = 1,
|
||||
Id = 2.AsGuid(),
|
||||
ShowId = 1.AsGuid(),
|
||||
ShowSlug = Get<Show>().Slug,
|
||||
Name = "New season",
|
||||
Overview = "New overview",
|
||||
@ -74,10 +74,10 @@ namespace Kyoo.Tests
|
||||
typeof(Episode),
|
||||
() => new Episode
|
||||
{
|
||||
Id = 2,
|
||||
ShowId = 1,
|
||||
Id = 2.AsGuid(),
|
||||
ShowId = 1.AsGuid(),
|
||||
ShowSlug = Get<Show>().Slug,
|
||||
SeasonId = 1,
|
||||
SeasonId = 1.AsGuid(),
|
||||
SeasonNumber = Get<Season>().SeasonNumber,
|
||||
EpisodeNumber = 3,
|
||||
AbsoluteNumber = 4,
|
||||
@ -92,7 +92,7 @@ namespace Kyoo.Tests
|
||||
typeof(People),
|
||||
() => new People
|
||||
{
|
||||
Id = 2,
|
||||
Id = 2.AsGuid(),
|
||||
Slug = "new-person-name",
|
||||
Name = "New person name",
|
||||
Logo = new Image("Old Logo"),
|
||||
@ -107,7 +107,7 @@ namespace Kyoo.Tests
|
||||
typeof(Collection),
|
||||
() => new Collection
|
||||
{
|
||||
Id = 1,
|
||||
Id = 1.AsGuid(),
|
||||
Slug = "collection",
|
||||
Name = "Collection",
|
||||
Overview = "A nice collection for tests",
|
||||
@ -118,7 +118,7 @@ namespace Kyoo.Tests
|
||||
typeof(Show),
|
||||
() => new Show
|
||||
{
|
||||
Id = 1,
|
||||
Id = 1.AsGuid(),
|
||||
Slug = "anohana",
|
||||
Name = "Anohana: The Flower We Saw That Day",
|
||||
Aliases = new List<string>
|
||||
@ -131,7 +131,7 @@ namespace Kyoo.Tests
|
||||
"In time, however, these childhood friends drifted apart, and when they became high " +
|
||||
"school students, they had long ceased to think of each other as friends.",
|
||||
Status = Status.Finished,
|
||||
StudioId = 1,
|
||||
StudioId = 1.AsGuid(),
|
||||
StartAir = new DateTime(2011, 1, 1).ToUniversalTime(),
|
||||
EndAir = new DateTime(2011, 1, 1).ToUniversalTime(),
|
||||
Poster = new Image("Poster"),
|
||||
@ -144,9 +144,9 @@ namespace Kyoo.Tests
|
||||
typeof(Season),
|
||||
() => new Season
|
||||
{
|
||||
Id = 1,
|
||||
Id = 1.AsGuid(),
|
||||
ShowSlug = "anohana",
|
||||
ShowId = 1,
|
||||
ShowId = 1.AsGuid(),
|
||||
SeasonNumber = 1,
|
||||
Name = "Season 1",
|
||||
Overview = "The first season",
|
||||
@ -161,10 +161,10 @@ namespace Kyoo.Tests
|
||||
typeof(Episode),
|
||||
() => new Episode
|
||||
{
|
||||
Id = 1,
|
||||
Id = 1.AsGuid(),
|
||||
ShowSlug = "anohana",
|
||||
ShowId = 1,
|
||||
SeasonId = 1,
|
||||
ShowId = 1.AsGuid(),
|
||||
SeasonId = 1.AsGuid(),
|
||||
SeasonNumber = 1,
|
||||
EpisodeNumber = 1,
|
||||
AbsoluteNumber = 1,
|
||||
@ -181,7 +181,7 @@ namespace Kyoo.Tests
|
||||
typeof(People),
|
||||
() => new People
|
||||
{
|
||||
Id = 1,
|
||||
Id = 1.AsGuid(),
|
||||
Slug = "the-actor",
|
||||
Name = "The Actor",
|
||||
Poster = new Image("Poster"),
|
||||
@ -193,7 +193,7 @@ namespace Kyoo.Tests
|
||||
typeof(Studio),
|
||||
() => new Studio
|
||||
{
|
||||
Id = 1,
|
||||
Id = 1.AsGuid(),
|
||||
Slug = "hyper-studio",
|
||||
Name = "Hyper studio",
|
||||
}
|
||||
@ -202,7 +202,7 @@ namespace Kyoo.Tests
|
||||
typeof(User),
|
||||
() => new User
|
||||
{
|
||||
Id = 1,
|
||||
Id = 1.AsGuid(),
|
||||
Slug = "user",
|
||||
Username = "User",
|
||||
Email = "user@im-a-user.com",
|
||||
@ -225,39 +225,39 @@ namespace Kyoo.Tests
|
||||
public static void FillDatabase(DatabaseContext context)
|
||||
{
|
||||
Collection collection = Get<Collection>();
|
||||
collection.Id = 0;
|
||||
collection.Id = 0.AsGuid();
|
||||
context.Collections.Add(collection);
|
||||
|
||||
Show show = Get<Show>();
|
||||
show.Id = 0;
|
||||
show.StudioId = 0;
|
||||
show.Id = 0.AsGuid();
|
||||
show.StudioId = 0.AsGuid();
|
||||
context.Shows.Add(show);
|
||||
|
||||
Season season = Get<Season>();
|
||||
season.Id = 0;
|
||||
season.ShowId = 0;
|
||||
season.Id = 0.AsGuid();
|
||||
season.ShowId = 0.AsGuid();
|
||||
season.Show = show;
|
||||
context.Seasons.Add(season);
|
||||
|
||||
Episode episode = Get<Episode>();
|
||||
episode.Id = 0;
|
||||
episode.ShowId = 0;
|
||||
episode.Id = 0.AsGuid();
|
||||
episode.ShowId = 0.AsGuid();
|
||||
episode.Show = show;
|
||||
episode.SeasonId = 0;
|
||||
episode.SeasonId = 0.AsGuid();
|
||||
episode.Season = season;
|
||||
context.Episodes.Add(episode);
|
||||
|
||||
Studio studio = Get<Studio>();
|
||||
studio.Id = 0;
|
||||
studio.Id = 0.AsGuid();
|
||||
studio.Shows = new List<Show> { show };
|
||||
context.Studios.Add(studio);
|
||||
|
||||
People people = Get<People>();
|
||||
people.Id = 0;
|
||||
context.People.Add(people);
|
||||
people.Id = 0.AsGuid();
|
||||
// context.People.Add(people);
|
||||
|
||||
User user = Get<User>();
|
||||
user.Id = 0;
|
||||
user.Id = 0.AsGuid();
|
||||
context.Users.Add(user);
|
||||
|
||||
context.SaveChanges();
|
||||
@ -267,9 +267,9 @@ namespace Kyoo.Tests
|
||||
{
|
||||
return new()
|
||||
{
|
||||
Id = 2,
|
||||
Id = 2.AsGuid(),
|
||||
ShowSlug = "anohana",
|
||||
ShowId = 1,
|
||||
ShowId = 1.AsGuid(),
|
||||
SeasonNumber = null,
|
||||
EpisodeNumber = null,
|
||||
AbsoluteNumber = 3,
|
||||
|
@ -17,6 +17,7 @@
|
||||
// along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
using FluentAssertions;
|
||||
using JetBrains.Annotations;
|
||||
using Kyoo.Abstractions.Models;
|
||||
@ -64,5 +65,21 @@ namespace Kyoo.Tests
|
||||
{
|
||||
throw new XunitException(message);
|
||||
}
|
||||
|
||||
public static Guid AsGuid(this string src)
|
||||
{
|
||||
// Use MD5 since (1) it's faster then SHA and (2) it's already 16 bytes which matches the Guid
|
||||
return string.IsNullOrWhiteSpace(src)
|
||||
? Guid.Empty
|
||||
: new Guid(MD5.Create().ComputeHash(System.Text.Encoding.UTF8.GetBytes(src)));
|
||||
}
|
||||
|
||||
public static Guid AsGuid(this int src)
|
||||
{
|
||||
// Use MD5 since (1) it's faster then SHA and (2) it's already 16 bytes which matches the Guid
|
||||
return src == 0
|
||||
? Guid.Empty
|
||||
: new Guid(MD5.Create().ComputeHash(BitConverter.GetBytes(src)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -36,11 +36,11 @@ namespace Kyoo.Tests.Utility
|
||||
Studio genre2 = new()
|
||||
{
|
||||
Name = "test",
|
||||
Id = 5,
|
||||
Id = 5.AsGuid(),
|
||||
};
|
||||
Studio ret = Merger.Complete(genre, genre2);
|
||||
Assert.True(ReferenceEquals(genre, ret));
|
||||
Assert.Equal(5, ret.Id);
|
||||
Assert.Equal(5.AsGuid(), ret.Id);
|
||||
Assert.Equal("test", genre.Name);
|
||||
Assert.Null(genre.Slug);
|
||||
}
|
||||
@ -54,12 +54,12 @@ namespace Kyoo.Tests.Utility
|
||||
};
|
||||
Collection collection2 = new()
|
||||
{
|
||||
Id = 5,
|
||||
Id = 5.AsGuid(),
|
||||
Name = "test",
|
||||
};
|
||||
Collection ret = Merger.Complete(collection, collection2);
|
||||
Assert.True(ReferenceEquals(collection, ret));
|
||||
Assert.Equal(5, ret.Id);
|
||||
Assert.Equal(5.AsGuid(), ret.Id);
|
||||
Assert.Equal("test", ret.Name);
|
||||
Assert.Null(ret.Slug);
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ namespace Kyoo.Tests.Utility
|
||||
[Fact]
|
||||
public void IsPropertyExpression_Tests()
|
||||
{
|
||||
Expression<Func<Show, int>> member = x => x.Id;
|
||||
Expression<Func<Show, Guid>> member = x => x.Id;
|
||||
Expression<Func<Show, object>> memberCast = x => x.Id;
|
||||
|
||||
Assert.True(KUtility.IsPropertyExpression(member));
|
||||
@ -44,7 +44,7 @@ namespace Kyoo.Tests.Utility
|
||||
[Fact]
|
||||
public void GetPropertyName_Test()
|
||||
{
|
||||
Expression<Func<Show, int>> member = x => x.Id;
|
||||
Expression<Func<Show, Guid>> member = x => x.Id;
|
||||
Expression<Func<Show, object>> memberCast = x => x.Id;
|
||||
|
||||
Assert.Equal("Id", KUtility.GetPropertyName(member));
|
||||
|
Loading…
x
Reference in New Issue
Block a user