public void ResultActionSafeScope() { int counter = 0; Result result = ResultScope.SafeResult(() => ++ counter); Assert.AreEqual(1, counter); CheckResultOk(result); var thrownException = new Exception("My exception"); int testVar = 12; result = ResultScope.SafeResult( () => { ++counter; if (testVar > 0) { throw thrownException; } ++counter; }); Assert.AreEqual(2, counter); CheckResultFail(result, "My exception", thrownException); Assert.Throws <ArgumentNullException>(() => ResultScope.SafeResult((Action)null)); }
public void CustomResultSafeScope() { var defaultError = new CustomErrorTest { ErrorCode = 51 }; CustomResult <CustomErrorTest> result = ResultScope.SafeCustomResult(Result.CustomOk <CustomErrorTest>, () => defaultError); CheckResultOk(result); result = ResultScope.SafeCustomResult(Result.CustomOk <CustomErrorTest>, defaultError); CheckResultOk(result); result = ResultScope.SafeCustomResult(() => Result.CustomWarn <CustomErrorTest>("My warning"), () => defaultError); CheckResultWarn(result, "My warning"); result = ResultScope.SafeCustomResult(() => Result.CustomWarn <CustomErrorTest>("My warning"), defaultError); CheckResultWarn(result, "My warning"); var errorObject = new CustomErrorTest { ErrorCode = 12 }; result = ResultScope.SafeCustomResult(() => Result.CustomFail("My failure", errorObject), () => defaultError); CheckResultFail(result, "My failure", errorObject); result = ResultScope.SafeCustomResult(() => Result.CustomFail("My failure", errorObject), defaultError); CheckResultFail(result, "My failure", errorObject); var thrownException = new Exception("My exception"); result = ResultScope.SafeCustomResult(() => throw thrownException, () => defaultError); CheckResultFail(result, "My exception", defaultError, thrownException); result = ResultScope.SafeCustomResult(() => throw thrownException, defaultError); CheckResultFail(result, "My exception", defaultError, thrownException); Assert.Throws <ArgumentNullException>(() => ResultScope.SafeCustomResult(null, defaultError)); Assert.Throws <ArgumentNullException>(() => ResultScope.SafeCustomResult(null, () => defaultError)); Assert.Throws <ArgumentNullException>(() => ResultScope.SafeCustomResult(Result.CustomOk <CustomErrorTest>, (CustomErrorTest)null)); Assert.Throws <ArgumentNullException>(() => ResultScope.SafeCustomResult(Result.CustomOk <CustomErrorTest>, (Func <CustomErrorTest>)null)); Assert.Throws <ArgumentNullException>(() => ResultScope.SafeCustomResult(null, (CustomErrorTest)null)); Assert.Throws <ArgumentNullException>(() => ResultScope.SafeCustomResult((Func <CustomResult <CustomErrorTest> >)null, (Func <CustomErrorTest>)null)); }
public void ValueResultSafeScope() { Result <int> result = ResultScope.SafeValueResult(() => Result.Ok(12)); CheckResultOk(result, 12); result = ResultScope.SafeValueResult(() => Result.Warn(42, "My warning")); CheckResultWarn(result, 42, "My warning"); result = ResultScope.SafeValueResult(() => Result.Fail <int>("My failure")); CheckResultFail(result, "My failure"); var thrownException = new Exception("My exception"); result = ResultScope.SafeValueResult <int>(() => throw thrownException); CheckResultFail(result, "My exception", thrownException); Assert.Throws <ArgumentNullException>(() => ResultScope.SafeValueResult((Func <Result <int> >)null)); }
public void ResultSafeScope() { Result result = ResultScope.SafeResult(Result.Ok); CheckResultOk(result); result = ResultScope.SafeResult(() => Result.Warn("My warning")); CheckResultWarn(result, "My warning"); result = ResultScope.SafeResult(() => Result.Fail("My failure")); CheckResultFail(result, "My failure"); var thrownException = new Exception("My exception"); result = ResultScope.SafeResult(() => throw thrownException); CheckResultFail(result, "My exception", thrownException); Assert.Throws <ArgumentNullException>(() => ResultScope.SafeResult(null)); }
public void ValueCustomResultSafeScope() { var defaultError = new CustomErrorTest { ErrorCode = 51 }; Result <int, CustomErrorTest> result = ResultScope.SafeValueCustomResult(() => Result.Ok <int, CustomErrorTest>(42), () => defaultError); CheckResultOk(result, 42); result = ResultScope.SafeValueCustomResult(() => Result.Ok <int, CustomErrorTest>(12), defaultError); CheckResultOk(result, 12); result = ResultScope.SafeValueCustomResult(() => Result.Warn <int, CustomErrorTest>(21, "My warning"), () => defaultError); CheckResultWarn(result, 21, "My warning"); result = ResultScope.SafeValueCustomResult(() => Result.Warn <int, CustomErrorTest>(51, "My warning"), defaultError); CheckResultWarn(result, 51, "My warning"); var errorObject = new CustomErrorTest { ErrorCode = 12 }; result = ResultScope.SafeValueCustomResult(() => Result.Fail <int, CustomErrorTest>("My failure", errorObject), () => defaultError); CheckResultFail(result, "My failure", errorObject); result = ResultScope.SafeValueCustomResult(() => Result.Fail <int, CustomErrorTest>("My failure", errorObject), defaultError); CheckResultFail(result, "My failure", errorObject); var thrownException = new Exception("My exception"); result = ResultScope.SafeValueCustomResult <int, CustomErrorTest>(() => throw thrownException, () => defaultError); CheckResultFail(result, "My exception", defaultError, thrownException); result = ResultScope.SafeValueCustomResult <int, CustomErrorTest>(() => throw thrownException, defaultError); CheckResultFail(result, "My exception", defaultError, thrownException); Assert.Throws <ArgumentNullException>(() => ResultScope.SafeValueCustomResult((Func <Result <int, CustomErrorTest> >)null, defaultError)); Assert.Throws <ArgumentNullException>(() => ResultScope.SafeValueCustomResult((Func <Result <int, CustomErrorTest> >)null, () => defaultError)); Assert.Throws <ArgumentNullException>(() => ResultScope.SafeValueCustomResult(() => Result.Ok <int, CustomErrorTest>(12), (CustomErrorTest)null)); Assert.Throws <ArgumentNullException>(() => ResultScope.SafeValueCustomResult(() => Result.Ok <int, CustomErrorTest>(12), (Func <CustomErrorTest>)null)); Assert.Throws <ArgumentNullException>(() => ResultScope.SafeValueCustomResult((Func <Result <int, CustomErrorTest> >)null, (CustomErrorTest)null)); Assert.Throws <ArgumentNullException>(() => ResultScope.SafeValueCustomResult((Func <Result <int, CustomErrorTest> >)null, (Func <CustomErrorTest>)null)); }
public GrepResult(string sourceFile, ResultScope resultScope) { Scope = resultScope; SourceFile = sourceFile; }
public void ProcessMessage(string message) { switch (wizStep) { case 1: question = message; bot.SendToUser( creator, "Registered question \"" + question + "\"" ); bot.SendToUser( creator, "Enter each option [in brackets] on the same line"); wizStep++; break; case 2: //options = Regex.Split(message, "] ["); //for (int i=0; i< options.Length; i++) // bot.SendToUser(creator, i + ": " + options[i]); string pattern = @"\[(.+?)\]"; MatchCollection mcol = Regex.Matches(message, pattern); options = new string[mcol.Count]; for ( int i = 0; i < mcol.Count; i++ ) options[i] = mcol[i].Groups[1].Value; for ( int i = 0; i < options.Length; i++ ) bot.SendToUser( creator, i + ": " + options[i] ); bot.SendToUser( creator, "Who should be polled? enter a #channel or nicknames separated by spaces" ); wizStep++; break; case 3: scope = message.Split(' '); bot.SendToUser( creator, "Registered " + scope.Length+ " participants."+(scope.Length==1?" ("+scope+")":"") ); bot.SendToUser( creator, "For how many minutes should the poll be active? max is 30" ); wizStep++; break; case 4: int minutes = int.Parse(message); runtime = TimeSpan.FromMinutes( minutes ); bot.SendToUser( creator, "Poll will be active for "+minutes+" minutes" ); bot.SendToUser( creator, "Who should see the results?" ); bot.SendToUser( creator, "1: Just yourself" ); bot.SendToUser( creator, "2: Those who voted" ); bot.SendToUser( creator, "or enter a #channel to publish to" ); wizStep++; break; case 5: if (message == "1") resultScope = ResultScope.Creator; else if (message == "2") resultScope = ResultScope.Participans; else { resultScope = ResultScope.Channel; resultchannel = message; } bot.SendToUser(creator, "Ok, now type \"start\" to start the voting "); wizStep++; break; case 6: if (message == "start") { bot.SendToUser( creator, "Voting started, will end "+DateTime.Now.Add(runtime).ToLongTimeString() ); Start(); } wizStep++; break; } // TODO: vi skal vel også lige have registreret om botten skal sige hvem der kalder til afstemning ...? }