Skip to content

Commit

Permalink
Integration & Unit Tests Update
Browse files Browse the repository at this point in the history
  • Loading branch information
mqsrr committed Nov 18, 2023
1 parent d3624e4 commit 8e8876f
Show file tree
Hide file tree
Showing 47 changed files with 11,528 additions and 673 deletions.
56 changes: 21 additions & 35 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,99 +9,85 @@ on:
jobs:
OrderingApi:
runs-on: ubuntu-latest
strategy:
matrix:
dotnet-version: ['7.0.x']

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup .NET ${{ matrix.dotnet-version }}
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ matrix.dotnet-version }}
dotnet-version: '7.0.x'

- name: Unit Tests
run: dotnet test "tests/Unit Tests/CoffeeSpace.OrderingApi.Tests" --verbosity normal
run: dotnet test "tests/Unit Tests/CoffeeSpace.OrderingApi.Tests"

- name: Integration Tests
run: dotnet test "tests/Integration Tests/CoffeeSpace.OrderingApi.Tests.Integration" --verbosity normal
run: dotnet test "tests/Integration Tests/CoffeeSpace.OrderingApi.Tests.Integration"

ProductsApi:
runs-on: ubuntu-latest
strategy:
matrix:
dotnet-version: ['7.0.x']

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup .NET ${{ matrix.dotnet-version }}
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ matrix.dotnet-version }}
dotnet-version: '7.0.x'

- name: Unit Tests
run: dotnet test "tests/Unit Tests/CoffeeSpace.ProductApi.Tests" --verbosity normal
run: dotnet test "tests/Unit Tests/CoffeeSpace.ProductApi.Tests"

- name: Integration Tests
run: dotnet test "tests/Integration Tests/CoffeeSpace.ProductApi.Tests.Integration" --verbosity normal
run: dotnet test "tests/Integration Tests/CoffeeSpace.ProductApi.Tests.Integration"

IdentityApi:
runs-on: ubuntu-latest
strategy:
matrix:
dotnet-version: ['7.0.x']


steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup .NET ${{ matrix.dotnet-version }}
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ matrix.dotnet-version }}
dotnet-version: '7.0.x'

- name: Unit Tests
run: dotnet test "tests/Unit Tests/CoffeeSpace.IdentityApi.Tests" --verbosity normal
run: dotnet test "tests/Unit Tests/CoffeeSpace.IdentityApi.Tests"

- name: Integration Tests
run: dotnet test "tests/Integration Tests/CoffeeSpace.IdentityApi.Tests.Integration" --verbosity normal
run: dotnet test "tests/Integration Tests/CoffeeSpace.IdentityApi.Tests.Integration"

PaymentService:
runs-on: ubuntu-latest
strategy:
matrix:
dotnet-version: ['7.0.x']


steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup .NET ${{ matrix.dotnet-version }}
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ matrix.dotnet-version }}

dotnet-version: '7.0.x'
- name: Unit Tests
run: dotnet test "tests/Unit Tests/CoffeeSpace.PaymentService.Tests" --verbosity normal
run: dotnet test "tests/Unit Tests/CoffeeSpace.PaymentService.Tests"

ShipmentService:
runs-on: ubuntu-latest
strategy:
matrix:
dotnet-version: ['7.0.x']

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup .NET ${{ matrix.dotnet-version }}
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ matrix.dotnet-version }}
dotnet-version: '7.0.x'

- name: Unit Tests
run: dotnet test "tests/Unit Tests/CoffeeSpace.ShipmentService.Tests" --verbosity normal
run: dotnet test "tests/Unit Tests/CoffeeSpace.ShipmentService.Tests"
24 changes: 8 additions & 16 deletions CoffeeSpace.Core/Extensions/SerilogExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,22 @@
using System.Reflection;
using Microsoft.Extensions.Hosting;
using Microsoft.IdentityModel.Tokens;
using Serilog;
using Serilog.Events;
using Serilog.Sinks.Datadog.Logs;

namespace CoffeeSpace.Core.Extensions;

public static class SerilogExtensions
{
public static LoggerConfiguration AddDatadogLogging(this LoggerConfiguration loggerConfiguration)
{
string solutionName = AppDomain.CurrentDomain.FriendlyName;
loggerConfiguration.WriteTo.DatadogLogs(Environment.GetEnvironmentVariable("DD_API_KEY"),
service: solutionName,
host: "CoffeeSpace",
configuration: new DatadogConfiguration(" https://http-intake.logs.us5.datadoghq.com", 443));

return loggerConfiguration;
}

public static LoggerConfiguration AddDatadogLogging(this LoggerConfiguration loggerConfiguration, string serviceName)
{
loggerConfiguration.WriteTo.DatadogLogs(Environment.GetEnvironmentVariable("DD_API_KEY"),
if (!Environment.GetEnvironmentVariable(Environments.Staging).IsNullOrEmpty())
{
return loggerConfiguration;
}

return loggerConfiguration.WriteTo.DatadogLogs(Environment.GetEnvironmentVariable("DD_API_KEY"),
service: serviceName,
host: "CoffeeSpace",
configuration: new DatadogConfiguration(" https://http-intake.logs.us5.datadoghq.com", 443));

return loggerConfiguration;
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using CoffeeSpace.Domain.Ordering.BuyerInfo;
using CoffeeSpace.OrderingApi.Application.Repositories.Abstractions;
using CoffeeSpace.OrderingApi.Persistence;
using CoffeeSpace.OrderingApi.Persistence.Abstractions;
using Microsoft.EntityFrameworkCore;

namespace CoffeeSpace.OrderingApi.Application.Repositories;

internal sealed class BuyerRepository : IBuyerRepository
{
private readonly OrderingDbContext _orderingDbContext;
private readonly IOrderingDbContext _orderingDbContext;

public BuyerRepository(OrderingDbContext orderingDbContext)
public BuyerRepository(IOrderingDbContext orderingDbContext)
{
_orderingDbContext = orderingDbContext;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using CoffeeSpace.Domain.Ordering.Orders;
using CoffeeSpace.OrderingApi.Application.Repositories.Abstractions;
using CoffeeSpace.OrderingApi.Persistence;
using CoffeeSpace.OrderingApi.Persistence.Abstractions;
using Microsoft.EntityFrameworkCore;

namespace CoffeeSpace.OrderingApi.Application.Repositories;

internal sealed class OrderRepository : IOrderRepository
{
private readonly OrderingDbContext _orderingDbContext;
private readonly IOrderingDbContext _orderingDbContext;

public OrderRepository(OrderingDbContext orderingDbContext)
public OrderRepository(IOrderingDbContext orderingDbContext)
{
_orderingDbContext = orderingDbContext;
}
Expand Down
30 changes: 18 additions & 12 deletions CoffeeSpace.OrderingApi/Application/Services/BuyerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,17 @@ public async Task<bool> CreateAsync(Buyer buyer, CancellationToken cancellationT
public async Task<Buyer?> UpdateAsync(Buyer buyer, CancellationToken cancellationToken)
{
var updatedBuyer = await _buyerRepository.UpdateAsync(buyer, cancellationToken);
if (updatedBuyer is not null)
if (updatedBuyer is null)
{
await _sendEndpointProvider.Send<UpdateBuyer>(new
{
Buyer = updatedBuyer
}, cancellationToken).ConfigureAwait(false);
return null;
}

var sendEndpoint = await _sendEndpointProvider.GetSendEndpoint(new Uri("queue:update-buyer"));
await sendEndpoint.Send<UpdateBuyer>(new
{
Buyer = updatedBuyer
}, cancellationToken).ConfigureAwait(false);

return updatedBuyer;
}

Expand All @@ -58,15 +61,18 @@ public async Task<bool> DeleteByIdAsync(Guid id, CancellationToken cancellationT
}

bool isDeleted = await _buyerRepository.DeleteByIdAsync(id.ToString(), cancellationToken);
if (isDeleted)
if (!isDeleted)
{
await _sendEndpointProvider.Send<DeleteBuyer>(new
{
buyerToDelete.Name,
buyerToDelete.Email
}, cancellationToken).ConfigureAwait(false);
return false;
}


var sendEndpoint = await _sendEndpointProvider.GetSendEndpoint(new Uri("queue:delete-buyer"));
await sendEndpoint.Send<DeleteBuyer>(new
{
buyerToDelete.Name,
buyerToDelete.Email
}, cancellationToken).ConfigureAwait(false);

return isDeleted;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using CoffeeSpace.Domain.Ordering.BuyerInfo;
using CoffeeSpace.Domain.Ordering.Orders;
using Microsoft.EntityFrameworkCore;

namespace CoffeeSpace.OrderingApi.Persistence.Abstractions;

public interface IOrderingDbContext
{
DbSet<Order> Orders { get; init; }

DbSet<OrderItem> OrderItems { get; init; }

DbSet<Buyer> Buyers { get; init; }

DbSet<Address> Addresses { get; init; }


Task<int> SaveChangesAsync(CancellationToken cancellationToken);
}
3 changes: 2 additions & 1 deletion CoffeeSpace.OrderingApi/Persistence/OrderingDbContext.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using System.Reflection;
using CoffeeSpace.Domain.Ordering.BuyerInfo;
using CoffeeSpace.Domain.Ordering.Orders;
using CoffeeSpace.OrderingApi.Persistence.Abstractions;
using Microsoft.EntityFrameworkCore;

namespace CoffeeSpace.OrderingApi.Persistence;

public sealed class OrderingDbContext : DbContext
public sealed class OrderingDbContext : DbContext, IOrderingDbContext
{
public required DbSet<Order> Orders { get; init; }

Expand Down
3 changes: 2 additions & 1 deletion CoffeeSpace.OrderingApi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using CoffeeSpace.OrderingApi.Application.SignalRHubs;
using CoffeeSpace.OrderingApi.Application.Validators;
using CoffeeSpace.OrderingApi.Persistence;
using CoffeeSpace.OrderingApi.Persistence.Abstractions;
using FluentValidation;
using FluentValidation.AspNetCore;
using MassTransit;
Expand All @@ -36,7 +37,7 @@
builder.Services.AddApiVersioning(new MediaTypeApiVersionReader("api-version"));
builder.Services.AddStackExchangeRedisCache(x => x.Configuration = builder.Configuration["Redis:ConnectionString"]);

builder.Services.AddApplicationDb<OrderingDbContext>(builder.Configuration["OrderingDb:ConnectionString"]!);
builder.Services.AddApplicationDb<IOrderingDbContext, OrderingDbContext>(builder.Configuration["OrderingDb:ConnectionString"]!);
builder.Services.AddApplicationDb<OrderStateSagaDbContext>(builder.Configuration["OrderStateSagaDb:ConnectionString"]!);

builder.Services.AddApplicationService(typeof(ICacheService<>));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using CoffeeSpace.PaymentService.Models;
using Microsoft.EntityFrameworkCore;
using PayPalCheckoutSdk.Orders;

namespace CoffeeSpace.PaymentService.Persistence.Abstractions;

public interface IPaymentDbContext
{
DbSet<PaypalOrderInformation> PaypalOrders { get; init; }

DbSet<Order> Orders { get; init; }

Task<int> SaveChangesAsync(CancellationToken cancellationToken);
}
3 changes: 2 additions & 1 deletion CoffeeSpace.PaymentService/Persistence/PaymentDbContext.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using System.Reflection;
using CoffeeSpace.PaymentService.Models;
using CoffeeSpace.PaymentService.Persistence.Abstractions;
using Microsoft.EntityFrameworkCore;
using PayPalCheckoutSdk.Orders;

namespace CoffeeSpace.PaymentService.Persistence;

internal sealed class PaymentDbContext : DbContext
internal sealed class PaymentDbContext : DbContext, IPaymentDbContext
{
public required DbSet<PaypalOrderInformation> PaypalOrders { get; init; }

Expand Down
3 changes: 2 additions & 1 deletion CoffeeSpace.PaymentService/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using CoffeeSpace.PaymentService.Extensions;
using CoffeeSpace.PaymentService.Messages.PipelineBehaviours;
using CoffeeSpace.PaymentService.Persistence;
using CoffeeSpace.PaymentService.Persistence.Abstractions;
using CoffeeSpace.PaymentService.Repositories.Abstractions;
using CoffeeSpace.PaymentService.Services.Abstractions;
using CoffeeSpace.PaymentService.Settings;
Expand All @@ -24,7 +25,7 @@
.AddDatadogLogging("Payment Service"));

builder.Services.AddStackExchangeRedisCache(options => options.Configuration = builder.Configuration["Redis:ConnectionString"]);
builder.Services.AddApplicationDb<PaymentDbContext>(builder.Configuration["PaymentDb:ConnectionString"]!);
builder.Services.AddApplicationDb<IPaymentDbContext, PaymentDbContext>(builder.Configuration["PaymentDb:ConnectionString"]!);

builder.Services.AddApplicationService<IPaymentRepository>();
builder.Services.AddApplicationService<IPaymentService>();
Expand Down
5 changes: 3 additions & 2 deletions CoffeeSpace.PaymentService/Repositories/PaymentRepository.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
using CoffeeSpace.PaymentService.Models;
using CoffeeSpace.PaymentService.Persistence;
using CoffeeSpace.PaymentService.Persistence.Abstractions;
using CoffeeSpace.PaymentService.Repositories.Abstractions;
using Microsoft.EntityFrameworkCore;

namespace CoffeeSpace.PaymentService.Repositories;

internal sealed class PaymentRepository : IPaymentRepository
{
private readonly PaymentDbContext _dbContext;
private readonly IPaymentDbContext _dbContext;

public PaymentRepository(PaymentDbContext dbContext)
public PaymentRepository(IPaymentDbContext dbContext)
{
_dbContext = dbContext;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using CoffeeSpace.Domain.Products;
using CoffeeSpace.ProductApi.Application.Repositories.Abstractions;
using CoffeeSpace.ProductApi.Persistence;
using CoffeeSpace.ProductApi.Persistence.Abstractions;
using Microsoft.EntityFrameworkCore;

namespace CoffeeSpace.ProductApi.Application.Repositories;

internal sealed class ProductRepository : IProductRepository
{
private readonly ProductDbContext _productDbContext;
private readonly IProductDbContext _productDbContext;

public ProductRepository(ProductDbContext productDbContext)
public ProductRepository(IProductDbContext productDbContext)
{
_productDbContext = productDbContext;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using CoffeeSpace.Domain.Products;
using Microsoft.EntityFrameworkCore;

namespace CoffeeSpace.ProductApi.Persistence.Abstractions;

public interface IProductDbContext
{
DbSet<Product> Products { get; init; }

Task<int> SaveChangesAsync(CancellationToken cancellationToken);
}
Loading

0 comments on commit 8e8876f

Please sign in to comment.