Skip to content

Commit

Permalink
Merge pull request #105 from wemogy/fix/mongodb-issues
Browse files Browse the repository at this point in the history
Fix/mongodb issues
  • Loading branch information
SebastianKuesters committed Jul 19, 2023
2 parents 39dd089 + 50a5e1c commit 23dffd0
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,26 @@ await MicrosoftUserRepository.DeleteAsync(
userExistsAfterDeletion.Should().BeFalse();
}

[Fact]
public async Task DeleteAsyncWithIdOnlyShouldWork()
{
// Arrange
var user = User.Faker.Generate();
await MicrosoftUserRepository.CreateAsync(user);

// Act
var userExistsBeforeDeletion = await MicrosoftUserRepository.ExistsAsync(
user.Id);
await MicrosoftUserRepository.DeleteAsync(
user.Id);
var userExistsAfterDeletion = await MicrosoftUserRepository.ExistsAsync(
user.Id);

// Assert
userExistsBeforeDeletion.Should().BeTrue();
userExistsAfterDeletion.Should().BeFalse();
}

[Fact]
public async Task DeleteAsyncShouldThrowForNonExistingEntities()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public partial class DatabaseRepository<TEntity>
{
public Task DeleteAsync(string id)
{
return _database.DeleteAsync(x => id == x.Id.ToString());
return _database.DeleteAsync(x => id == x.Id);
}

public Task DeleteAsync(string id, string partitionKey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public async Task<TEntity> GetAsync(string id, CancellationToken cancellationTok
try
{
return await GetAsync(
x => x.Id.ToString() == id,
x => x.Id == id,
cancellationToken);
}
catch (NotFoundErrorException)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Microsoft.Extensions.Logging;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Conventions;
using MongoDB.Driver;
using MongoDB.Driver.Core.Events;
using Wemogy.Infrastructure.Database.Core.Abstractions;
using Wemogy.Infrastructure.Database.Core.Models;
using Wemogy.Infrastructure.Database.Mongo.Client;
Expand All @@ -24,7 +26,7 @@ public MongoDatabaseClientFactory(
var pack = new ConventionPack { new CamelCaseElementNameConvention() };
ConventionRegistry.Register(nameof(CamelCaseElementNameConvention), pack, x => true);

_mongoClient = new MongoClient(connectionString);
var settings = MongoClientSettings.FromConnectionString(connectionString);

if (enableLogging)
{
Expand All @@ -33,7 +35,20 @@ public MongoDatabaseClientFactory(
builder.AddConsole();
});
_logger = loggerFactory.CreateLogger(nameof(MongoDatabaseClientFactory));

settings.ClusterConfigurator = cb =>
{
cb.Subscribe<CommandStartedEvent>(e =>
{
_logger.LogInformation(
"{CommandName} - {Json}",
e.CommandName,
e.Command.ToJson());
});
};
}

_mongoClient = new MongoClient(settings);
}

public IDatabaseClient<TEntity> CreateClient<TEntity>(DatabaseRepositoryOptions databaseRepositoryOptions)
Expand Down

0 comments on commit 23dffd0

Please sign in to comment.