Skip to content

Commit

Permalink
Merge pull request #369 from jburditt/fork
Browse files Browse the repository at this point in the history
VS-6873 update readme
  • Loading branch information
GeorgeWalker authored Jan 6, 2025
2 parents 953a143 + 18f8c73 commit da7ef5c
Show file tree
Hide file tree
Showing 28 changed files with 2,315 additions and 34 deletions.
73 changes: 73 additions & 0 deletions COAST.postman_collection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"info": {
"_postman_id": "a1cf9a99-8a52-4deb-998a-e3b4e990bf41",
"name": "COAST",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "730057"
},
"item": [
{
"name": "VSD",
"item": [
{
"name": "Payment/send POST",
"request": {
"method": "POST",
"header": [],
"url": {
"raw": "https://coast-restitution-dev.silver.devops.bcgov/api/Payment/send",
"host": [
"{{server}}"
],
"path": [
"Payment",
"send"
]
}
},
"response": []
},
{
"name": "PaymentSchedule/schedule-cvap POST",
"request": {
"method": "POST",
"header": [],
"url": {
"raw": "https://coast-restitution-dev.silver.devops.bcgov/api/PaymentSchedule/schedule-cvap",
"host": [
"{{server}}"
],
"path": [
"PaymentSchedule",
"schedule-cvap"
]
}
},
"response": []
}
]
}
],
"event": [
{
"listen": "prerequest",
"script": {
"type": "text/javascript",
"packages": {},
"exec": [
""
]
}
},
{
"listen": "test",
"script": {
"type": "text/javascript",
"packages": {},
"exec": [
""
]
}
}
]
}
39 changes: 39 additions & 0 deletions Database/Model/DatabaseContext.Partial.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Microsoft.Xrm.Sdk;

namespace Database.Model;

public partial class DatabaseContext
{
private bool isInTransaction;

public new SaveChangesResultCollection SaveChanges()
{
if (!isInTransaction)
{
return base.SaveChanges();
}

return null;
}

public TransactionContext BeginTransaction()
{
if (isInTransaction) throw new InvalidOperationException("Already in a transaction");
isInTransaction = true;
return new TransactionContext(this);
}

public void CommitTransaction()
{
if (isInTransaction)
{
base.SaveChanges();
isInTransaction = false;
}
}
}

public class TransactionContext(DatabaseContext context)
{
public void Commit() => context.CommitTransaction();
}
4 changes: 1 addition & 3 deletions Manager.Contract/Dto/ScheduleG.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
namespace Manager.Contract;

public record ScheduleGQuery : IRequest<ScheduleGResult>
public record ScheduleGQuery : IRequest<IEnumerable<ScheduleG>>
{
public Guid? Id { get; set; }
public Guid? ProgramId { get; set; }
public Quarter? Quarter { get; set; }
}

public record ScheduleGResult(IEnumerable<ScheduleG> ScheduleGs);

public record ScheduleG : IDto
{
public Guid Id { get; set; }
Expand Down
8 changes: 4 additions & 4 deletions Manager/ScheduleGHandlers.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
namespace Manager;

public class ScheduleGHandlers(IScheduleGRepository repository) //:
//QueryBaseHandlers<IScheduleGRepository, ScheduleG, ScheduleGQuery>(repository),
//IRequestHandler<ScheduleGQuery, ScheduleGResult>,
//IRequestHandler<InsertCommand<ScheduleG>, Guid>
public class ScheduleGHandlers(IScheduleGRepository repository) :
QueryBaseHandlers<IScheduleGRepository, ScheduleG, ScheduleGQuery>(repository),
IRequestHandler<ScheduleGQuery, IEnumerable<ScheduleG>>,
IRequestHandler<InsertCommand<ScheduleG>, Guid>
{

}
2 changes: 1 addition & 1 deletion Resources/ScheduleG/IScheduleGRepository.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Resources;

public interface IScheduleGRepository : IBaseRepository<ScheduleG>, IQueryRepository<ScheduleGQuery, ScheduleGResult>
public interface IScheduleGRepository : IBaseRepository<ScheduleG>, IQueryRepository<ScheduleGQuery, ScheduleG>
{

}
7 changes: 3 additions & 4 deletions Resources/ScheduleG/ScheduleGRepository.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Resources;

public class ScheduleGRepository : BaseRepository<Vsd_ScheduleG, ScheduleG>//, IScheduleGRepository
public class ScheduleGRepository : BaseRepository<Vsd_ScheduleG, ScheduleG>, IScheduleGRepository
{
private readonly DatabaseContext _databaseContext;

Expand All @@ -9,15 +9,14 @@ public ScheduleGRepository(DatabaseContext databaseContext, IMapper mapper) : ba
_databaseContext = databaseContext;
}

public ScheduleGResult Query(ScheduleGQuery query)
public IEnumerable<ScheduleG> Query(ScheduleGQuery query)
{
var queryResults = _databaseContext.Vsd_ScheduleGSet
.WhereIf(query.Id != null, x => x.Id == query.Id)
.WhereIf(query.ProgramId != null, x => x.Vsd_Program.Id == query.ProgramId)
.WhereIf(query.Quarter != null, x => x.Vsd_Cpu_ReportingPeriod == (Vsd_ScheduleG_Vsd_Cpu_ReportingPeriod?)query.Quarter)
.ToList();

var scheduleGs = _mapper.Map<IEnumerable<ScheduleG>>(queryResults);
return new ScheduleGResult(scheduleGs);
return _mapper.Map<IEnumerable<ScheduleG>>(queryResults);
}
}
6 changes: 6 additions & 0 deletions Shared.Database/Mappers/SharedMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ public class SharedMapper : Profile
{
public SharedMapper()
{
RecognizeDestinationPrefixes("Vsd_");
RecognizePrefixes("Vsd_");

RecognizeDestinationPostfixes("Id");
RecognizePostfixes("Id");

CreateMap<Money, decimal>()
.ConvertUsing(src => src.Value);
CreateMap<Money, decimal?>()
Expand Down
5 changes: 5 additions & 0 deletions Tests/Fake/FakeDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public class FakeDto : IDto
{
public Guid Id { get; set; }
public StateCode StateCode { get; set; }
}
8 changes: 8 additions & 0 deletions Tests/Fake/FakeHandlers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
public class FakeHandlers(IFakeRepository repository) : BaseHandlers<IFakeRepository, FakeDto>(repository),
IRequestHandler<InsertCommand<FakeDto>, Guid>,
IRequestHandler<UpsertCommand<FakeDto>, Guid>,
IRequestHandler<DeleteCommand<FakeDto>, bool>,
IRequestHandler<TryDeleteCommand<FakeDto>, bool>,
IRequestHandler<TryDeleteByDtoCommand<FakeDto>, bool>
{
}
56 changes: 56 additions & 0 deletions Tests/Fake/FakeRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using AutoMapper;
using System.Linq.Expressions;

namespace Resources;

public class FakeRepository : IFakeRepository
{
protected readonly DatabaseContext _databaseContext;
protected readonly IMapper _mapper;

public FakeRepository(DatabaseContext databaseContext, IMapper mapper)
{
_databaseContext = databaseContext;
_mapper = mapper;
}

public virtual Guid Insert(FakeDto dto)
{
return new Guid();
}

public virtual Guid Upsert(FakeDto dto)
{
return new Guid();
}

public IEnumerable<FakeDto> Where(Expression<Func<FakeDto, bool>> predicates)
{
throw new NotImplementedException();
}

public bool Update(FakeDto dto)
{
return true;
}

public virtual bool TryDelete(Guid id)
{
return true;
}

public virtual bool TryDelete(FakeDto dto, bool isRecursive = false)
{
return true;
}

public virtual bool TryDeleteRange(IEnumerable<FakeDto> invoices, bool isRecursive = false)
{
return true;
}

public virtual bool Delete(Guid id)
{
return true;
}
}
3 changes: 3 additions & 0 deletions Tests/Fake/IFakeRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public interface IFakeRepository : IBaseRepository<FakeDto>
{
}
105 changes: 105 additions & 0 deletions Tests/Integration/Database/ContractRepositoryTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
public class ContractRepositoryTests(IContractRepository repository)
{
// WARNING!!! these are not reliable tests, they will fail, these were shortcuts I used for building a POC, these tests will need to be adjusted in order to be idempotent

[Fact]
public void Insert()
{
// Arrange
var contract = FakeData.Contracts[0];

// Act
var id = repository.Insert(contract);

// Assert
Assert.True(id != Guid.Empty);
}

[Fact]
public void Upsert()
{
// Arrange
var contract = FakeData.Contracts[0];

// Act
var id = repository.Upsert(contract);

// Assert
Assert.True(id != Guid.Empty);
}

[Fact]
public void Query()
{
// Arrange
var command = new ContractQuery();

// Act
var result = repository.Query(command);

// Assert
Assert.True(result.Count() > 0);
}

[Fact]
public void Delete()
{
// Arrange
var id = new Guid("");

// Act
var result = repository.TryDelete(id);

// Assert
Assert.True(result);
}

// FINDINGS
// Cloning using the vsd_CloneContract Action does not duplicate all fields like Dynamics scheduled job does
// Cannot save vsd_contract entity with "DulyExecuted" status code
// Scheduled Job worked the first time and then stopped working, no clone was found and vsd_ClonedContractId was null
[Fact]
public void Clone()
{
// Arrange
var command = new ContractQuery();
command.StateCode = StateCode.Active;
command.StatusCode = ContractStatusCode.DulyExecuted;
command.CpuCloneFlag = true;

// Act
var result = repository.Query(command);
Guid? id = null;
foreach (var contract in result)
{
if (!repository.IsCloned(contract.Id))
{
id = repository.Clone(contract.Id);
}
}

// Assert
Assert.NotNull(id);
}

[Fact]
public void Delete_Clones()
{
var query = new ContractQuery();
query.StateCode = StateCode.Active;
query.StatusCode = ContractStatusCode.DulyExecuted;
query.CpuCloneFlag = true;
var result = repository.Query(query);

List<Guid> ids = new List<Guid>();
foreach (var contract in result)
{
// if cloned
if (repository.IsCloned(contract.Id))
{
// delete the clone
repository.DeleteClone(contract.Id);
}
}
}
}
Loading

0 comments on commit da7ef5c

Please sign in to comment.