├── CulDeSacApi ├── Brokers │ ├── Events │ │ ├── IEventBroker.cs │ │ ├── EventBroker.cs │ │ ├── IEventBroker.Students.cs │ │ └── EventBroker.Students.cs │ ├── Queues │ │ ├── IQueueBroker.cs │ │ ├── IQueueBroker.Students.cs │ │ ├── QueueBroker.Students.cs │ │ └── QueueBroker.cs │ └── Storages │ │ ├── IStorageBroker.cs │ │ ├── IStorageBroker.Students.cs │ │ ├── IStorageBroker.LibraryCards.cs │ │ ├── IStorageBroker.LibraryAccounts.cs │ │ ├── StorageBroker.LibraryAccounts.References.cs │ │ ├── StorageBroker.LibraryCards.References.cs │ │ ├── StorageBroker.Students.cs │ │ ├── StorageBroker.LibraryCards.cs │ │ ├── StorageBroker.LibraryAccounts.cs │ │ └── StorageBroker.cs ├── appsettings.json ├── Services │ ├── Foundations │ │ ├── Students │ │ │ ├── IStudentService.cs │ │ │ └── StudentService.cs │ │ ├── LibraryCards │ │ │ ├── ILibraryCardService.cs │ │ │ └── LibraryCardService.cs │ │ ├── StudentEvents │ │ │ ├── IStudentEventService.cs │ │ │ └── StudentEventService.cs │ │ ├── LibraryAccounts │ │ │ ├── ILibraryAccountService.cs │ │ │ └── LibraryAccountService.cs │ │ └── LocalStudentEvents │ │ │ ├── ILocalStudentEventService.cs │ │ │ └── LocalStudentEventService.cs │ └── Orchestrations │ │ ├── StudentEvents │ │ ├── IStudentEventOrchestrationService.cs │ │ └── StudentEventOrchestrationService.cs │ │ └── LibraryAccounts │ │ ├── ILibraryAccountOrchestrationService.cs │ │ └── LibraryAccountOrchestrationService.cs ├── Models │ ├── LibraryCards │ │ └── LibraryCard.cs │ ├── Students │ │ └── Student.cs │ └── LibraryAccounts │ │ └── LibraryAccount.cs ├── appsettings.Development.json ├── Program.cs ├── Controllers │ └── StudentsController.cs ├── Properties │ └── launchSettings.json ├── Migrations │ ├── 20220123160022_AddStudentModel.cs │ ├── 20220123160022_AddStudentModel.Designer.cs │ ├── 20220221021659_AddLibraryCard.cs │ ├── 20220221015024_AddLibraryAccount.cs │ ├── 20220221015024_AddLibraryAccount.Designer.cs │ ├── StorageBrokerModelSnapshot.cs │ └── 20220221021659_AddLibraryCard.Designer.cs ├── CulDeSacApi.csproj └── Startup.cs ├── CulDeSacApi.Tests.Unit ├── Services │ ├── Foundations │ │ ├── Students │ │ │ ├── StudentServiceTests.cs │ │ │ └── StudentServiceTests.Logic.Add.cs │ │ ├── LocalStudentEvents │ │ │ ├── LocalStudentEventServiceTests.Logic.Publish.cs │ │ │ ├── LocalStudentEventServiceTests.Logic.Listen.cs │ │ │ └── LocalStudentEventServiceTests.cs │ │ ├── LibraryCards │ │ │ ├── LibraryCardServiceTests.cs │ │ │ └── LibraryCardServiceTests.Logic.Add.cs │ │ ├── LibraryAccounts │ │ │ ├── LibraryAccountServiceTests.cs │ │ │ └── LibraryAccountServiceTests.Logic.Add.cs │ │ └── StudentEvents │ │ │ ├── StudentEventServiceTests.Logic.Listen.cs │ │ │ └── StudentEventServiceTests.cs │ └── Orchestrations │ │ ├── StudentEvents │ │ ├── StudentEventOrchestrationServiceTests.cs │ │ └── StudentEventOrchestrationServiceTests.Logic.Listen.cs │ │ └── LibraryAccounts │ │ ├── LibraryAccountOrchestrationServiceTests.cs │ │ └── LibraryAccountOrchestrationServiceTests.Logic.Create.cs └── CulDeSacApi.Tests.Unit.csproj ├── CulDeSacDemoApi.sln ├── .gitattributes └── .gitignore /CulDeSacApi/Brokers/Events/IEventBroker.cs: -------------------------------------------------------------------------------- 1 | namespace CulDeSacApi.Brokers.Events 2 | { 3 | public partial interface IEventBroker 4 | { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /CulDeSacApi/Brokers/Queues/IQueueBroker.cs: -------------------------------------------------------------------------------- 1 | namespace CulDeSacApi.Brokers.Queues 2 | { 3 | public partial interface IQueueBroker 4 | { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /CulDeSacApi/Brokers/Events/EventBroker.cs: -------------------------------------------------------------------------------- 1 | namespace CulDeSacApi.Brokers.Events 2 | { 3 | public partial class EventBroker : IEventBroker 4 | { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /CulDeSacApi/Brokers/Storages/IStorageBroker.cs: -------------------------------------------------------------------------------- 1 | namespace CulDeSacApi.Brokers.Storages 2 | { 3 | public partial interface IStorageBroker 4 | { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /CulDeSacApi/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | }, 9 | "AllowedHosts": "*" 10 | } 11 | -------------------------------------------------------------------------------- /CulDeSacApi/Brokers/Storages/IStorageBroker.Students.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using CulDeSacApi.Models.Students; 3 | 4 | namespace CulDeSacApi.Brokers.Storages 5 | { 6 | public partial interface IStorageBroker 7 | { 8 | ValueTask InsertStudentAsync(Student student); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /CulDeSacApi/Services/Foundations/Students/IStudentService.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using CulDeSacApi.Models.Students; 3 | 4 | namespace CulDeSacApi.Services.Foundations.Students 5 | { 6 | public interface IStudentService 7 | { 8 | ValueTask AddStudentAsync(Student student); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /CulDeSacApi/Brokers/Storages/IStorageBroker.LibraryCards.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using CulDeSacApi.Models.LibraryCards; 3 | 4 | namespace CulDeSacApi.Brokers.Storages 5 | { 6 | public partial interface IStorageBroker 7 | { 8 | ValueTask InsertLibraryCardAsync(LibraryCard libraryCard); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /CulDeSacApi/Brokers/Storages/IStorageBroker.LibraryAccounts.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using CulDeSacApi.Models.LibraryAccounts; 3 | 4 | namespace CulDeSacApi.Brokers.Storages 5 | { 6 | public partial interface IStorageBroker 7 | { 8 | ValueTask InsertLibraryAccountAsync(LibraryAccount libraryAccount); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /CulDeSacApi/Services/Foundations/LibraryCards/ILibraryCardService.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using CulDeSacApi.Models.LibraryCards; 3 | 4 | namespace CulDeSacApi.Services.Foundations.LibraryCards 5 | { 6 | public interface ILibraryCardService 7 | { 8 | ValueTask AddLibraryCardAsync(LibraryCard libraryCard); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /CulDeSacApi/Services/Orchestrations/StudentEvents/IStudentEventOrchestrationService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | using CulDeSacApi.Models.Students; 4 | 5 | namespace CulDeSacApi.Services.Orchestrations.StudentEvents 6 | { 7 | public interface IStudentEventOrchestrationService 8 | { 9 | void ListenToStudentEvents(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /CulDeSacApi/Brokers/Queues/IQueueBroker.Students.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | using System.Threading.Tasks; 4 | using Microsoft.Azure.ServiceBus; 5 | 6 | namespace CulDeSacApi.Brokers.Queues 7 | { 8 | public partial interface IQueueBroker 9 | { 10 | void ListenToStudentsQueue(Func eventHandler); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /CulDeSacApi/Services/Foundations/StudentEvents/IStudentEventService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | using CulDeSacApi.Models.Students; 4 | 5 | namespace CulDeSacApi.Services.Foundations.StudentEvents 6 | { 7 | public interface IStudentEventService 8 | { 9 | void ListenToStudentEvent(Func studentEventHandler); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /CulDeSacApi/Models/LibraryCards/LibraryCard.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using CulDeSacApi.Models.LibraryAccounts; 3 | 4 | namespace CulDeSacApi.Models.LibraryCards 5 | { 6 | public class LibraryCard 7 | { 8 | public Guid Id { get; set; } 9 | 10 | public Guid LibraryAccountId { get; set; } 11 | public LibraryAccount LibraryAccount { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /CulDeSacApi/Services/Foundations/LibraryAccounts/ILibraryAccountService.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using CulDeSacApi.Models.LibraryAccounts; 3 | 4 | namespace CulDeSacApi.Services.Foundations.LibraryAccounts 5 | { 6 | public interface ILibraryAccountService 7 | { 8 | ValueTask AddLibraryAccountAsync(LibraryAccount libraryAccount); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /CulDeSacApi/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "ConnectionStrings": { 3 | "DefaultConnection": "Server=(localdb)\\MSSQLLocalDB;Database=CulDeSacDB;Trusted_Connection=True;MultipleActiveResultSets=true", 4 | "ServiceBusConnection": "Endpoint=sb://culdesacbus.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=evIwMuf1/aEeFd1KPk5Apeh9w3jViAydUZkMxa+Qt/o=" 5 | } 6 | } -------------------------------------------------------------------------------- /CulDeSacApi/Brokers/Events/IEventBroker.Students.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | using CulDeSacApi.Models.Students; 4 | 5 | namespace CulDeSacApi.Brokers.Events 6 | { 7 | public partial interface IEventBroker 8 | { 9 | void ListenToStudentEvent(Func> studentEventHandler); 10 | ValueTask PublishStudentEventAsync(Student student); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /CulDeSacApi/Models/Students/Student.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using CulDeSacApi.Models.LibraryAccounts; 5 | 6 | namespace CulDeSacApi.Models.Students 7 | { 8 | public class Student 9 | { 10 | public Guid Id { get; set; } 11 | public string Name { get; set; } 12 | 13 | public LibraryAccount LibraryAccount { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /CulDeSacApi/Services/Orchestrations/LibraryAccounts/ILibraryAccountOrchestrationService.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using CulDeSacApi.Models.LibraryAccounts; 3 | 4 | namespace CulDeSacApi.Services.Orchestrations.LibraryAccounts 5 | { 6 | public interface ILibraryAccountOrchestrationService 7 | { 8 | ValueTask CreateLibraryAccountAsync(LibraryAccount libraryAccount); 9 | void ListenToLocalStudentEvent(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /CulDeSacApi/Services/Foundations/LocalStudentEvents/ILocalStudentEventService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | using CulDeSacApi.Models.Students; 4 | 5 | namespace CulDeSacApi.Services.Foundations.LocalStudentEvents 6 | { 7 | public interface ILocalStudentEventService 8 | { 9 | void ListenToStudentEvent(Func> studentEventHandler); 10 | ValueTask PublishStudentAsync(Student student); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /CulDeSacApi/Models/LibraryAccounts/LibraryAccount.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using CulDeSacApi.Models.LibraryCards; 4 | using CulDeSacApi.Models.Students; 5 | 6 | namespace CulDeSacApi.Models.LibraryAccounts 7 | { 8 | public class LibraryAccount 9 | { 10 | public Guid Id { get; set; } 11 | 12 | public Guid StudentId { get; set; } 13 | public Student Student { get; set; } 14 | 15 | public IEnumerable LibraryCards { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /CulDeSacApi/Brokers/Storages/StorageBroker.LibraryAccounts.References.cs: -------------------------------------------------------------------------------- 1 | using CulDeSacApi.Models.LibraryAccounts; 2 | using Microsoft.EntityFrameworkCore; 3 | 4 | namespace CulDeSacApi.Brokers.Storages 5 | { 6 | public partial class StorageBroker 7 | { 8 | private static void AddLibraryAccountsReferences(ModelBuilder modelBuilder) 9 | { 10 | modelBuilder.Entity() 11 | .HasOne(libraryAccount => libraryAccount.Student) 12 | .WithOne(student => student.LibraryAccount) 13 | .OnDelete(DeleteBehavior.NoAction); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /CulDeSacApi/Brokers/Events/EventBroker.Students.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | using CulDeSacApi.Models.Students; 4 | 5 | namespace CulDeSacApi.Brokers.Events 6 | { 7 | public partial class EventBroker 8 | { 9 | private static Func> StudentEventHandler; 10 | 11 | public void ListenToStudentEvent(Func> studentEventHandler) => 12 | StudentEventHandler = studentEventHandler; 13 | 14 | public async ValueTask PublishStudentEventAsync(Student student) => 15 | await StudentEventHandler(student); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /CulDeSacApi/Services/Foundations/Students/StudentService.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using CulDeSacApi.Brokers.Storages; 3 | using CulDeSacApi.Models.Students; 4 | 5 | namespace CulDeSacApi.Services.Foundations.Students 6 | { 7 | public class StudentService : IStudentService 8 | { 9 | private readonly IStorageBroker storageBroker; 10 | 11 | public StudentService(IStorageBroker storageBroker) => 12 | this.storageBroker = storageBroker; 13 | 14 | public async ValueTask AddStudentAsync(Student student) => 15 | await this.storageBroker.InsertStudentAsync(student); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /CulDeSacApi/Brokers/Storages/StorageBroker.LibraryCards.References.cs: -------------------------------------------------------------------------------- 1 | using CulDeSacApi.Models.LibraryCards; 2 | using Microsoft.EntityFrameworkCore; 3 | 4 | namespace CulDeSacApi.Brokers.Storages 5 | { 6 | public partial class StorageBroker 7 | { 8 | private static void AddLibraryCardsReferences(ModelBuilder modelBuilder) 9 | { 10 | modelBuilder.Entity() 11 | .HasOne(libraryCard => libraryCard.LibraryAccount) 12 | .WithMany(account => account.LibraryCards) 13 | .HasForeignKey(libraryCard => libraryCard.LibraryAccountId) 14 | .OnDelete(DeleteBehavior.NoAction); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /CulDeSacApi/Services/Foundations/LibraryCards/LibraryCardService.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using CulDeSacApi.Brokers.Storages; 3 | using CulDeSacApi.Models.LibraryCards; 4 | 5 | namespace CulDeSacApi.Services.Foundations.LibraryCards 6 | { 7 | public class LibraryCardService : ILibraryCardService 8 | { 9 | private readonly IStorageBroker storageBroker; 10 | 11 | public LibraryCardService(IStorageBroker storageBroker) => 12 | this.storageBroker = storageBroker; 13 | 14 | public async ValueTask AddLibraryCardAsync(LibraryCard libraryCard) => 15 | await this.storageBroker.InsertLibraryCardAsync(libraryCard); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /CulDeSacApi/Services/Foundations/LibraryAccounts/LibraryAccountService.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using CulDeSacApi.Brokers.Storages; 3 | using CulDeSacApi.Models.LibraryAccounts; 4 | 5 | namespace CulDeSacApi.Services.Foundations.LibraryAccounts 6 | { 7 | public class LibraryAccountService : ILibraryAccountService 8 | { 9 | private readonly IStorageBroker storageBroker; 10 | 11 | public LibraryAccountService(IStorageBroker storageBroker) => 12 | this.storageBroker = storageBroker; 13 | 14 | public async ValueTask AddLibraryAccountAsync(LibraryAccount libraryAccount) => 15 | await this.storageBroker.InsertLibraryAccountAsync(libraryAccount); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /CulDeSacApi/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Hosting; 6 | using Microsoft.Extensions.Configuration; 7 | using Microsoft.Extensions.Hosting; 8 | using Microsoft.Extensions.Logging; 9 | 10 | namespace CulDeSacApi 11 | { 12 | public class Program 13 | { 14 | public static void Main(string[] args) 15 | { 16 | CreateHostBuilder(args).Build().Run(); 17 | } 18 | 19 | public static IHostBuilder CreateHostBuilder(string[] args) => 20 | Host.CreateDefaultBuilder(args) 21 | .ConfigureWebHostDefaults(webBuilder => 22 | { 23 | webBuilder.UseStartup(); 24 | }); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /CulDeSacApi/Brokers/Storages/StorageBroker.Students.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using CulDeSacApi.Models.Students; 3 | using Microsoft.EntityFrameworkCore; 4 | using Microsoft.EntityFrameworkCore.ChangeTracking; 5 | 6 | namespace CulDeSacApi.Brokers.Storages 7 | { 8 | public partial class StorageBroker 9 | { 10 | public DbSet Students { get; set; } 11 | 12 | public async ValueTask InsertStudentAsync(Student student) 13 | { 14 | using var broker = new StorageBroker(this.configuration); 15 | 16 | EntityEntry studentEntityEntry = 17 | await broker.Students.AddAsync(student); 18 | 19 | await broker.SaveChangesAsync(); 20 | 21 | return studentEntityEntry.Entity; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /CulDeSacApi/Brokers/Storages/StorageBroker.LibraryCards.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using CulDeSacApi.Models.LibraryCards; 3 | using Microsoft.EntityFrameworkCore; 4 | using Microsoft.EntityFrameworkCore.ChangeTracking; 5 | 6 | namespace CulDeSacApi.Brokers.Storages 7 | { 8 | public partial class StorageBroker 9 | { 10 | public DbSet LibraryCards { get; set; } 11 | 12 | public async ValueTask InsertLibraryCardAsync(LibraryCard libraryCard) 13 | { 14 | using var broker = new StorageBroker(this.configuration); 15 | 16 | EntityEntry libraryCardEntityEntry = 17 | await broker.LibraryCards.AddAsync(libraryCard); 18 | 19 | await broker.SaveChangesAsync(); 20 | 21 | return libraryCardEntityEntry.Entity; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /CulDeSacApi/Services/Foundations/LocalStudentEvents/LocalStudentEventService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | using CulDeSacApi.Brokers.Events; 4 | using CulDeSacApi.Models.Students; 5 | 6 | namespace CulDeSacApi.Services.Foundations.LocalStudentEvents 7 | { 8 | public class LocalStudentEventService : ILocalStudentEventService 9 | { 10 | private readonly IEventBroker eventBroker; 11 | 12 | public LocalStudentEventService(IEventBroker eventBroker) => 13 | this.eventBroker = eventBroker; 14 | 15 | public void ListenToStudentEvent(Func> studentEventHandler) => 16 | this.eventBroker.ListenToStudentEvent(studentEventHandler); 17 | 18 | public async ValueTask PublishStudentAsync(Student student) => 19 | await this.eventBroker.PublishStudentEventAsync(student); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /CulDeSacApi/Brokers/Storages/StorageBroker.LibraryAccounts.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using CulDeSacApi.Models.LibraryAccounts; 3 | using Microsoft.EntityFrameworkCore; 4 | using Microsoft.EntityFrameworkCore.ChangeTracking; 5 | 6 | namespace CulDeSacApi.Brokers.Storages 7 | { 8 | public partial class StorageBroker 9 | { 10 | public DbSet LibraryAccounts { get; set; } 11 | 12 | public async ValueTask InsertLibraryAccountAsync(LibraryAccount libraryAccount) 13 | { 14 | using var broker = new StorageBroker(this.configuration); 15 | 16 | EntityEntry libraryAccountEntityEntry = 17 | await broker.LibraryAccounts.AddAsync(libraryAccount); 18 | 19 | await broker.SaveChangesAsync(); 20 | 21 | return libraryAccountEntityEntry.Entity; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /CulDeSacApi/Controllers/StudentsController.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using CulDeSacApi.Models.Students; 3 | using CulDeSacApi.Services.Foundations.Students; 4 | using Microsoft.AspNetCore.Mvc; 5 | using RESTFulSense.Controllers; 6 | 7 | namespace CulDeSacApi.Controllers 8 | { 9 | [ApiController] 10 | [Route("api/[controller]")] 11 | public class StudentsController : RESTFulController 12 | { 13 | private readonly IStudentService studentService; 14 | 15 | public StudentsController(IStudentService studentService) => 16 | this.studentService = studentService; 17 | 18 | [HttpPost] 19 | public async ValueTask> PostStudentAsync(Student student) 20 | { 21 | Student addedStudent = await this.studentService.AddStudentAsync(student); 22 | 23 | return Created(addedStudent); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /CulDeSacApi/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:42688", 8 | "sslPort": 44363 9 | } 10 | }, 11 | "profiles": { 12 | "IIS Express": { 13 | "commandName": "IISExpress", 14 | "launchBrowser": true, 15 | "launchUrl": "swagger", 16 | "environmentVariables": { 17 | "ASPNETCORE_ENVIRONMENT": "Development" 18 | } 19 | }, 20 | "CulDeSacApi": { 21 | "commandName": "Project", 22 | "dotnetRunMessages": "true", 23 | "launchBrowser": true, 24 | "launchUrl": "swagger", 25 | "applicationUrl": "https://localhost:5001;http://localhost:5000", 26 | "environmentVariables": { 27 | "ASPNETCORE_ENVIRONMENT": "Development" 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /CulDeSacApi.Tests.Unit/Services/Foundations/Students/StudentServiceTests.cs: -------------------------------------------------------------------------------- 1 | using CulDeSacApi.Brokers.Storages; 2 | using CulDeSacApi.Models.Students; 3 | using CulDeSacApi.Services.Foundations.Students; 4 | using Moq; 5 | using Tynamix.ObjectFiller; 6 | 7 | namespace CulDeSacApi.Tests.Unit.Services.Foundations.Students 8 | { 9 | public partial class StudentServiceTests 10 | { 11 | private readonly Mock storageBrokerMock; 12 | private readonly IStudentService studentService; 13 | 14 | public StudentServiceTests() 15 | { 16 | this.storageBrokerMock = new Mock(); 17 | 18 | this.studentService = new StudentService( 19 | storageBroker: this.storageBrokerMock.Object); 20 | } 21 | 22 | private static Student CreateRandomStudent() => 23 | CreateStudentFiller().Create(); 24 | 25 | private static Filler CreateStudentFiller() => 26 | new Filler(); 27 | } 28 | } -------------------------------------------------------------------------------- /CulDeSacApi.Tests.Unit/Services/Foundations/LocalStudentEvents/LocalStudentEventServiceTests.Logic.Publish.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using CulDeSacApi.Models.Students; 3 | using FluentAssertions; 4 | using Force.DeepCloner; 5 | using Moq; 6 | using Xunit; 7 | 8 | namespace CulDeSacApi.Tests.Unit.Services.Foundations.LocalStudentEvents 9 | { 10 | public partial class LocalStudentEventServiceTests 11 | { 12 | [Fact] 13 | public async Task ShouldPublishStudentAsync() 14 | { 15 | // given 16 | Student randomStudent = CreateRandomStudent(); 17 | Student inputStudent = randomStudent; 18 | 19 | // when 20 | await this.localStudentEventService 21 | .PublishStudentAsync(inputStudent); 22 | 23 | // then 24 | this.eventBrokerMock.Verify(broker => 25 | broker.PublishStudentEventAsync(inputStudent), 26 | Times.Once); 27 | 28 | this.eventBrokerMock.VerifyNoOtherCalls(); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /CulDeSacApi.Tests.Unit/Services/Foundations/LocalStudentEvents/LocalStudentEventServiceTests.Logic.Listen.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | using CulDeSacApi.Models.Students; 4 | using Moq; 5 | using Xunit; 6 | 7 | namespace CulDeSacApi.Tests.Unit.Services.Foundations.LocalStudentEvents 8 | { 9 | public partial class LocalStudentEventServiceTests 10 | { 11 | [Fact] 12 | public void ShouldListenToStudentEvent() 13 | { 14 | // given 15 | var studentEventHandlerMock = 16 | new Mock>>(); 17 | 18 | // when 19 | this.localStudentEventService.ListenToStudentEvent( 20 | studentEventHandlerMock.Object); 21 | 22 | // then 23 | this.eventBrokerMock.Verify(broker => 24 | broker.ListenToStudentEvent( 25 | studentEventHandlerMock.Object), 26 | Times.Once); 27 | 28 | this.eventBrokerMock.VerifyNoOtherCalls(); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /CulDeSacApi/Migrations/20220123160022_AddStudentModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.EntityFrameworkCore.Migrations; 3 | 4 | #nullable disable 5 | 6 | namespace CulDeSacApi.Migrations 7 | { 8 | public partial class AddStudentModel : Migration 9 | { 10 | protected override void Up(MigrationBuilder migrationBuilder) 11 | { 12 | migrationBuilder.CreateTable( 13 | name: "Students", 14 | columns: table => new 15 | { 16 | Id = table.Column(type: "uniqueidentifier", nullable: false), 17 | Name = table.Column(type: "nvarchar(max)", nullable: true) 18 | }, 19 | constraints: table => 20 | { 21 | table.PrimaryKey("PK_Students", x => x.Id); 22 | }); 23 | } 24 | 25 | protected override void Down(MigrationBuilder migrationBuilder) 26 | { 27 | migrationBuilder.DropTable( 28 | name: "Students"); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /CulDeSacApi.Tests.Unit/Services/Foundations/LibraryCards/LibraryCardServiceTests.cs: -------------------------------------------------------------------------------- 1 | using CulDeSacApi.Brokers.Storages; 2 | using CulDeSacApi.Models.LibraryCards; 3 | using CulDeSacApi.Services.Foundations.LibraryCards; 4 | using Moq; 5 | using Tynamix.ObjectFiller; 6 | 7 | namespace CulDeSacApi.Tests.Unit.Services.Foundations.LibraryCards 8 | { 9 | public partial class LibraryCardServiceTests 10 | { 11 | private readonly Mock storageBrokerMock; 12 | private readonly ILibraryCardService libraryCardService; 13 | 14 | public LibraryCardServiceTests() 15 | { 16 | this.storageBrokerMock = new Mock(); 17 | 18 | this.libraryCardService = new LibraryCardService( 19 | storageBroker: storageBrokerMock.Object); 20 | } 21 | 22 | private static LibraryCard CreateRandomLibraryAcocunt() => 23 | CreateLibraryCardFiller().Create(); 24 | 25 | private static Filler CreateLibraryCardFiller() => 26 | new Filler(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /CulDeSacApi/Brokers/Storages/StorageBroker.cs: -------------------------------------------------------------------------------- 1 | using EFxceptions; 2 | using Microsoft.EntityFrameworkCore; 3 | using Microsoft.Extensions.Configuration; 4 | 5 | namespace CulDeSacApi.Brokers.Storages 6 | { 7 | public partial class StorageBroker : EFxceptionsContext, IStorageBroker 8 | { 9 | private readonly IConfiguration configuration; 10 | 11 | public StorageBroker(IConfiguration configuration) 12 | { 13 | this.configuration = configuration; 14 | this.Database.Migrate(); 15 | } 16 | 17 | protected override void OnModelCreating(ModelBuilder modelBuilder) 18 | { 19 | AddLibraryAccountsReferences(modelBuilder); 20 | AddLibraryCardsReferences(modelBuilder); 21 | } 22 | 23 | protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) 24 | { 25 | string connectionString = 26 | this.configuration.GetConnectionString("DefaultConnection"); 27 | 28 | optionsBuilder.UseSqlServer(connectionString); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /CulDeSacApi.Tests.Unit/Services/Foundations/LocalStudentEvents/LocalStudentEventServiceTests.cs: -------------------------------------------------------------------------------- 1 | using CulDeSacApi.Brokers.Events; 2 | using CulDeSacApi.Models.Students; 3 | using CulDeSacApi.Services.Foundations.LocalStudentEvents; 4 | using Moq; 5 | using Tynamix.ObjectFiller; 6 | 7 | namespace CulDeSacApi.Tests.Unit.Services.Foundations.LocalStudentEvents 8 | { 9 | 10 | public partial class LocalStudentEventServiceTests 11 | { 12 | private readonly Mock eventBrokerMock; 13 | private readonly ILocalStudentEventService localStudentEventService; 14 | 15 | public LocalStudentEventServiceTests() 16 | { 17 | this.eventBrokerMock = new Mock(); 18 | 19 | this.localStudentEventService = new LocalStudentEventService( 20 | eventBroker: this.eventBrokerMock.Object); 21 | } 22 | 23 | private static Student CreateRandomStudent() => 24 | CreateStudentFiller().Create(); 25 | 26 | private static Filler CreateStudentFiller() => 27 | new Filler(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /CulDeSacApi.Tests.Unit/Services/Foundations/LibraryAccounts/LibraryAccountServiceTests.cs: -------------------------------------------------------------------------------- 1 | using CulDeSacApi.Brokers.Storages; 2 | using CulDeSacApi.Models.LibraryAccounts; 3 | using CulDeSacApi.Services.Foundations.LibraryAccounts; 4 | using Moq; 5 | using Tynamix.ObjectFiller; 6 | 7 | namespace CulDeSacApi.Tests.Unit.Services.Foundations.LibraryAccounts 8 | { 9 | public partial class LibraryAccountServiceTests 10 | { 11 | private readonly Mock storageBrokerMock; 12 | private readonly ILibraryAccountService libraryAccountService; 13 | 14 | public LibraryAccountServiceTests() 15 | { 16 | this.storageBrokerMock = new Mock(); 17 | 18 | this.libraryAccountService = new LibraryAccountService( 19 | storageBroker: storageBrokerMock.Object); 20 | } 21 | 22 | private static LibraryAccount CreateRandomLibraryAcocunt() => 23 | CreateLibraryAccountFiller().Create(); 24 | 25 | private static Filler CreateLibraryAccountFiller() => 26 | new Filler(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /CulDeSacApi/CulDeSacApi.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | all 12 | runtime; build; native; contentfiles; analyzers; buildtransitive 13 | 14 | 15 | 16 | all 17 | runtime; build; native; contentfiles; analyzers; buildtransitive 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /CulDeSacApi/Brokers/Queues/QueueBroker.Students.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | using System.Threading.Tasks; 4 | using Microsoft.Azure.ServiceBus; 5 | 6 | namespace CulDeSacApi.Brokers.Queues 7 | { 8 | public partial class QueueBroker 9 | { 10 | public IQueueClient StudentsQueue { get; set; } 11 | 12 | public void ListenToStudentsQueue(Func eventHandler) 13 | { 14 | MessageHandlerOptions messageHandlerOptions = GetMessageHandlerOptions(); 15 | 16 | Func messageEventHasndler = 17 | CompleteStudentsQueueMessageAsync(eventHandler); 18 | 19 | this.StudentsQueue.RegisterMessageHandler(messageEventHasndler, messageHandlerOptions); 20 | } 21 | 22 | private Func CompleteStudentsQueueMessageAsync( 23 | Func handler) 24 | { 25 | return async (message, token) => 26 | { 27 | await handler(message, token); 28 | await this.StudentsQueue.CompleteAsync(message.SystemProperties.LockToken); 29 | }; 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /CulDeSacApi/Services/Foundations/StudentEvents/StudentEventService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using System.Threading.Tasks; 4 | using CulDeSacApi.Brokers.Queues; 5 | using CulDeSacApi.Models.Students; 6 | using Microsoft.Azure.ServiceBus; 7 | using Newtonsoft.Json; 8 | 9 | namespace CulDeSacApi.Services.Foundations.StudentEvents 10 | { 11 | public partial class StudentEventService : IStudentEventService 12 | { 13 | private readonly IQueueBroker queueBroker; 14 | 15 | public StudentEventService(IQueueBroker queueBroker) => 16 | this.queueBroker = queueBroker; 17 | 18 | public void ListenToStudentEvent(Func studentEventHandler) 19 | { 20 | this.queueBroker.ListenToStudentsQueue(async (message, token) => 21 | { 22 | Student incomingStudent = MapToStudent(message); 23 | await studentEventHandler(incomingStudent); 24 | }); 25 | } 26 | 27 | private static Student MapToStudent(Message message) 28 | { 29 | string serializedStudent = 30 | Encoding.UTF8.GetString(message.Body); 31 | 32 | return JsonConvert.DeserializeObject(serializedStudent); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /CulDeSacApi.Tests.Unit/Services/Foundations/Students/StudentServiceTests.Logic.Add.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using CulDeSacApi.Models.Students; 3 | using FluentAssertions; 4 | using Force.DeepCloner; 5 | using Moq; 6 | using Xunit; 7 | 8 | namespace CulDeSacApi.Tests.Unit.Services.Foundations.Students 9 | { 10 | public partial class StudentServiceTests 11 | { 12 | [Fact] 13 | public async Task ShouldAddStudentAsync() 14 | { 15 | // given 16 | Student randomStudent = CreateRandomStudent(); 17 | Student inputStudent = randomStudent; 18 | Student insertedStudent = inputStudent; 19 | Student expectedStudent = insertedStudent.DeepClone(); 20 | 21 | this.storageBrokerMock.Setup(broker => 22 | broker.InsertStudentAsync(inputStudent)) 23 | .ReturnsAsync(insertedStudent); 24 | 25 | // when 26 | Student actualStudent = await this.studentService 27 | .AddStudentAsync(inputStudent); 28 | 29 | // then 30 | actualStudent.Should().BeEquivalentTo(expectedStudent); 31 | 32 | this.storageBrokerMock.Verify(broker => 33 | broker.InsertStudentAsync(inputStudent), 34 | Times.Once); 35 | 36 | this.storageBrokerMock.VerifyNoOtherCalls(); 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /CulDeSacApi.Tests.Unit/CulDeSacApi.Tests.Unit.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | enable 6 | 7 | false 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | runtime; build; native; contentfiles; analyzers; buildtransitive 20 | all 21 | 22 | 23 | runtime; build; native; contentfiles; analyzers; buildtransitive 24 | all 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /CulDeSacApi/Services/Orchestrations/StudentEvents/StudentEventOrchestrationService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | using CulDeSacApi.Models.Students; 4 | using CulDeSacApi.Services.Foundations.LocalStudentEvents; 5 | using CulDeSacApi.Services.Foundations.StudentEvents; 6 | using CulDeSacApi.Services.Foundations.Students; 7 | 8 | namespace CulDeSacApi.Services.Orchestrations.StudentEvents 9 | { 10 | public class StudentEventOrchestrationService : IStudentEventOrchestrationService 11 | { 12 | private readonly IStudentEventService studentEventService; 13 | private readonly IStudentService studentService; 14 | private readonly ILocalStudentEventService localStudentEventService; 15 | 16 | public StudentEventOrchestrationService( 17 | IStudentEventService studentEventService, 18 | IStudentService studentService, 19 | ILocalStudentEventService localStudentEventService) 20 | { 21 | this.studentEventService = studentEventService; 22 | this.studentService = studentService; 23 | this.localStudentEventService = localStudentEventService; 24 | } 25 | 26 | public void ListenToStudentEvents() 27 | { 28 | this.studentEventService.ListenToStudentEvent(async (student) => 29 | { 30 | await this.studentService.AddStudentAsync(student); 31 | await this.localStudentEventService.PublishStudentAsync(student); 32 | }); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /CulDeSacApi/Brokers/Queues/QueueBroker.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using Microsoft.Azure.ServiceBus; 3 | using Microsoft.Extensions.Configuration; 4 | 5 | namespace CulDeSacApi.Brokers.Queues 6 | { 7 | public partial class QueueBroker : IQueueBroker 8 | { 9 | private readonly IConfiguration configuration; 10 | 11 | public QueueBroker(IConfiguration configuration) 12 | { 13 | this.configuration = configuration; 14 | InitializeQueueClients(); 15 | } 16 | 17 | private void InitializeQueueClients() => 18 | this.StudentsQueue = GetQueueClient(nameof(this.StudentsQueue)); 19 | 20 | private IQueueClient GetQueueClient(string queueName) 21 | { 22 | string connectionString = 23 | this.configuration.GetConnectionString("ServiceBusConnection"); 24 | 25 | return new QueueClient(connectionString, queueName); 26 | } 27 | 28 | private MessageHandlerOptions GetMessageHandlerOptions() 29 | { 30 | return new MessageHandlerOptions(ExceptionReceivedHandler) 31 | { 32 | AutoComplete = false, 33 | MaxConcurrentCalls = 1 34 | }; 35 | } 36 | 37 | private Task ExceptionReceivedHandler(ExceptionReceivedEventArgs exceptionReceivedEventArgs) 38 | { 39 | ExceptionReceivedContext context = exceptionReceivedEventArgs.ExceptionReceivedContext; 40 | 41 | return Task.CompletedTask; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /CulDeSacApi/Migrations/20220123160022_AddStudentModel.Designer.cs: -------------------------------------------------------------------------------- 1 | // 2 | using System; 3 | using CulDeSacApi.Brokers.Storages; 4 | using Microsoft.EntityFrameworkCore; 5 | using Microsoft.EntityFrameworkCore.Infrastructure; 6 | using Microsoft.EntityFrameworkCore.Metadata; 7 | using Microsoft.EntityFrameworkCore.Migrations; 8 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 9 | 10 | #nullable disable 11 | 12 | namespace CulDeSacApi.Migrations 13 | { 14 | [DbContext(typeof(StorageBroker))] 15 | [Migration("20220123160022_AddStudentModel")] 16 | partial class AddStudentModel 17 | { 18 | protected override void BuildTargetModel(ModelBuilder modelBuilder) 19 | { 20 | #pragma warning disable 612, 618 21 | modelBuilder 22 | .HasAnnotation("ProductVersion", "6.0.1") 23 | .HasAnnotation("Relational:MaxIdentifierLength", 128); 24 | 25 | SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1); 26 | 27 | modelBuilder.Entity("CulDeSacApi.Models.Students.Student", b => 28 | { 29 | b.Property("Id") 30 | .ValueGeneratedOnAdd() 31 | .HasColumnType("uniqueidentifier"); 32 | 33 | b.Property("Name") 34 | .HasColumnType("nvarchar(max)"); 35 | 36 | b.HasKey("Id"); 37 | 38 | b.ToTable("Students"); 39 | }); 40 | #pragma warning restore 612, 618 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /CulDeSacApi/Migrations/20220221021659_AddLibraryCard.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.EntityFrameworkCore.Migrations; 3 | 4 | #nullable disable 5 | 6 | namespace CulDeSacApi.Migrations 7 | { 8 | public partial class AddLibraryCard : Migration 9 | { 10 | protected override void Up(MigrationBuilder migrationBuilder) 11 | { 12 | migrationBuilder.CreateTable( 13 | name: "LibraryCards", 14 | columns: table => new 15 | { 16 | Id = table.Column(type: "uniqueidentifier", nullable: false), 17 | LibraryAccountId = table.Column(type: "uniqueidentifier", nullable: false) 18 | }, 19 | constraints: table => 20 | { 21 | table.PrimaryKey("PK_LibraryCards", x => x.Id); 22 | table.ForeignKey( 23 | name: "FK_LibraryCards_LibraryAccounts_LibraryAccountId", 24 | column: x => x.LibraryAccountId, 25 | principalTable: "LibraryAccounts", 26 | principalColumn: "Id"); 27 | }); 28 | 29 | migrationBuilder.CreateIndex( 30 | name: "IX_LibraryCards_LibraryAccountId", 31 | table: "LibraryCards", 32 | column: "LibraryAccountId"); 33 | } 34 | 35 | protected override void Down(MigrationBuilder migrationBuilder) 36 | { 37 | migrationBuilder.DropTable( 38 | name: "LibraryCards"); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /CulDeSacApi/Migrations/20220221015024_AddLibraryAccount.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.EntityFrameworkCore.Migrations; 3 | 4 | #nullable disable 5 | 6 | namespace CulDeSacApi.Migrations 7 | { 8 | public partial class AddLibraryAccount : Migration 9 | { 10 | protected override void Up(MigrationBuilder migrationBuilder) 11 | { 12 | migrationBuilder.CreateTable( 13 | name: "LibraryAccounts", 14 | columns: table => new 15 | { 16 | Id = table.Column(type: "uniqueidentifier", nullable: false), 17 | StudentId = table.Column(type: "uniqueidentifier", nullable: false) 18 | }, 19 | constraints: table => 20 | { 21 | table.PrimaryKey("PK_LibraryAccounts", x => x.Id); 22 | table.ForeignKey( 23 | name: "FK_LibraryAccounts_Students_StudentId", 24 | column: x => x.StudentId, 25 | principalTable: "Students", 26 | principalColumn: "Id"); 27 | }); 28 | 29 | migrationBuilder.CreateIndex( 30 | name: "IX_LibraryAccounts_StudentId", 31 | table: "LibraryAccounts", 32 | column: "StudentId", 33 | unique: true); 34 | } 35 | 36 | protected override void Down(MigrationBuilder migrationBuilder) 37 | { 38 | migrationBuilder.DropTable( 39 | name: "LibraryAccounts"); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /CulDeSacApi.Tests.Unit/Services/Foundations/LibraryCards/LibraryCardServiceTests.Logic.Add.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using CulDeSacApi.Models.LibraryCards; 3 | using FluentAssertions; 4 | using Force.DeepCloner; 5 | using Moq; 6 | using Xunit; 7 | 8 | namespace CulDeSacApi.Tests.Unit.Services.Foundations.LibraryCards 9 | { 10 | public partial class LibraryCardServiceTests 11 | { 12 | [Fact] 13 | public async Task ShouldAddLibraryCardAsync() 14 | { 15 | // given 16 | LibraryCard randomLibraryCard = 17 | CreateRandomLibraryAcocunt(); 18 | 19 | LibraryCard inputLibraryCard = 20 | randomLibraryCard; 21 | 22 | LibraryCard insertedLibraryCard = 23 | inputLibraryCard; 24 | 25 | LibraryCard expectedLibraryCard = 26 | insertedLibraryCard.DeepClone(); 27 | 28 | this.storageBrokerMock.Setup(broker => 29 | broker.InsertLibraryCardAsync(inputLibraryCard)) 30 | .ReturnsAsync(insertedLibraryCard); 31 | 32 | // when 33 | LibraryCard actualLibraryCard = 34 | await this.libraryCardService.AddLibraryCardAsync( 35 | inputLibraryCard); 36 | 37 | // then 38 | actualLibraryCard.Should().BeEquivalentTo(actualLibraryCard); 39 | 40 | this.storageBrokerMock.Verify(broker => 41 | broker.InsertLibraryCardAsync(inputLibraryCard), 42 | Times.Once()); 43 | 44 | this.storageBrokerMock.VerifyNoOtherCalls(); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /CulDeSacApi.Tests.Unit/Services/Foundations/LibraryAccounts/LibraryAccountServiceTests.Logic.Add.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using CulDeSacApi.Models.LibraryAccounts; 3 | using FluentAssertions; 4 | using Force.DeepCloner; 5 | using Moq; 6 | using Xunit; 7 | 8 | namespace CulDeSacApi.Tests.Unit.Services.Foundations.LibraryAccounts 9 | { 10 | public partial class LibraryAccountServiceTests 11 | { 12 | [Fact] 13 | public async Task ShouldAddLibraryAccountAsync() 14 | { 15 | // given 16 | LibraryAccount randomLibraryAccount = 17 | CreateRandomLibraryAcocunt(); 18 | 19 | LibraryAccount inputLibraryAccount = 20 | randomLibraryAccount; 21 | 22 | LibraryAccount insertedLibraryAccount = 23 | inputLibraryAccount; 24 | 25 | LibraryAccount expectedLibraryAccount = 26 | insertedLibraryAccount.DeepClone(); 27 | 28 | this.storageBrokerMock.Setup(broker => 29 | broker.InsertLibraryAccountAsync(inputLibraryAccount)) 30 | .ReturnsAsync(insertedLibraryAccount); 31 | 32 | // when 33 | LibraryAccount actualLibraryAccount = 34 | await this.libraryAccountService.AddLibraryAccountAsync( 35 | inputLibraryAccount); 36 | 37 | // then 38 | actualLibraryAccount.Should().BeEquivalentTo(expectedLibraryAccount); 39 | 40 | this.storageBrokerMock.Verify(broker => 41 | broker.InsertLibraryAccountAsync(inputLibraryAccount), 42 | Times.Once()); 43 | 44 | this.storageBrokerMock.VerifyNoOtherCalls(); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /CulDeSacDemoApi.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.0.32112.339 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CulDeSacApi", "CulDeSacApi\CulDeSacApi.csproj", "{40EA868B-B1E8-437B-B9E7-44305982323D}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CulDeSacApi.Tests.Unit", "CulDeSacApi.Tests.Unit\CulDeSacApi.Tests.Unit.csproj", "{0E8A2011-E928-4E15-956E-BFE44FE73AB4}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {40EA868B-B1E8-437B-B9E7-44305982323D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {40EA868B-B1E8-437B-B9E7-44305982323D}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {40EA868B-B1E8-437B-B9E7-44305982323D}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {40EA868B-B1E8-437B-B9E7-44305982323D}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {0E8A2011-E928-4E15-956E-BFE44FE73AB4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {0E8A2011-E928-4E15-956E-BFE44FE73AB4}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {0E8A2011-E928-4E15-956E-BFE44FE73AB4}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {0E8A2011-E928-4E15-956E-BFE44FE73AB4}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {0F716299-BCEA-4693-A6F7-94CFF2640DED} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /CulDeSacApi.Tests.Unit/Services/Orchestrations/StudentEvents/StudentEventOrchestrationServiceTests.cs: -------------------------------------------------------------------------------- 1 | using CulDeSacApi.Models.Students; 2 | using CulDeSacApi.Services.Foundations.LocalStudentEvents; 3 | using CulDeSacApi.Services.Foundations.StudentEvents; 4 | using CulDeSacApi.Services.Foundations.Students; 5 | using CulDeSacApi.Services.Orchestrations.StudentEvents; 6 | using Moq; 7 | using Tynamix.ObjectFiller; 8 | 9 | namespace CulDeSacApi.Tests.Unit.Services.Orchestrations.StudentEvents 10 | { 11 | public partial class StudentEventOrchestrationServiceTests 12 | { 13 | private readonly Mock studentEventServiceMock; 14 | private readonly Mock studentServiceMock; 15 | private readonly Mock localStudentEventService; 16 | private readonly IStudentEventOrchestrationService studentEventOrchestrationService; 17 | 18 | public StudentEventOrchestrationServiceTests() 19 | { 20 | this.studentEventServiceMock = new Mock(); 21 | this.studentServiceMock = new Mock(MockBehavior.Strict); 22 | this.localStudentEventService = new Mock(MockBehavior.Strict); 23 | 24 | this.studentEventOrchestrationService = new StudentEventOrchestrationService( 25 | studentEventService: this.studentEventServiceMock.Object, 26 | studentService: this.studentServiceMock.Object, 27 | localStudentEventService: this.localStudentEventService.Object); 28 | } 29 | 30 | private static Student CreateRandomStudent() => 31 | CreateStudentFiller().Create(); 32 | 33 | private static Filler CreateStudentFiller() => 34 | new Filler(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /CulDeSacApi.Tests.Unit/Services/Foundations/StudentEvents/StudentEventServiceTests.Logic.Listen.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | using System.Threading.Tasks; 4 | using CulDeSacApi.Models.Students; 5 | using Microsoft.Azure.ServiceBus; 6 | using Moq; 7 | using Xunit; 8 | 9 | namespace CulDeSacApi.Tests.Unit.Services.Foundations.StudentEvents 10 | { 11 | public partial class StudentEventServiceTests 12 | { 13 | [Fact] 14 | public void ShouldListenToStudentEvent() 15 | { 16 | // given 17 | var studentEventHandlerMock = 18 | new Mock>(); 19 | 20 | Student randomStudent = CreateRandomStudent(); 21 | Student incomingStudent = randomStudent; 22 | 23 | Message studentMessage = 24 | CreateStudentMessage(incomingStudent); 25 | 26 | this.queueBrokerMock.Setup(broker => 27 | broker.ListenToStudentsQueue( 28 | It.IsAny>())) 29 | .Callback>(eventFunction => 30 | eventFunction.Invoke(studentMessage, It.IsAny())); 31 | 32 | // when 33 | studentEventService.ListenToStudentEvent( 34 | studentEventHandler: studentEventHandlerMock.Object); 35 | 36 | // then 37 | studentEventHandlerMock.Verify(handler => 38 | handler.Invoke(It.Is(SameStudentAs(incomingStudent))), 39 | Times.Once()); 40 | 41 | this.queueBrokerMock.Verify(broker => 42 | broker.ListenToStudentsQueue( 43 | It.IsAny>()), 44 | Times.Once()); 45 | 46 | this.queueBrokerMock.VerifyNoOtherCalls(); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /CulDeSacApi.Tests.Unit/Services/Foundations/StudentEvents/StudentEventServiceTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq.Expressions; 3 | using System.Text; 4 | using CulDeSacApi.Brokers.Queues; 5 | using CulDeSacApi.Models.Students; 6 | using CulDeSacApi.Services.Foundations.StudentEvents; 7 | using KellermanSoftware.CompareNetObjects; 8 | using Microsoft.Azure.ServiceBus; 9 | using Moq; 10 | using Newtonsoft.Json; 11 | using Tynamix.ObjectFiller; 12 | 13 | namespace CulDeSacApi.Tests.Unit.Services.Foundations.StudentEvents 14 | { 15 | public partial class StudentEventServiceTests 16 | { 17 | private readonly Mock queueBrokerMock; 18 | private readonly IStudentEventService studentEventService; 19 | private readonly ICompareLogic comparelogic; 20 | 21 | public StudentEventServiceTests() 22 | { 23 | this.queueBrokerMock = new Mock(); 24 | this.comparelogic = new CompareLogic(); 25 | 26 | this.studentEventService = new StudentEventService( 27 | queueBroker: this.queueBrokerMock.Object); 28 | } 29 | 30 | private static Message CreateStudentMessage(Student student) 31 | { 32 | string serializedStudent = JsonConvert.SerializeObject(student); 33 | byte[] studentBody = Encoding.UTF8.GetBytes(serializedStudent); 34 | 35 | return new Message 36 | { 37 | Body = studentBody 38 | }; 39 | } 40 | 41 | private Expression> SameStudentAs(Student expectedStudent) 42 | { 43 | return actualStudent => 44 | this.comparelogic.Compare(expectedStudent, actualStudent).AreEqual; 45 | } 46 | 47 | private static Student CreateRandomStudent() => 48 | CreateStudentFiller().Create(); 49 | 50 | private static Filler CreateStudentFiller() => 51 | new Filler(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /CulDeSacApi.Tests.Unit/Services/Orchestrations/StudentEvents/StudentEventOrchestrationServiceTests.Logic.Listen.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | using CulDeSacApi.Models.Students; 4 | using Moq; 5 | using Xunit; 6 | 7 | namespace CulDeSacApi.Tests.Unit.Services.Orchestrations.StudentEvents 8 | { 9 | public partial class StudentEventOrchestrationServiceTests 10 | { 11 | [Fact] 12 | public void ShouldListenAndAddStudent() 13 | { 14 | // given 15 | Student randomStudent = CreateRandomStudent(); 16 | Student incomingStudent = randomStudent; 17 | 18 | var mockSequence = new MockSequence(); 19 | 20 | this.studentEventServiceMock.InSequence(mockSequence).Setup(service => 21 | service.ListenToStudentEvent(It.IsAny>())) 22 | .Callback>(eventFunction => 23 | eventFunction.Invoke(incomingStudent)); 24 | 25 | this.studentServiceMock.InSequence(mockSequence).Setup(service => 26 | service.AddStudentAsync(incomingStudent)) 27 | .ReturnsAsync(incomingStudent); 28 | 29 | // when 30 | this.studentEventOrchestrationService.ListenToStudentEvents(); 31 | 32 | // then 33 | this.studentEventServiceMock.Verify(service => 34 | service.ListenToStudentEvent(It.IsAny>()), 35 | Times.Once); 36 | 37 | this.studentServiceMock.Verify(service => 38 | service.AddStudentAsync(incomingStudent), 39 | Times.Once); 40 | 41 | this.localStudentEventService.Verify(broker => 42 | broker.PublishStudentAsync(incomingStudent), 43 | Times.Once); 44 | 45 | this.studentEventServiceMock.VerifyNoOtherCalls(); 46 | this.studentServiceMock.VerifyNoOtherCalls(); 47 | this.localStudentEventService.VerifyNoOtherCalls(); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /CulDeSacApi.Tests.Unit/Services/Orchestrations/LibraryAccounts/LibraryAccountOrchestrationServiceTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Linq.Expressions; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using CulDeSacApi.Models.LibraryAccounts; 8 | using CulDeSacApi.Models.LibraryCards; 9 | using CulDeSacApi.Services.Foundations.LibraryAccounts; 10 | using CulDeSacApi.Services.Foundations.LibraryCards; 11 | using CulDeSacApi.Services.Orchestrations.LibraryAccounts; 12 | using Moq; 13 | using Tynamix.ObjectFiller; 14 | 15 | namespace CulDeSacApi.Tests.Unit.Services.Orchestrations.LibraryAccounts 16 | { 17 | public partial class LibraryAccountOrchestrationServiceTests 18 | { 19 | private readonly Mock libraryAccountServiceMock; 20 | private readonly Mock libraryCardServiceMock; 21 | private readonly ILibraryAccountOrchestrationService libraryAccountOrchestrationService; 22 | 23 | public LibraryAccountOrchestrationServiceTests() 24 | { 25 | this.libraryAccountServiceMock = new Mock(MockBehavior.Strict); 26 | this.libraryCardServiceMock = new Mock(MockBehavior.Strict); 27 | 28 | this.libraryAccountOrchestrationService = new LibraryAccountOrchestrationService( 29 | libraryAccountService: this.libraryAccountServiceMock.Object, 30 | libraryCardService: this.libraryCardServiceMock.Object); 31 | } 32 | 33 | private static Expression> SameLibraryCardAs( 34 | LibraryCard expectedLibraryCard) 35 | { 36 | return actualLibraryCard => 37 | actualLibraryCard.LibraryAccountId == expectedLibraryCard.LibraryAccountId 38 | && actualLibraryCard.Id != Guid.Empty; 39 | } 40 | 41 | private static LibraryAccount CreateRandomLibraryAccount() => 42 | CreateLibraryAccountFiller().Create(); 43 | 44 | private static Filler CreateLibraryAccountFiller() => 45 | new Filler(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /CulDeSacApi.Tests.Unit/Services/Orchestrations/LibraryAccounts/LibraryAccountOrchestrationServiceTests.Logic.Create.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | using CulDeSacApi.Models.LibraryAccounts; 4 | using CulDeSacApi.Models.LibraryCards; 5 | using FluentAssertions; 6 | using Force.DeepCloner; 7 | using Moq; 8 | using Xunit; 9 | 10 | namespace CulDeSacApi.Tests.Unit.Services.Orchestrations.LibraryAccounts 11 | { 12 | public partial class LibraryAccountOrchestrationServiceTests 13 | { 14 | [Fact] 15 | public async Task ShouldCreateLibraryAccountAsync() 16 | { 17 | // given 18 | LibraryAccount randomLibraryAccount = 19 | CreateRandomLibraryAccount(); 20 | 21 | LibraryAccount inputLibraryAccount = 22 | randomLibraryAccount; 23 | 24 | LibraryAccount addedLibraryAccount = 25 | inputLibraryAccount; 26 | 27 | LibraryAccount expectedLibraryAccount = 28 | addedLibraryAccount.DeepClone(); 29 | 30 | var mockSequence = new MockSequence(); 31 | 32 | var expectedInputLibraryCard = new LibraryCard 33 | { 34 | Id = Guid.NewGuid(), 35 | LibraryAccountId = addedLibraryAccount.Id 36 | }; 37 | 38 | this.libraryAccountServiceMock.InSequence(mockSequence).Setup(service => 39 | service.AddLibraryAccountAsync(inputLibraryAccount)) 40 | .ReturnsAsync(addedLibraryAccount); 41 | 42 | this.libraryCardServiceMock.InSequence(mockSequence).Setup(service => 43 | service.AddLibraryCardAsync(It.Is( 44 | SameLibraryCardAs(expectedInputLibraryCard)))) 45 | .ReturnsAsync(expectedInputLibraryCard); 46 | 47 | // when 48 | LibraryAccount actualLibraryAccount = 49 | await this.libraryAccountOrchestrationService 50 | .CreateLibraryAccountAsync(inputLibraryAccount); 51 | 52 | // then 53 | actualLibraryAccount.Should().BeEquivalentTo(expectedLibraryAccount); 54 | 55 | this.libraryAccountServiceMock.Verify(service => 56 | service.AddLibraryAccountAsync(inputLibraryAccount), 57 | Times.Once); 58 | 59 | this.libraryCardServiceMock.Verify(broker => 60 | broker.AddLibraryCardAsync(It.Is(SameLibraryCardAs( 61 | expectedInputLibraryCard))), 62 | Times.Once); 63 | 64 | this.libraryAccountServiceMock.VerifyNoOtherCalls(); 65 | this.libraryCardServiceMock.VerifyNoOtherCalls(); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /CulDeSacApi/Services/Orchestrations/LibraryAccounts/LibraryAccountOrchestrationService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | using CulDeSacApi.Models.LibraryAccounts; 4 | using CulDeSacApi.Models.LibraryCards; 5 | using CulDeSacApi.Services.Foundations.LibraryAccounts; 6 | using CulDeSacApi.Services.Foundations.LibraryCards; 7 | using CulDeSacApi.Services.Foundations.LocalStudentEvents; 8 | 9 | namespace CulDeSacApi.Services.Orchestrations.LibraryAccounts 10 | { 11 | public class LibraryAccountOrchestrationService : ILibraryAccountOrchestrationService 12 | { 13 | private readonly ILibraryAccountService libraryAccountService; 14 | private readonly ILibraryCardService libraryCardService; 15 | private readonly ILocalStudentEventService localStudentEventService; 16 | 17 | public LibraryAccountOrchestrationService( 18 | ILibraryAccountService libraryAccountService, 19 | ILibraryCardService libraryCardService, 20 | ILocalStudentEventService localStudentEventService) 21 | { 22 | this.libraryAccountService = libraryAccountService; 23 | this.libraryCardService = libraryCardService; 24 | this.localStudentEventService = localStudentEventService; 25 | } 26 | 27 | public void ListenToLocalStudentEvent() 28 | { 29 | this.localStudentEventService.ListenToStudentEvent(async (student) => 30 | { 31 | var libraryAccount = new LibraryAccount 32 | { 33 | Id = Guid.NewGuid(), 34 | StudentId = student.Id 35 | }; 36 | 37 | await CreateLibraryAccountAsync(libraryAccount); 38 | 39 | return student; 40 | }); 41 | } 42 | 43 | public async ValueTask CreateLibraryAccountAsync(LibraryAccount libraryAccount) 44 | { 45 | LibraryAccount addedLibraryAccount = 46 | await this.libraryAccountService 47 | .AddLibraryAccountAsync(libraryAccount); 48 | 49 | await CreateLibraryCardAsync(libraryAccount); 50 | 51 | return addedLibraryAccount; 52 | } 53 | 54 | private async Task CreateLibraryCardAsync(LibraryAccount libraryAccount) 55 | { 56 | LibraryCard inputLibraryCard = 57 | CreateLibraryCard(libraryAccount.Id); 58 | 59 | await this.libraryCardService 60 | .AddLibraryCardAsync(inputLibraryCard); 61 | } 62 | 63 | private static LibraryCard CreateLibraryCard(Guid libraryAccountId) 64 | { 65 | return new LibraryCard 66 | { 67 | Id = Guid.NewGuid(), 68 | LibraryAccountId = libraryAccountId 69 | }; 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /CulDeSacApi/Migrations/20220221015024_AddLibraryAccount.Designer.cs: -------------------------------------------------------------------------------- 1 | // 2 | using System; 3 | using CulDeSacApi.Brokers.Storages; 4 | using Microsoft.EntityFrameworkCore; 5 | using Microsoft.EntityFrameworkCore.Infrastructure; 6 | using Microsoft.EntityFrameworkCore.Metadata; 7 | using Microsoft.EntityFrameworkCore.Migrations; 8 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 9 | 10 | #nullable disable 11 | 12 | namespace CulDeSacApi.Migrations 13 | { 14 | [DbContext(typeof(StorageBroker))] 15 | [Migration("20220221015024_AddLibraryAccount")] 16 | partial class AddLibraryAccount 17 | { 18 | protected override void BuildTargetModel(ModelBuilder modelBuilder) 19 | { 20 | #pragma warning disable 612, 618 21 | modelBuilder 22 | .HasAnnotation("ProductVersion", "6.0.1") 23 | .HasAnnotation("Relational:MaxIdentifierLength", 128); 24 | 25 | SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1); 26 | 27 | modelBuilder.Entity("CulDeSacApi.Models.LibraryAccounts.LibraryAccount", b => 28 | { 29 | b.Property("Id") 30 | .ValueGeneratedOnAdd() 31 | .HasColumnType("uniqueidentifier"); 32 | 33 | b.Property("StudentId") 34 | .HasColumnType("uniqueidentifier"); 35 | 36 | b.HasKey("Id"); 37 | 38 | b.HasIndex("StudentId") 39 | .IsUnique(); 40 | 41 | b.ToTable("LibraryAccounts"); 42 | }); 43 | 44 | modelBuilder.Entity("CulDeSacApi.Models.Students.Student", b => 45 | { 46 | b.Property("Id") 47 | .ValueGeneratedOnAdd() 48 | .HasColumnType("uniqueidentifier"); 49 | 50 | b.Property("Name") 51 | .HasColumnType("nvarchar(max)"); 52 | 53 | b.HasKey("Id"); 54 | 55 | b.ToTable("Students"); 56 | }); 57 | 58 | modelBuilder.Entity("CulDeSacApi.Models.LibraryAccounts.LibraryAccount", b => 59 | { 60 | b.HasOne("CulDeSacApi.Models.Students.Student", "Student") 61 | .WithOne("LibraryAccount") 62 | .HasForeignKey("CulDeSacApi.Models.LibraryAccounts.LibraryAccount", "StudentId") 63 | .OnDelete(DeleteBehavior.NoAction) 64 | .IsRequired(); 65 | 66 | b.Navigation("Student"); 67 | }); 68 | 69 | modelBuilder.Entity("CulDeSacApi.Models.Students.Student", b => 70 | { 71 | b.Navigation("LibraryAccount"); 72 | }); 73 | #pragma warning restore 612, 618 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /CulDeSacApi/Startup.cs: -------------------------------------------------------------------------------- 1 | using CulDeSacApi.Brokers.Events; 2 | using CulDeSacApi.Brokers.Queues; 3 | using CulDeSacApi.Brokers.Storages; 4 | using CulDeSacApi.Services.Foundations.LibraryAccounts; 5 | using CulDeSacApi.Services.Foundations.LibraryCards; 6 | using CulDeSacApi.Services.Foundations.LocalStudentEvents; 7 | using CulDeSacApi.Services.Foundations.StudentEvents; 8 | using CulDeSacApi.Services.Foundations.Students; 9 | using CulDeSacApi.Services.Orchestrations.LibraryAccounts; 10 | using CulDeSacApi.Services.Orchestrations.StudentEvents; 11 | using Microsoft.AspNetCore.Builder; 12 | using Microsoft.AspNetCore.Hosting; 13 | using Microsoft.Extensions.Configuration; 14 | using Microsoft.Extensions.DependencyInjection; 15 | using Microsoft.Extensions.Hosting; 16 | using Microsoft.OpenApi.Models; 17 | 18 | namespace CulDeSacApi 19 | { 20 | public class Startup 21 | { 22 | public Startup(IConfiguration configuration) 23 | { 24 | Configuration = configuration; 25 | } 26 | 27 | public IConfiguration Configuration { get; } 28 | 29 | // This method gets called by the runtime. Use this method to add services to the container. 30 | public void ConfigureServices(IServiceCollection services) 31 | { 32 | services.AddControllers(); 33 | services.AddDbContext(); 34 | services.AddTransient(); 35 | services.AddTransient(); 36 | services.AddTransient(); 37 | services.AddTransient(); 38 | services.AddTransient(); 39 | services.AddTransient(); 40 | services.AddTransient(); 41 | services.AddTransient(); 42 | services.AddTransient(); 43 | services.AddTransient(); 44 | 45 | services.AddSwaggerGen(c => 46 | { 47 | c.SwaggerDoc("v1", new OpenApiInfo { Title = "CulDeSacApi", Version = "v1" }); 48 | }); 49 | } 50 | 51 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env) 52 | { 53 | if (env.IsDevelopment()) 54 | { 55 | app.UseDeveloperExceptionPage(); 56 | app.UseSwagger(); 57 | app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "CulDeSacApi v1")); 58 | } 59 | 60 | app.ApplicationServices.GetService().ListenToLocalStudentEvent(); 61 | app.ApplicationServices.GetService().ListenToStudentEvents(); 62 | app.UseHttpsRedirection(); 63 | app.UseRouting(); 64 | app.UseAuthorization(); 65 | 66 | app.UseEndpoints(endpoints => 67 | { 68 | endpoints.MapControllers(); 69 | }); 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /CulDeSacApi/Migrations/StorageBrokerModelSnapshot.cs: -------------------------------------------------------------------------------- 1 | // 2 | using System; 3 | using CulDeSacApi.Brokers.Storages; 4 | using Microsoft.EntityFrameworkCore; 5 | using Microsoft.EntityFrameworkCore.Infrastructure; 6 | using Microsoft.EntityFrameworkCore.Metadata; 7 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 8 | 9 | #nullable disable 10 | 11 | namespace CulDeSacApi.Migrations 12 | { 13 | [DbContext(typeof(StorageBroker))] 14 | partial class StorageBrokerModelSnapshot : ModelSnapshot 15 | { 16 | protected override void BuildModel(ModelBuilder modelBuilder) 17 | { 18 | #pragma warning disable 612, 618 19 | modelBuilder 20 | .HasAnnotation("ProductVersion", "6.0.1") 21 | .HasAnnotation("Relational:MaxIdentifierLength", 128); 22 | 23 | SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1); 24 | 25 | modelBuilder.Entity("CulDeSacApi.Models.LibraryAccounts.LibraryAccount", b => 26 | { 27 | b.Property("Id") 28 | .ValueGeneratedOnAdd() 29 | .HasColumnType("uniqueidentifier"); 30 | 31 | b.Property("StudentId") 32 | .HasColumnType("uniqueidentifier"); 33 | 34 | b.HasKey("Id"); 35 | 36 | b.HasIndex("StudentId") 37 | .IsUnique(); 38 | 39 | b.ToTable("LibraryAccounts"); 40 | }); 41 | 42 | modelBuilder.Entity("CulDeSacApi.Models.LibraryCards.LibraryCard", b => 43 | { 44 | b.Property("Id") 45 | .ValueGeneratedOnAdd() 46 | .HasColumnType("uniqueidentifier"); 47 | 48 | b.Property("LibraryAccountId") 49 | .HasColumnType("uniqueidentifier"); 50 | 51 | b.HasKey("Id"); 52 | 53 | b.HasIndex("LibraryAccountId"); 54 | 55 | b.ToTable("LibraryCards"); 56 | }); 57 | 58 | modelBuilder.Entity("CulDeSacApi.Models.Students.Student", b => 59 | { 60 | b.Property("Id") 61 | .ValueGeneratedOnAdd() 62 | .HasColumnType("uniqueidentifier"); 63 | 64 | b.Property("Name") 65 | .HasColumnType("nvarchar(max)"); 66 | 67 | b.HasKey("Id"); 68 | 69 | b.ToTable("Students"); 70 | }); 71 | 72 | modelBuilder.Entity("CulDeSacApi.Models.LibraryAccounts.LibraryAccount", b => 73 | { 74 | b.HasOne("CulDeSacApi.Models.Students.Student", "Student") 75 | .WithOne("LibraryAccount") 76 | .HasForeignKey("CulDeSacApi.Models.LibraryAccounts.LibraryAccount", "StudentId") 77 | .OnDelete(DeleteBehavior.NoAction) 78 | .IsRequired(); 79 | 80 | b.Navigation("Student"); 81 | }); 82 | 83 | modelBuilder.Entity("CulDeSacApi.Models.LibraryCards.LibraryCard", b => 84 | { 85 | b.HasOne("CulDeSacApi.Models.LibraryAccounts.LibraryAccount", "LibraryAccount") 86 | .WithMany("LibraryCards") 87 | .HasForeignKey("LibraryAccountId") 88 | .OnDelete(DeleteBehavior.NoAction) 89 | .IsRequired(); 90 | 91 | b.Navigation("LibraryAccount"); 92 | }); 93 | 94 | modelBuilder.Entity("CulDeSacApi.Models.LibraryAccounts.LibraryAccount", b => 95 | { 96 | b.Navigation("LibraryCards"); 97 | }); 98 | 99 | modelBuilder.Entity("CulDeSacApi.Models.Students.Student", b => 100 | { 101 | b.Navigation("LibraryAccount"); 102 | }); 103 | #pragma warning restore 612, 618 104 | } 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /CulDeSacApi/Migrations/20220221021659_AddLibraryCard.Designer.cs: -------------------------------------------------------------------------------- 1 | // 2 | using System; 3 | using CulDeSacApi.Brokers.Storages; 4 | using Microsoft.EntityFrameworkCore; 5 | using Microsoft.EntityFrameworkCore.Infrastructure; 6 | using Microsoft.EntityFrameworkCore.Metadata; 7 | using Microsoft.EntityFrameworkCore.Migrations; 8 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 9 | 10 | #nullable disable 11 | 12 | namespace CulDeSacApi.Migrations 13 | { 14 | [DbContext(typeof(StorageBroker))] 15 | [Migration("20220221021659_AddLibraryCard")] 16 | partial class AddLibraryCard 17 | { 18 | protected override void BuildTargetModel(ModelBuilder modelBuilder) 19 | { 20 | #pragma warning disable 612, 618 21 | modelBuilder 22 | .HasAnnotation("ProductVersion", "6.0.1") 23 | .HasAnnotation("Relational:MaxIdentifierLength", 128); 24 | 25 | SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1); 26 | 27 | modelBuilder.Entity("CulDeSacApi.Models.LibraryAccounts.LibraryAccount", b => 28 | { 29 | b.Property("Id") 30 | .ValueGeneratedOnAdd() 31 | .HasColumnType("uniqueidentifier"); 32 | 33 | b.Property("StudentId") 34 | .HasColumnType("uniqueidentifier"); 35 | 36 | b.HasKey("Id"); 37 | 38 | b.HasIndex("StudentId") 39 | .IsUnique(); 40 | 41 | b.ToTable("LibraryAccounts"); 42 | }); 43 | 44 | modelBuilder.Entity("CulDeSacApi.Models.LibraryCards.LibraryCard", b => 45 | { 46 | b.Property("Id") 47 | .ValueGeneratedOnAdd() 48 | .HasColumnType("uniqueidentifier"); 49 | 50 | b.Property("LibraryAccountId") 51 | .HasColumnType("uniqueidentifier"); 52 | 53 | b.HasKey("Id"); 54 | 55 | b.HasIndex("LibraryAccountId"); 56 | 57 | b.ToTable("LibraryCards"); 58 | }); 59 | 60 | modelBuilder.Entity("CulDeSacApi.Models.Students.Student", b => 61 | { 62 | b.Property("Id") 63 | .ValueGeneratedOnAdd() 64 | .HasColumnType("uniqueidentifier"); 65 | 66 | b.Property("Name") 67 | .HasColumnType("nvarchar(max)"); 68 | 69 | b.HasKey("Id"); 70 | 71 | b.ToTable("Students"); 72 | }); 73 | 74 | modelBuilder.Entity("CulDeSacApi.Models.LibraryAccounts.LibraryAccount", b => 75 | { 76 | b.HasOne("CulDeSacApi.Models.Students.Student", "Student") 77 | .WithOne("LibraryAccount") 78 | .HasForeignKey("CulDeSacApi.Models.LibraryAccounts.LibraryAccount", "StudentId") 79 | .OnDelete(DeleteBehavior.NoAction) 80 | .IsRequired(); 81 | 82 | b.Navigation("Student"); 83 | }); 84 | 85 | modelBuilder.Entity("CulDeSacApi.Models.LibraryCards.LibraryCard", b => 86 | { 87 | b.HasOne("CulDeSacApi.Models.LibraryAccounts.LibraryAccount", "LibraryAccount") 88 | .WithMany("LibraryCards") 89 | .HasForeignKey("LibraryAccountId") 90 | .OnDelete(DeleteBehavior.NoAction) 91 | .IsRequired(); 92 | 93 | b.Navigation("LibraryAccount"); 94 | }); 95 | 96 | modelBuilder.Entity("CulDeSacApi.Models.LibraryAccounts.LibraryAccount", b => 97 | { 98 | b.Navigation("LibraryCards"); 99 | }); 100 | 101 | modelBuilder.Entity("CulDeSacApi.Models.Students.Student", b => 102 | { 103 | b.Navigation("LibraryAccount"); 104 | }); 105 | #pragma warning restore 612, 618 106 | } 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Oo]ut/ 33 | [Ll]og/ 34 | [Ll]ogs/ 35 | 36 | # Visual Studio 2015/2017 cache/options directory 37 | .vs/ 38 | # Uncomment if you have tasks that create the project's static files in wwwroot 39 | #wwwroot/ 40 | 41 | # Visual Studio 2017 auto generated files 42 | Generated\ Files/ 43 | 44 | # MSTest test Results 45 | [Tt]est[Rr]esult*/ 46 | [Bb]uild[Ll]og.* 47 | 48 | # NUnit 49 | *.VisualState.xml 50 | TestResult.xml 51 | nunit-*.xml 52 | 53 | # Build Results of an ATL Project 54 | [Dd]ebugPS/ 55 | [Rr]eleasePS/ 56 | dlldata.c 57 | 58 | # Benchmark Results 59 | BenchmarkDotNet.Artifacts/ 60 | 61 | # .NET Core 62 | project.lock.json 63 | project.fragment.lock.json 64 | artifacts/ 65 | 66 | # ASP.NET Scaffolding 67 | ScaffoldingReadMe.txt 68 | 69 | # StyleCop 70 | StyleCopReport.xml 71 | 72 | # Files built by Visual Studio 73 | *_i.c 74 | *_p.c 75 | *_h.h 76 | *.ilk 77 | *.meta 78 | *.obj 79 | *.iobj 80 | *.pch 81 | *.pdb 82 | *.ipdb 83 | *.pgc 84 | *.pgd 85 | *.rsp 86 | *.sbr 87 | *.tlb 88 | *.tli 89 | *.tlh 90 | *.tmp 91 | *.tmp_proj 92 | *_wpftmp.csproj 93 | *.log 94 | *.vspscc 95 | *.vssscc 96 | .builds 97 | *.pidb 98 | *.svclog 99 | *.scc 100 | 101 | # Chutzpah Test files 102 | _Chutzpah* 103 | 104 | # Visual C++ cache files 105 | ipch/ 106 | *.aps 107 | *.ncb 108 | *.opendb 109 | *.opensdf 110 | *.sdf 111 | *.cachefile 112 | *.VC.db 113 | *.VC.VC.opendb 114 | 115 | # Visual Studio profiler 116 | *.psess 117 | *.vsp 118 | *.vspx 119 | *.sap 120 | 121 | # Visual Studio Trace Files 122 | *.e2e 123 | 124 | # TFS 2012 Local Workspace 125 | $tf/ 126 | 127 | # Guidance Automation Toolkit 128 | *.gpState 129 | 130 | # ReSharper is a .NET coding add-in 131 | _ReSharper*/ 132 | *.[Rr]e[Ss]harper 133 | *.DotSettings.user 134 | 135 | # TeamCity is a build add-in 136 | _TeamCity* 137 | 138 | # DotCover is a Code Coverage Tool 139 | *.dotCover 140 | 141 | # AxoCover is a Code Coverage Tool 142 | .axoCover/* 143 | !.axoCover/settings.json 144 | 145 | # Coverlet is a free, cross platform Code Coverage Tool 146 | coverage*.json 147 | coverage*.xml 148 | coverage*.info 149 | 150 | # Visual Studio code coverage results 151 | *.coverage 152 | *.coveragexml 153 | 154 | # NCrunch 155 | _NCrunch_* 156 | .*crunch*.local.xml 157 | nCrunchTemp_* 158 | 159 | # MightyMoose 160 | *.mm.* 161 | AutoTest.Net/ 162 | 163 | # Web workbench (sass) 164 | .sass-cache/ 165 | 166 | # Installshield output folder 167 | [Ee]xpress/ 168 | 169 | # DocProject is a documentation generator add-in 170 | DocProject/buildhelp/ 171 | DocProject/Help/*.HxT 172 | DocProject/Help/*.HxC 173 | DocProject/Help/*.hhc 174 | DocProject/Help/*.hhk 175 | DocProject/Help/*.hhp 176 | DocProject/Help/Html2 177 | DocProject/Help/html 178 | 179 | # Click-Once directory 180 | publish/ 181 | 182 | # Publish Web Output 183 | *.[Pp]ublish.xml 184 | *.azurePubxml 185 | # Note: Comment the next line if you want to checkin your web deploy settings, 186 | # but database connection strings (with potential passwords) will be unencrypted 187 | *.pubxml 188 | *.publishproj 189 | 190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 191 | # checkin your Azure Web App publish settings, but sensitive information contained 192 | # in these scripts will be unencrypted 193 | PublishScripts/ 194 | 195 | # NuGet Packages 196 | *.nupkg 197 | # NuGet Symbol Packages 198 | *.snupkg 199 | # The packages folder can be ignored because of Package Restore 200 | **/[Pp]ackages/* 201 | # except build/, which is used as an MSBuild target. 202 | !**/[Pp]ackages/build/ 203 | # Uncomment if necessary however generally it will be regenerated when needed 204 | #!**/[Pp]ackages/repositories.config 205 | # NuGet v3's project.json files produces more ignorable files 206 | *.nuget.props 207 | *.nuget.targets 208 | 209 | # Microsoft Azure Build Output 210 | csx/ 211 | *.build.csdef 212 | 213 | # Microsoft Azure Emulator 214 | ecf/ 215 | rcf/ 216 | 217 | # Windows Store app package directories and files 218 | AppPackages/ 219 | BundleArtifacts/ 220 | Package.StoreAssociation.xml 221 | _pkginfo.txt 222 | *.appx 223 | *.appxbundle 224 | *.appxupload 225 | 226 | # Visual Studio cache files 227 | # files ending in .cache can be ignored 228 | *.[Cc]ache 229 | # but keep track of directories ending in .cache 230 | !?*.[Cc]ache/ 231 | 232 | # Others 233 | ClientBin/ 234 | ~$* 235 | *~ 236 | *.dbmdl 237 | *.dbproj.schemaview 238 | *.jfm 239 | *.pfx 240 | *.publishsettings 241 | orleans.codegen.cs 242 | 243 | # Including strong name files can present a security risk 244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 245 | #*.snk 246 | 247 | # Since there are multiple workflows, uncomment next line to ignore bower_components 248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 249 | #bower_components/ 250 | 251 | # RIA/Silverlight projects 252 | Generated_Code/ 253 | 254 | # Backup & report files from converting an old project file 255 | # to a newer Visual Studio version. Backup files are not needed, 256 | # because we have git ;-) 257 | _UpgradeReport_Files/ 258 | Backup*/ 259 | UpgradeLog*.XML 260 | UpgradeLog*.htm 261 | ServiceFabricBackup/ 262 | *.rptproj.bak 263 | 264 | # SQL Server files 265 | *.mdf 266 | *.ldf 267 | *.ndf 268 | 269 | # Business Intelligence projects 270 | *.rdl.data 271 | *.bim.layout 272 | *.bim_*.settings 273 | *.rptproj.rsuser 274 | *- [Bb]ackup.rdl 275 | *- [Bb]ackup ([0-9]).rdl 276 | *- [Bb]ackup ([0-9][0-9]).rdl 277 | 278 | # Microsoft Fakes 279 | FakesAssemblies/ 280 | 281 | # GhostDoc plugin setting file 282 | *.GhostDoc.xml 283 | 284 | # Node.js Tools for Visual Studio 285 | .ntvs_analysis.dat 286 | node_modules/ 287 | 288 | # Visual Studio 6 build log 289 | *.plg 290 | 291 | # Visual Studio 6 workspace options file 292 | *.opt 293 | 294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 295 | *.vbw 296 | 297 | # Visual Studio LightSwitch build output 298 | **/*.HTMLClient/GeneratedArtifacts 299 | **/*.DesktopClient/GeneratedArtifacts 300 | **/*.DesktopClient/ModelManifest.xml 301 | **/*.Server/GeneratedArtifacts 302 | **/*.Server/ModelManifest.xml 303 | _Pvt_Extensions 304 | 305 | # Paket dependency manager 306 | .paket/paket.exe 307 | paket-files/ 308 | 309 | # FAKE - F# Make 310 | .fake/ 311 | 312 | # CodeRush personal settings 313 | .cr/personal 314 | 315 | # Python Tools for Visual Studio (PTVS) 316 | __pycache__/ 317 | *.pyc 318 | 319 | # Cake - Uncomment if you are using it 320 | # tools/** 321 | # !tools/packages.config 322 | 323 | # Tabs Studio 324 | *.tss 325 | 326 | # Telerik's JustMock configuration file 327 | *.jmconfig 328 | 329 | # BizTalk build output 330 | *.btp.cs 331 | *.btm.cs 332 | *.odx.cs 333 | *.xsd.cs 334 | 335 | # OpenCover UI analysis results 336 | OpenCover/ 337 | 338 | # Azure Stream Analytics local run output 339 | ASALocalRun/ 340 | 341 | # MSBuild Binary and Structured Log 342 | *.binlog 343 | 344 | # NVidia Nsight GPU debugger configuration file 345 | *.nvuser 346 | 347 | # MFractors (Xamarin productivity tool) working folder 348 | .mfractor/ 349 | 350 | # Local History for Visual Studio 351 | .localhistory/ 352 | 353 | # BeatPulse healthcheck temp database 354 | healthchecksdb 355 | 356 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 357 | MigrationBackup/ 358 | 359 | # Ionide (cross platform F# VS Code tools) working folder 360 | .ionide/ 361 | 362 | # Fody - auto-generated XML schema 363 | FodyWeavers.xsd --------------------------------------------------------------------------------