예제 #1
0
        public void The_Then_Method_Should_Chain_Together_Strings()
        {
            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();
                sb.Append(val);
                sb.AppendLine("Third Line");
                var strValue = sb.ToString();
                return(FunqFactory.Ok <string>(strValue, "The third line was added successfully"));
            });
            var expectedSb = new StringBuilder();

            expectedSb.AppendLine("First Line");
            expectedSb.AppendLine("Second Line");
            expectedSb.AppendLine("Third Line");
            var expected = expectedSb.ToString();

            Assert.AreEqual(expected, someResult.Value);
        }
예제 #2
0
 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"));
        }
예제 #4
0
        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);
        }
        public async Task <FunqResult> DeleteMinionAsync(Guid minionId)
        {
            await _appCache.RemoveAsync(minionId.ToString(), typeof(Minion).Name);

            return(FunqFactory.KeepGroovin("Deleted the minion"));
        }
        public async Task <FunqResult <Minion> > CreateMinionAsync(Minion minion)
        {
            await _appCache.AddOrUpdateAsync(minion.Id.ToString(), minion, null, typeof(Minion).Name).ConfigureAwait(false);

            return(FunqFactory.KeepGroovin(minion, "Succesfully added minion"));
        }