public void ExampleRenunciation() { var testCrime = new Felony { ActusReus = new Conspiracy { IsAgreementToCommitCrime = lp => lp is ShellyDriverEg }, MensRea = new SpecificIntent { IsKnowledgeOfWrongdoing = lp => lp is ShellyDriverEg, IsIntentOnWrongdoing = lp => lp is ShellyDriverEg } }; var testResult = testCrime.IsValid(new ShellyDriverEg()); Assert.IsTrue(testResult); var testSubject = new Renunciation(testCrime) { IsCompletely = lp => lp is ShellyDriverEg, IsResultCrimeThwarted = lp => lp is ShellyDriverEg, IsVoluntarily = lp => lp is ShellyDriverEg }; testResult = testSubject.IsValid(new ShellyDriverEg()); Console.WriteLine(testSubject.ToString()); Assert.IsTrue(testResult); }
public RenunciationModule() : base("/renunciations") { #region Get["/"] = _ => { return(View["index", DocumentSession.Query <Renunciation>() .Customize(q => q.WaitForNonStaleResultsAsOfLastWrite()) .ToList()]); }; #endregion #region Get["/{Id}"] = x => { Guid renunciationId = Guid.Parse(x.Id); var renunciation = DocumentSession.Query <Renunciation>("RenunciationById") .Customize(q => q.WaitForNonStaleResultsAsOfLastWrite()) .Where(n => n.Id == renunciationId).FirstOrDefault(); if (renunciation == null) { return(new NotFoundResponse()); } return(View["show", renunciation]); }; #endregion #region Get["/new"] = x => { return(View["new", Renunciation.DefaultRenunciation()]); }; #endregion #region Post["/new"] = x => { var renunciation = this.Bind <Renunciation>(); var result = new RenunciationValidator().Validate(renunciation); if (!result.IsValid) { return(View["Shared/_errors", result]); } DocumentSession.Store(renunciation); return(Response.AsRedirect(string.Format("/renunciations/{0}", renunciation.Id))); }; #endregion #region Get["/edit/{Id}"] = x => { Guid renunciationId = Guid.Parse(x.Id); var renunciation = DocumentSession.Query <Renunciation>("RenunciationById") .Where(n => n.Id == renunciationId).FirstOrDefault(); if (renunciation == null) { return(new NotFoundResponse()); } return(View["edit", renunciation]); }; #endregion #region Post["/edit/{Id}"] = x => { var renunciation = this.Bind <Renunciation>(); var result = new RenunciationValidator().Validate(renunciation, ruleSet: "Update"); if (!result.IsValid) { return(View["Shared/_errors", result]); } Guid renunciationId = Guid.Parse(x.Id); var saved = DocumentSession.Query <Renunciation>("RenunciationById") .Where(n => n.Id == renunciationId).FirstOrDefault(); if (saved == null) { return(new NotFoundResponse()); } saved.Fill(renunciation); return(Response.AsRedirect(string.Format("/renunciations/{0}", renunciation.Id))); }; #endregion #region Get["/delete/{Id}"] = x => { Guid renunciationId = Guid.Parse(x.Id); var renunciation = DocumentSession.Query <Renunciation>("RenunciationById") .Where(n => n.Id == renunciationId).FirstOrDefault(); if (renunciation == null) { return(new NotFoundResponse()); } DocumentSession.Delete(renunciation); return(Response.AsRedirect("/renunciations")); }; #endregion }