예제 #1
0
        public static ICard HasCard <TCard>(this SkillResponse response, Predicate <TCard> predicate = null) where TCard : class, ICard
        {
            GuardAgainstNull(nameof(response), response);
            if (response.Response?.Card == null)
            {
                throw new CardMissingException(AlexaAssertMessages.CardNotSet);
            }

            var card = response.Response.Card;

            if (!(card is TCard))
            {
                throw new CardMismatchException(AlexaAssertMessages.Mismatch(typeof(TCard).FullName, card?.GetType().FullName ?? "null"));
            }

            if (predicate != null && !predicate(response.Response.Card as TCard))
            {
                throw new PredicateFailedException();
            }

            return(response.Response.Card);
        }
예제 #2
0
        public static Reprompt HasReprompt <TOutput>(this SkillResponse response, Predicate <TOutput> predicate = null) where TOutput : class, IOutputSpeech
        {
            GuardAgainstNull(nameof(response), response);
            if (response.Response.Reprompt == null)
            {
                throw new RepromptMissingException(AlexaAssertMessages.RepromptNotSet);
            }

            var output = response.Response.Reprompt.OutputSpeech;

            if (!(output is TOutput))
            {
                throw new OutputMismatchException(AlexaAssertMessages.Mismatch(typeof(TOutput).FullName, output?.GetType().FullName ?? "null"));
            }

            if (predicate != null && !predicate(output as TOutput))
            {
                throw new PredicateFailedException();
            }

            return(response.Response.Reprompt);
        }
예제 #3
0
        //TODO: Add tests
        public static TOutput Tells <TOutput>(this SkillResponse response, Predicate <TOutput> predicate = null) where TOutput : class, IOutputSpeech
        {
            GuardAgainstNull(nameof(response), response);
            var shouldEnd = response?.Response?.ShouldEndSession;

            if (!shouldEnd.HasValue || !shouldEnd.Value)
            {
                throw new ShouldEndSessionException(AlexaAssertMessages.TellShouldEndSessionNotFalse);
            }

            var output = response.Response?.OutputSpeech;

            if (!(output is TOutput))
            {
                throw new OutputMismatchException(AlexaAssertMessages.Mismatch(typeof(TOutput).FullName, output?.GetType().FullName ?? "null"));
            }

            if (predicate != null && !predicate(output as TOutput))
            {
                throw new PredicateFailedException();
            }

            return(output as TOutput);
        }