Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using EstateReporting.Database;
using EstateReporting.Database.Entities;
using EstateManagement.Database.Contexts;
using EstateManagement.Database.Entities;
using EventHandling;
using MessagingService.Client;
using Microsoft.EntityFrameworkCore;
Expand All @@ -33,20 +33,20 @@ public enum TestDatabaseType

public class VoucherDomainEventHandlerTests
{
private Mock<Shared.EntityFramework.IDbContextFactory<EstateReportingGenericContext>> GetMockDbContextFactory()
private Mock<Shared.EntityFramework.IDbContextFactory<EstateManagementGenericContext>> GetMockDbContextFactory()
{
return new Mock<Shared.EntityFramework.IDbContextFactory<EstateReportingGenericContext>>();
return new Mock<Shared.EntityFramework.IDbContextFactory<EstateManagementGenericContext>>();
}

private async Task<EstateReportingGenericContext> GetContext(String databaseName, TestDatabaseType databaseType = TestDatabaseType.InMemory)
private async Task<EstateManagementGenericContext> GetContext(String databaseName, TestDatabaseType databaseType = TestDatabaseType.InMemory)
{
EstateReportingGenericContext context = null;
EstateManagementGenericContext context = null;
if (databaseType == TestDatabaseType.InMemory)
{
DbContextOptionsBuilder<EstateReportingGenericContext> builder = new DbContextOptionsBuilder<EstateReportingGenericContext>()
.UseInMemoryDatabase(databaseName)
.ConfigureWarnings(w => w.Ignore(InMemoryEventId.TransactionIgnoredWarning));
context = new EstateReportingSqlServerContext(builder.Options);
DbContextOptionsBuilder<EstateManagementGenericContext> builder = new DbContextOptionsBuilder<EstateManagementGenericContext>()
.UseInMemoryDatabase(databaseName)
.ConfigureWarnings(w => w.Ignore(InMemoryEventId.TransactionIgnoredWarning));
context = new EstateManagementSqlServerContext(builder.Options);
}
else
{
Expand All @@ -70,8 +70,8 @@ public async Task VoucherDomainEventHandler_VoucherIssuedEvent_WithEmailAddress_
voucherAggregateRepository.Setup(t => t.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(TestData.GetVoucherAggregateWithRecipientEmail);

EstateReportingGenericContext context = await this.GetContext(Guid.NewGuid().ToString("N"), TestDatabaseType.InMemory);
context.Transactions.Add(new EstateReporting.Database.Entities.Transaction()
EstateManagementGenericContext context = await this.GetContext(Guid.NewGuid().ToString("N"), TestDatabaseType.InMemory);
context.Transactions.Add(new EstateManagement.Database.Entities.Transaction()
{
TransactionId = TestData.TransactionId,
EstateId = TestData.EstateId,
Expand Down Expand Up @@ -119,8 +119,8 @@ public async Task VoucherDomainEventHandler_VoucherIssuedEvent_WithRecipientMobi
voucherAggregateRepository.Setup(t => t.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(TestData.GetVoucherAggregateWithRecipientMobile);

EstateReportingGenericContext context = await this.GetContext(Guid.NewGuid().ToString("N"), TestDatabaseType.InMemory);
context.Transactions.Add(new EstateReporting.Database.Entities.Transaction()
EstateManagementGenericContext context = await this.GetContext(Guid.NewGuid().ToString("N"), TestDatabaseType.InMemory);
context.Transactions.Add(new EstateManagement.Database.Entities.Transaction()
{
TransactionId = TestData.TransactionId,
EstateId = TestData.EstateId,
Expand All @@ -134,7 +134,7 @@ public async Task VoucherDomainEventHandler_VoucherIssuedEvent_WithRecipientMobi
});
await context.SaveChangesAsync(CancellationToken.None);

var dbContextFactory = this.GetMockDbContextFactory();
Mock<Shared.EntityFramework.IDbContextFactory<EstateManagementGenericContext>> dbContextFactory = this.GetMockDbContextFactory();
dbContextFactory.Setup(d => d.GetContext(It.IsAny<Guid>(), It.IsAny<String>(), It.IsAny<CancellationToken>())).ReturnsAsync(context);

Mock<IMessagingServiceClient> messagingServiceClient = new Mock<IMessagingServiceClient>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
using EstateReporting.Database;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Moq;
using Shared.DomainDrivenDesign.EventSourcing;
using Shared.EventStore.Aggregate;
using Shared.Exceptions;
using Shouldly;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using TransactionProcessor.BusinessLogic.Manager;
Expand All @@ -17,27 +13,29 @@

namespace TransactionProcessor.BusinessLogic.Tests.Manager
{
using EstateReporting.Database.Entities;
using EstateManagement.Database.Contexts;
using EstateManagement.Database.Entities;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Shared.EntityFramework;
using Testing;
using VoucherAggregate;

public class VoucherManagementManagerTests
{
private Mock<Shared.EntityFramework.IDbContextFactory<EstateReportingGenericContext>> GetMockDbContextFactory()
private Mock<Shared.EntityFramework.IDbContextFactory<EstateManagementGenericContext>> GetMockDbContextFactory()
{
return new Mock<Shared.EntityFramework.IDbContextFactory<EstateReportingGenericContext>>();
return new Mock<Shared.EntityFramework.IDbContextFactory<EstateManagementGenericContext>>();
}

private async Task<EstateReportingGenericContext> GetContext(String databaseName, TestDatabaseType databaseType = TestDatabaseType.InMemory)
private async Task<EstateManagementGenericContext> GetContext(String databaseName, TestDatabaseType databaseType = TestDatabaseType.InMemory)
{
EstateReportingGenericContext context = null;
EstateManagementGenericContext context = null;
if (databaseType == TestDatabaseType.InMemory)
{
DbContextOptionsBuilder<EstateReportingGenericContext> builder = new DbContextOptionsBuilder<EstateReportingGenericContext>()
.UseInMemoryDatabase(databaseName)
.ConfigureWarnings(w => w.Ignore(InMemoryEventId.TransactionIgnoredWarning));
context = new EstateReportingSqlServerContext(builder.Options);
DbContextOptionsBuilder<EstateManagementGenericContext> builder = new DbContextOptionsBuilder<EstateManagementGenericContext>()
.UseInMemoryDatabase(databaseName)
.ConfigureWarnings(w => w.Ignore(InMemoryEventId.TransactionIgnoredWarning));
context = new EstateManagementSqlServerContext(builder.Options);
}
else
{
Expand All @@ -50,16 +48,17 @@ private async Task<EstateReportingGenericContext> GetContext(String databaseName
[Fact]
public async Task VoucherManagementManager_GetVoucherByCode_VoucherRetrieved()
{
EstateReportingGenericContext context = await this.GetContext(Guid.NewGuid().ToString("N"), TestDatabaseType.InMemory);
EstateManagementGenericContext context = await this.GetContext(Guid.NewGuid().ToString("N"), TestDatabaseType.InMemory);
await context.Vouchers.AddAsync(new Voucher
{
EstateId = TestData.EstateId,
VoucherId = TestData.VoucherId,
VoucherCode = TestData.VoucherCode
VoucherCode = TestData.VoucherCode,
OperatorIdentifier = TestData.OperatorIdentifier,
});
await context.SaveChangesAsync(CancellationToken.None);

var dbContextFactory = this.GetMockDbContextFactory();
Mock<IDbContextFactory<EstateManagementGenericContext>> dbContextFactory = this.GetMockDbContextFactory();
dbContextFactory.Setup(d => d.GetContext(It.IsAny<Guid>(), It.IsAny<String>(), It.IsAny<CancellationToken>())).ReturnsAsync(context);

Mock<IAggregateRepository<VoucherAggregate, DomainEvent>> voucherAggregateRepository = new Mock<IAggregateRepository<VoucherAggregate, DomainEvent>>();
Expand All @@ -75,11 +74,11 @@ await context.Vouchers.AddAsync(new Voucher
[Fact]
public async Task VoucherManagementManager_GetVoucherByCode_VoucherNotFound_ErrorThrown()
{
EstateReportingGenericContext context = await this.GetContext(Guid.NewGuid().ToString("N"), TestDatabaseType.InMemory);
EstateManagementGenericContext context = await this.GetContext(Guid.NewGuid().ToString("N"), TestDatabaseType.InMemory);

await context.SaveChangesAsync(CancellationToken.None);

var dbContextFactory = this.GetMockDbContextFactory();
Mock<IDbContextFactory<EstateManagementGenericContext>> dbContextFactory = this.GetMockDbContextFactory();
dbContextFactory.Setup(d => d.GetContext(It.IsAny<Guid>(), It.IsAny<String>(), It.IsAny<CancellationToken>())).ReturnsAsync(context);

Mock<IAggregateRepository<VoucherAggregate, DomainEvent>> voucherAggregateRepository = new Mock<IAggregateRepository<VoucherAggregate, DomainEvent>>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using BusinessLogic.Services;
using DomainEventHandlers;
using EstateManagement.Client;
using EstateReporting.Database;
using EstateManagement.Database.Contexts;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.Extensions.Configuration;
Expand All @@ -23,7 +23,6 @@
using Testing;
using VoucherAggregate;
using Xunit;
using Voucher = EstateReporting.Database.Entities.Voucher;

public class VoucherDomainServiceTests
{
Expand All @@ -44,7 +43,7 @@ public async Task VoucherDomainService_IssueVoucher_EstateWithEmptyOperators_Err
estateClient.Setup(e => e.GetEstate(It.IsAny<String>(), It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(TestData.GetEstateResponseWithEmptyOperators);

EstateReportingGenericContext context = await this.GetContext(Guid.NewGuid().ToString("N"));
EstateManagementGenericContext context = await this.GetContext(Guid.NewGuid().ToString("N"));

var dbContextFactory = this.GetMockDbContextFactory();
dbContextFactory.Setup(d => d.GetContext(It.IsAny<Guid>(), It.IsAny<String>(), It.IsAny<CancellationToken>())).ReturnsAsync(context);
Expand Down Expand Up @@ -82,7 +81,7 @@ public async Task VoucherDomainService_IssueVoucher_EstateWithNullOperators_Erro
estateClient.Setup(e => e.GetEstate(It.IsAny<String>(), It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(TestData.GetEstateResponseWithNullOperators);

EstateReportingGenericContext context = await this.GetContext(Guid.NewGuid().ToString("N"));
EstateManagementGenericContext context = await this.GetContext(Guid.NewGuid().ToString("N"));

var dbContextFactory = this.GetMockDbContextFactory();
dbContextFactory.Setup(d => d.GetContext(It.IsAny<Guid>(), It.IsAny<String>(), It.IsAny<CancellationToken>())).ReturnsAsync(context);
Expand Down Expand Up @@ -120,7 +119,7 @@ public async Task VoucherDomainService_IssueVoucher_InvalidEstate_ErrorThrown()
estateClient.Setup(e => e.GetEstate(It.IsAny<String>(), It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
.ThrowsAsync(new Exception("Exception", new KeyNotFoundException("Invalid Estate")));

EstateReportingGenericContext context = await this.GetContext(Guid.NewGuid().ToString("N"));
EstateManagementGenericContext context = await this.GetContext(Guid.NewGuid().ToString("N"));

var dbContextFactory = this.GetMockDbContextFactory();
dbContextFactory.Setup(d => d.GetContext(It.IsAny<Guid>(), It.IsAny<String>(), It.IsAny<CancellationToken>())).ReturnsAsync(context);
Expand Down Expand Up @@ -158,7 +157,7 @@ public async Task VoucherDomainService_IssueVoucher_OperatorNotSupportedByEstate
estateClient.Setup(e => e.GetEstate(It.IsAny<String>(), It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(TestData.GetEstateResponseWithOperator2);

EstateReportingGenericContext context = await this.GetContext(Guid.NewGuid().ToString("N"));
EstateManagementGenericContext context = await this.GetContext(Guid.NewGuid().ToString("N"));

var dbContextFactory = this.GetMockDbContextFactory();
dbContextFactory.Setup(d => d.GetContext(It.IsAny<Guid>(), It.IsAny<String>(), It.IsAny<CancellationToken>())).ReturnsAsync(context);
Expand Down Expand Up @@ -196,7 +195,7 @@ public async Task VoucherDomainService_IssueVoucher_VoucherIssued() {
estateClient.Setup(e => e.GetEstate(It.IsAny<String>(), It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(TestData.GetEstateResponseWithOperator1);

EstateReportingGenericContext context = await this.GetContext(Guid.NewGuid().ToString("N"));
EstateManagementGenericContext context = await this.GetContext(Guid.NewGuid().ToString("N"));

var dbContextFactory = this.GetMockDbContextFactory();
dbContextFactory.Setup(d => d.GetContext(It.IsAny<Guid>(), It.IsAny<String>(), It.IsAny<CancellationToken>())).ReturnsAsync(context);
Expand Down Expand Up @@ -235,10 +234,11 @@ public async Task VoucherDomainService_RedeemVoucher_InvalidEstate_ErrorThrown()
estateClient.Setup(e => e.GetEstate(It.IsAny<String>(), It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
.ThrowsAsync(new Exception("Exception", new KeyNotFoundException("Invalid Estate")));

EstateReportingGenericContext context = await this.GetContext(Guid.NewGuid().ToString("N"));
context.Vouchers.Add(new Voucher {
EstateManagementGenericContext context = await this.GetContext(Guid.NewGuid().ToString("N"));
context.Vouchers.Add(new EstateManagement.Database.Entities.Voucher {
VoucherCode = TestData.VoucherCode,
EstateId = TestData.EstateId
EstateId = TestData.EstateId,
OperatorIdentifier = TestData.OperatorIdentifier
});
await context.SaveChangesAsync();
var dbContextFactory = this.GetMockDbContextFactory();
Expand Down Expand Up @@ -273,10 +273,11 @@ public async Task VoucherDomainService_RedeemVoucher_VoucherIssued() {
estateClient.Setup(e => e.GetEstate(It.IsAny<String>(), It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(TestData.GetEstateResponseWithOperator1);

EstateReportingGenericContext context = await this.GetContext(Guid.NewGuid().ToString("N"));
context.Vouchers.Add(new Voucher {
EstateManagementGenericContext context = await this.GetContext(Guid.NewGuid().ToString("N"));
context.Vouchers.Add(new EstateManagement.Database.Entities.Voucher {
VoucherCode = TestData.VoucherCode,
EstateId = TestData.EstateId
EstateId = TestData.EstateId,
OperatorIdentifier = TestData.OperatorIdentifier
});
await context.SaveChangesAsync();
var dbContextFactory = this.GetMockDbContextFactory();
Expand Down Expand Up @@ -311,7 +312,7 @@ public async Task VoucherDomainService_RedeemVoucher_VoucherNotFound_ErrorThrown
estateClient.Setup(e => e.GetEstate(It.IsAny<String>(), It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(TestData.GetEstateResponseWithOperator1);

EstateReportingGenericContext context = await this.GetContext(Guid.NewGuid().ToString("N"));
EstateManagementGenericContext context = await this.GetContext(Guid.NewGuid().ToString("N"));
var dbContextFactory = this.GetMockDbContextFactory();
dbContextFactory.Setup(d => d.GetContext(It.IsAny<Guid>(), It.IsAny<String>(), It.IsAny<CancellationToken>())).ReturnsAsync(context);

Expand All @@ -328,14 +329,14 @@ await domainService.RedeemVoucher(TestData.EstateId,
});
}

private async Task<EstateReportingGenericContext> GetContext(String databaseName,
TestDatabaseType databaseType = TestDatabaseType.InMemory) {
EstateReportingGenericContext context = null;
private async Task<EstateManagementGenericContext> GetContext(String databaseName,
TestDatabaseType databaseType = TestDatabaseType.InMemory) {
EstateManagementGenericContext context = null;
if (databaseType == TestDatabaseType.InMemory) {
DbContextOptionsBuilder<EstateReportingGenericContext> builder = new DbContextOptionsBuilder<EstateReportingGenericContext>()
.UseInMemoryDatabase(databaseName)
.ConfigureWarnings(w => w.Ignore(InMemoryEventId.TransactionIgnoredWarning));
context = new EstateReportingSqlServerContext(builder.Options);
DbContextOptionsBuilder<EstateManagementGenericContext> builder = new DbContextOptionsBuilder<EstateManagementGenericContext>()
.UseInMemoryDatabase(databaseName)
.ConfigureWarnings(w => w.Ignore(InMemoryEventId.TransactionIgnoredWarning));
context = new EstateManagementSqlServerContext(builder.Options);
}
else {
throw new NotSupportedException($"Database type [{databaseType}] not supported");
Expand All @@ -344,8 +345,8 @@ private async Task<EstateReportingGenericContext> GetContext(String databaseName
return context;
}

private Mock<Shared.EntityFramework.IDbContextFactory<EstateReportingGenericContext>> GetMockDbContextFactory() {
return new Mock<Shared.EntityFramework.IDbContextFactory<EstateReportingGenericContext>>();
private Mock<Shared.EntityFramework.IDbContextFactory<EstateManagementGenericContext>> GetMockDbContextFactory() {
return new Mock<Shared.EntityFramework.IDbContextFactory<EstateManagementGenericContext>>();
}

#endregion
Expand Down
Loading