Skip to content

Instantly share code, notes, and snippets.

View MarcoNicolodi's full-sized avatar

Marco Nicolodi MarcoNicolodi

View GitHub Profile
@MarcoNicolodi
MarcoNicolodi / BusinessEngineMock.cs
Created January 13, 2019 21:06
Flaky unit test suite
var businessMock = new Mock<IDocumentBusiness>();
businessMock.Setup(b => b.EnsureCanCancelRevision(It.Is<Document>(calledDocument => calledDocument.Equals(document))));
businessMock.Verify();
@MarcoNicolodi
MarcoNicolodi / ImprovedTestCase.cs
Created January 14, 2019 13:08
Flaky unit test suite
[Fact(DisplayName = @"
GIVEN
that document Atendence List is published
AND SteveJobs is the elaborator
AND SteveJobs requested a new revision
AND the request is still open
AND SteveJobs has an open and closed revision request
WHEN
I replace SteveJobs with MrCatra
THEN
@MarcoNicolodi
MarcoNicolodi / WebformsComponentCodeBehind.cs
Last active January 18, 2019 14:10
Chain of responsability code refactoring
public class WebformsComponentCodeBehind
{
public List<TrainingEffectiveness> TrainingEffectiveness { get; private set; }
public List<TrainingEvaluations> TrainingEvaluations { get; private set; }
protected string GetClass(string code, bool approve)
{
// Don't bother these
var evaluation = TrainingEvaluations.Find(x => x.EmployeeCode == code.Split('_')[0] && x.CriteriaCode == code.Split('_')[1]);
var criteriaHasEvaluation = evaluation.Any();
@MarcoNicolodi
MarcoNicolodi / Request.cs
Last active January 17, 2019 22:16
Chain of responsibility
public class Request
{
public Request(string code, bool approve, TrainingEvaluations evaluations, TrainningEffectiveness effectiveness)
{
CriteriaHasEvaluation = evaluations.Find(x => x.EmployeeCode == code.Split('_')[0] && x.CriteriaCode == code.Split('_')[1]).Any();
IsNew = code.Split('_')[1] == IEntity.NewCode;
Effectiveness = effectiveness.Find(x => x.EmployeeCode == code.Split('_')[0]);
HasEffectiveness = effectiveness.Any();
Approve = approve;
}
@MarcoNicolodi
MarcoNicolodi / GetClass.cs
Created January 17, 2019 21:13
Chain of responsibility
protected string GetClass(string code, bool approve)
{
var request = new Request(code, approve, TrainingEvaluations, TrainningEffectiveness);
if (request.CriteriaHasEvaluation)
{
return request.Evaluation.IsEvaluated
? request.Approve
? request.Evaluation.IsApproved
? "approvedOn"
@MarcoNicolodi
MarcoNicolodi / Label.cs
Last active January 22, 2019 10:49
Chain of responsibility
public class Label
{
private Label(string Result)
{
Value = Result;
}
public string Value { get; }
public static Label ApprovedOn => new Label("approvedOn");
@MarcoNicolodi
MarcoNicolodi / AbstractRuleHandler.cs
Last active January 22, 2019 11:01
Chain of responsibility
public abstract class RuleHandler {
private RuleHandler _nextRule;
public RuleHandler NextRule (RuleHandler nextRule) {
_nextRule = nextRule;
return nextRule;
}
public virtual Label Run (Request request) => _nextRule.Run(request);
}
@MarcoNicolodi
MarcoNicolodi / CriteriaHasEvaluation.cs
Last active January 17, 2019 22:31
Chain of responsibility
if (request.CriteriaHasEvaluation)
{
return request.Evaluation.IsEvaluated
? request.Approve
? request.Evaluation.IsApproved
? "approvedOn"
: "approvedOff"
: !request.Evaluation.IsApproved
? "reprovedOn"
: "reprovedOff"
@MarcoNicolodi
MarcoNicolodi / CriteriaHasEvaluation.cs
Created January 17, 2019 22:45
Chain of responsibility
public class CriteriaHasEvaluation : RuleHandler {
public override Label Run(Request request)
{
if(request.CriteriaHasEvaluation)
{
return request.Evaluation.IsEvaluated
? request.Approve
? request.Evaluation.IsApproved
? Label.Approved
@MarcoNicolodi
MarcoNicolodi / EffectivenessMissing.cs
Created January 18, 2019 14:12
Chain of responsibility
if (!hasEffectiveness) return approve ? "approvedOff" : "reprovedOff";