-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6c2e5fa
commit 0f89be9
Showing
28 changed files
with
493 additions
and
42 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
...e/Wemogy.Infrastructure.Database.Core.UnitTests/DatabaseRepositories/IAnimalRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System; | ||
using Wemogy.Infrastructure.Database.Core.Abstractions; | ||
using Wemogy.Infrastructure.Database.Core.Attributes; | ||
using Wemogy.Infrastructure.Database.Core.UnitTests.Fakes.Entities; | ||
|
||
namespace Wemogy.Infrastructure.Database.Core.UnitTests.DatabaseRepositories; | ||
|
||
[RepositoryOptions(enableSoftDelete: true)] | ||
public interface IAnimalRepository : IDatabaseRepository<Animal, Guid, string> | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/core/Wemogy.Infrastructure.Database.Core.UnitTests/Fakes/Entities/Animal.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System; | ||
using Bogus; | ||
using Wemogy.Core.Extensions; | ||
using Wemogy.Infrastructure.Database.Core.Abstractions; | ||
using Wemogy.Infrastructure.Database.Core.Attributes; | ||
|
||
namespace Wemogy.Infrastructure.Database.Core.UnitTests.Fakes.Entities; | ||
|
||
public class Animal : EntityBase<string> | ||
{ | ||
[PartitionKey] | ||
public Guid TenantId { get; set; } | ||
|
||
public string Firstname { get; set; } | ||
|
||
public string Lastname { get; set; } | ||
|
||
public string PrivateNote { get; set; } | ||
|
||
public Animal() | ||
: base(Guid.NewGuid().ToString()) | ||
{ | ||
TenantId = Guid.Empty; | ||
Firstname = string.Empty; | ||
Lastname = string.Empty; | ||
PrivateNote = string.Empty; | ||
} | ||
|
||
public static Faker<Animal> Faker | ||
{ | ||
get | ||
{ | ||
return new Faker<Animal>() | ||
.RuleFor(x => x.CreatedAt, f => f.Date.Past().Clone()) | ||
.RuleFor(x => x.UpdatedAt, f => f.Date.Past().Clone()) | ||
.RuleFor(x => x.TenantId, f => f.Random.Guid()) | ||
.RuleFor(x => x.Firstname, f => f.Name.FirstName()) | ||
.RuleFor(x => x.Lastname, f => f.Name.LastName()); | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...dPrimaryKey/Repositories/AnimalEntity/ComposedPrimaryKeyDatabaseRepositoryTestBase.Get.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System.Threading.Tasks; | ||
using FluentAssertions; | ||
using Wemogy.Infrastructure.Database.Core.UnitTests.Fakes.Entities; | ||
using Xunit; | ||
|
||
namespace Wemogy.Infrastructure.Database.Core.UnitTests.Plugins.ComposedPrimaryKey.Repositories.AnimalEntity; | ||
|
||
public abstract partial class ComposedPrimaryKeyDatabaseRepositoryTestBase | ||
{ | ||
[Fact] | ||
public async Task GetAsync_ShouldRespectComposedKey() | ||
{ | ||
// Arrange | ||
var animal = Animal.Faker.Generate(); | ||
var prefix = "tenantA"; | ||
SetPrefixContext(prefix); | ||
await AnimalRepository.CreateAsync(animal); | ||
|
||
// Act | ||
var animalFromDb = await AnimalRepository.GetAsync( | ||
animal.Id, | ||
animal.TenantId); | ||
|
||
// Assert | ||
animalFromDb.Should().BeEquivalentTo(animal); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...posedPrimaryKey/Repositories/AnimalEntity/ComposedPrimaryKeyDatabaseRepositoryTestBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Wemogy.Infrastructure.Database.Core.Factories; | ||
using Wemogy.Infrastructure.Database.Core.UnitTests.DatabaseRepositories; | ||
using Wemogy.Infrastructure.Database.Core.UnitTests.Plugins.ComposedPrimaryKey.TestingData.Models; | ||
|
||
namespace Wemogy.Infrastructure.Database.Core.UnitTests.Plugins.ComposedPrimaryKey.Repositories.AnimalEntity; | ||
|
||
public abstract partial class ComposedPrimaryKeyDatabaseRepositoryTestBase : IDisposable | ||
{ | ||
private readonly IServiceCollection _serviceCollection; | ||
private IAnimalRepository AnimalRepository => _serviceCollection.BuildServiceProvider().GetRequiredService<IAnimalRepository>(); | ||
|
||
protected ComposedPrimaryKeyDatabaseRepositoryTestBase(Action<IServiceCollection> addRepositoryAction) | ||
{ | ||
_serviceCollection = new ServiceCollection(); | ||
_serviceCollection.AddScoped<StringPrefixComposedPrimaryKeyBuilder>(); | ||
addRepositoryAction(_serviceCollection); | ||
DatabaseRepositoryFactoryFactory.DatabaseClientProxy = null; | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
// Cleanup | ||
// AnimalRepository.DeleteAsync(x => true).Wait(); | ||
} | ||
|
||
private void SetPrefixContext(string prefix) | ||
{ | ||
_serviceCollection.AddSingleton(new PrefixContext(prefix)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...ts/Plugins/ComposedPrimaryKey/TestingData/Models/StringPrefixComposedPrimaryKeyBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System; | ||
using Wemogy.Core.Extensions; | ||
using Wemogy.Infrastructure.Database.Core.Plugins.ComposedPrimaryKey.Abstractions; | ||
|
||
namespace Wemogy.Infrastructure.Database.Core.UnitTests.Plugins.ComposedPrimaryKey.TestingData.Models; | ||
|
||
public class StringPrefixComposedPrimaryKeyBuilder : IComposedPrimaryKeyBuilder<string> | ||
{ | ||
private readonly PrefixContext _prefixContext; | ||
|
||
public StringPrefixComposedPrimaryKeyBuilder(PrefixContext prefixContext) | ||
{ | ||
_prefixContext = prefixContext; | ||
} | ||
|
||
public string GetComposedPrimaryKeyPrefix() | ||
{ | ||
return $"{_prefixContext.Prefix}_"; | ||
} | ||
|
||
public string BuildComposedPrimaryKey(string id) | ||
{ | ||
return $"{_prefixContext.Prefix}_{id}"; | ||
} | ||
|
||
public string ExtractIdFromComposedPrimaryKey(string composedPrimaryKey) | ||
{ | ||
return composedPrimaryKey.SplitOnFirstOccurrence("_")[1]; | ||
} | ||
} |
1 change: 0 additions & 1 deletion
1
...Infrastructure.Database.Core.UnitTests/Repositories/RepositoryTestBase.PropertyFilters.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 0 additions & 3 deletions
3
src/core/Wemogy.Infrastructure.Database.Core.UnitTests/Repositories/RepositoryTestBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.