public void FunqResult_Should_Fail_If_Not_Successful_And_Message_Is_Null_Or_WhiteSpace() { try { var funqResult = FunqFactory.Fail(" "); Assert.Fail("InvalidOperationException was not thrown as expected."); } catch (InvalidOperationException e) { Assert.AreEqual("No error message provided for a non-successful value", e.Message, "The expected messages didn't match up. Please correct the \"expected\" value"); } }
public async Task <FunqResult <Minion> > UpdateMinionAsync(Minion minion) { var dbMinion = await _minionReadSvc.GetMinionAsync(minion.Id).ConfigureAwait(false); if (dbMinion == null) { return(FunqFactory.Fail("Unable to find existing minion to update", (Minion)null)); } dbMinion.MovieMoments = minion.MovieMoments; dbMinion.Name = minion.Name; dbMinion.Nickname = minion.Nickname; dbMinion.Traits = minion.Traits; await _appCache.AddOrUpdateAsync(dbMinion.Id.ToString(), dbMinion, null, typeof(Minion).Name).ConfigureAwait(false); return(FunqFactory.KeepGroovin(dbMinion, "Successfully updated minion")); }
public void The_Catch_Method_Should_Handle_The_Error() { string someLogger = null; var someResult = "First Line".GetFunqy() .Then(val => { var sb = new StringBuilder(); sb.AppendLine(val); sb.AppendLine("Second Line"); var strValue = sb.ToString(); return(FunqFactory.Ok <string>(strValue, "The second line was added successfully")); }) .Then(val => { var sb = new StringBuilder(); return(FunqFactory.Fail <string>("I forgot what number comes after two!!", val)); }) .Catch(resultSoFar => { if (resultSoFar.IsSuccessful) { return(FunqFactory.Ok <string>(resultSoFar.Value, "Everything Was a success")); } // Write out the current error message to a log someLogger = $"I just logged a message. Here is the error:\n{resultSoFar.Message}"; return(FunqFactory.Fail <string>("You suck!", resultSoFar.Value)); }); var expectedSb = new StringBuilder(); expectedSb.AppendLine("First Line"); expectedSb.AppendLine("Second Line"); var expected = expectedSb.ToString(); Assert.AreEqual(expected, someResult.Value); Assert.AreEqual("I just logged a message. Here is the error:\nI forgot what number comes after two!!", someLogger); }