Skip to content

Commit

Permalink
Changes to address the broken build
Browse files Browse the repository at this point in the history
- architecture tests rejected non sealed domain events - fixed
- architecture tests failed to find private parameterless constructor as required - fixed.
- mapping tests failed to detect private parameter constructors - fixed
  • Loading branch information
carlsixsmith-moj committed Jun 25, 2024
1 parent b0ddde1 commit 50a5c99
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 150 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

12 changes: 4 additions & 8 deletions src/Application/Features/Participants/Commands/AddConsent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,13 @@ public async Task<Result<string>> Handle(Command request, CancellationToken canc
throw new NotFoundException("Cannot find participant", request.ParticipantId);
}

var document = new Document()
{
Description = $"Consent form for {request.ParticipantId}",
DocumentType = DocumentType.Document,
IsPublic = false,
Title = request.UploadRequest!.FileName
};
var document = Document.Create(request.UploadRequest!.FileName,
$"Consent form for {request.ParticipantId}",
DocumentType.PDF);

var result = await uploadService.UploadAsync($"{request.ParticipantId}/consent", request.UploadRequest!);

document.URL = result;
document.SetURL(result);

participant.AddConsent(request.ConsentDate!.Value, document.Id);

Expand Down
13 changes: 5 additions & 8 deletions src/Application/Features/Participants/Commands/AddRightToWork.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,14 @@ public async Task<Result<string>> Handle(Command request, CancellationToken canc
{
throw new NotFoundException("Cannot find participant", request.ParticipantId);
}

var document = Document.Create(request.UploadRequest!.FileName,
$"Right to work evidence for {request.ParticipantId}",
DocumentType.PDF);

var document = new Document()
{
Description = $"Right to work evidence for {request.ParticipantId}",
DocumentType = DocumentType.Document,
IsPublic = false,
Title = request.UploadRequest!.FileName
};

var result = await uploadService.UploadAsync($"{request.ParticipantId}/rtw", request.UploadRequest!);
document.URL = result;
document.SetURL(result);

participant.AddRightToWork(request.ValidFrom!.Value, request.ValidTo!.Value, document.Id);

Expand Down
41 changes: 33 additions & 8 deletions src/Domain/Entities/Documents/Document.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,50 @@
using Cfo.Cats.Domain.Common.Contracts;
using Cfo.Cats.Domain.Common.Entities;
using Cfo.Cats.Domain.Entities.Administration;
using Cfo.Cats.Domain.Events;

namespace Cfo.Cats.Domain.Entities.Documents;

public class Document : OwnerPropertyEntity<Guid>, IMayHaveTenant, IAuditTrial
{
public Document()
private Document()
{
Id = Guid.NewGuid();
}

public string? Title { get; set; }
public string? Description { get; set; }
public string? Content { get; set; }
public bool IsPublic { get; set; }
public string? URL { get; set; }
public DocumentType DocumentType { get; set; } = default!;
private Document(string title, string description, DocumentType documentType)
{
Title = title;
IsPublic = false;
Description = description;
DocumentType = documentType;

AddDomainEvent(new DocumentCreatedDomainEvent(this));
}


public static Document Create(string title, string description, DocumentType documentType)
{
return new(title, description, documentType);
}

public Document SetURL(string url)
{
URL = url;
return this;
}

public string? Title { get; private set; }
public string? Description { get; private set; }

[Obsolete("We are not storing the content with the document", false)]
public string? Content { get; private set; }
public bool IsPublic { get; private set; }
public string? URL { get; private set; }
public DocumentType DocumentType { get; private set; } = default!;
public virtual Tenant? Tenant { get; set; }

public string? TenantId {get;set;}
public string? TenantId {get; set;}
}

public enum DocumentType
Expand Down
4 changes: 2 additions & 2 deletions src/Domain/Events/DocumentEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

namespace Cfo.Cats.Domain.Events;

public class DocumentCreatedDomainEvent(Document entity) : CreatedDomainEvent<Document>(entity);
public sealed class DocumentCreatedDomainEvent(Document entity) : CreatedDomainEvent<Document>(entity);

public class DocumentUpdatedDomainEvent(Document entity) : UpdatedDomainEvent<Document>(entity);
public sealed class DocumentUpdatedDomainEvent(Document entity) : UpdatedDomainEvent<Document>(entity);
2 changes: 1 addition & 1 deletion src/Domain/Events/RightToWorkEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
namespace Cfo.Cats.Domain.Events;


public class RightToWorkCreatedDomainEvent(RightToWork entity) : CreatedDomainEvent<RightToWork>(entity);
public sealed class RightToWorkCreatedDomainEvent(RightToWork entity) : CreatedDomainEvent<RightToWork>(entity);
2 changes: 1 addition & 1 deletion src/Domain/Events/TenantRenamedDomainEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Cfo.Cats.Domain.Events;

public class TenantRenamedDomainEvent(Tenant entity, string oldName) : UpdatedDomainEvent<Tenant>(entity)
public sealed class TenantRenamedDomainEvent(Tenant entity, string oldName) : UpdatedDomainEvent<Tenant>(entity)
{
public string OldName { get; } = oldName;
}
8 changes: 5 additions & 3 deletions test/Application.UnitTests/Mappings/MappingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ public void LocationDtoShouldMapCorrectlyToLocationTypeDto()

}

private object GetInstanceOf(Type type)
private static object GetInstanceOf(Type type)
{
if (type.GetConstructor(Type.EmptyTypes) != null)
return Activator.CreateInstance(type);
// Check for a parameterless constructor, including non-public ones
ConstructorInfo constructor = type.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null);
if (constructor != null)
return constructor.Invoke(null);

// Type without parameterless constructor
return FormatterServices.GetUninitializedObject(type);
Expand Down

0 comments on commit 50a5c99

Please sign in to comment.