public async Task WaterfallPrompt()
        {
            var activities = TranscriptUtilities.GetFromTestContext(TestContext);

            var convState    = new ConversationState(new MemoryStorage());
            var testProperty = convState.CreateProperty <Dictionary <string, object> >("test", () => new Dictionary <string, object>());

            TestAdapter adapter = new TestAdapter()
                                  .Use(convState);

            await new TestFlow(adapter, async(turnContext) =>
            {
                if (turnContext.Activity.Type == ActivityTypes.Message)
                {
                    var state = await testProperty.GetAsync(turnContext);

                    var dialogs = new DialogSet();
                    dialogs.Add("test-waterfall", Create_Waterfall2());
                    dialogs.Add("number", new NumberPrompt <int>(Culture.English));

                    var dc = dialogs.CreateContext(turnContext, state);

                    await dc.ContinueAsync();

                    if (!turnContext.Responded)
                    {
                        await dc.BeginAsync("test-waterfall");
                    }
                }
            })
            .Test(activities)
            .StartTestAsync();
        }
Beispiel #2
0
        public async Task WaterfallNested()
        {
            var activities = TranscriptUtilities.GetFromTestContext(TestContext);

            TestAdapter adapter = new TestAdapter()
                                  .Use(new ConversationState <Dictionary <string, object> >(new MemoryStorage()));

            await new TestFlow(adapter, async(turnContext) =>
            {
                var dialogs = new DialogSet();
                dialogs.Add("test-waterfall-a", Create_Waterfall3());
                dialogs.Add("test-waterfall-b", Create_Waterfall4());
                dialogs.Add("test-waterfall-c", Create_Waterfall5());

                var state = ConversationState <Dictionary <string, object> > .Get(turnContext);
                var dc    = dialogs.CreateContext(turnContext, state);

                await dc.Continue();

                if (!turnContext.Responded)
                {
                    await dc.Begin("test-waterfall-a");
                }
            })
            .Test(activities)
            .StartTestAsync();
        }
Beispiel #3
0
        public async Task LocaleConvertToEnglish()
        {
            var botLocale = "en-us";

            var activities = TranscriptUtilities.GetFromTestContext(TestContext);

            var userState    = new UserState(new MemoryStorage());
            var userLangProp = userState.CreateProperty <string>("language", () => "en-us");

            TestAdapter adapter = new TestAdapter()
                                  .Use(userState)
                                  .Use(new LocaleConverterMiddleware(userLangProp, botLocale, LocaleConverter.Converter));

            var flow = new TestFlow(adapter, async(context, cancellationToken) =>
            {
                if (context.Activity.Type == ActivityTypes.Message)
                {
                    var userMessage = context.Activity.Text.ToLowerInvariant();
                    if (userMessage.StartsWith("set language "))
                    {
                        await userLangProp.SetAsync(context, userMessage.Substring(13, 5));
                    }
                    else
                    {
                        await context.SendActivityAsync($"message: {context.Activity.Text}");
                    }
                }
            });

            await flow.Test(activities, (expected, actual) =>
            {
                Assert.AreEqual(expected.AsMessageActivity().Text, actual.AsMessageActivity().Text);
            }).StartTestAsync();
        }
Beispiel #4
0
        public async Task CustomStateTest()
        {
            var activities = TranscriptUtilities.GetFromTestContext(TestContext);

            var storage = new MemoryStorage();

            TestAdapter adapter = new TestAdapter()
                                  .Use(new CustomState(storage));

            var flow = new TestFlow(adapter, async(context) => {
                var(command, value) = GetCommandValue(context);
                switch (command)
                {
                case "delete":
                    CustomState.Get(context).Value = null;
                    break;

                case "set":
                    CustomState.Get(context).Value = value;
                    break;

                case "read":
                    await context.SendActivityAsync($"value:{CustomState.Get(context).Value}");
                    break;

                default:
                    await context.SendActivityAsync("bot message");
                    break;
                }
            });

            await flow.Test(activities).StartTestAsync();
        }
Beispiel #5
0
        public async Task TranslateToEnglish()
        {
            if (!EnvironmentVariablesDefined())
            {
                Assert.Inconclusive("Missing Translator Environment variables - Skipping test");
                return;
            }

            var nativeLanguages = new string[] { "en-us" };
            var patterns        = new Dictionary <string, List <string> >();

            var activities = TranscriptUtilities.GetFromTestContext(TestContext);

            TestAdapter adapter = new TestAdapter()
                                  .Use(new UserState <LanguageState>(new MemoryStorage()))
                                  .Use(new TranslationMiddleware(nativeLanguages, translatorKey, patterns, new CustomDictionary(), GetUserLanguage, SetUserLanguage, false));

            var flow = new TestFlow(adapter, async(context) => {
                if (!context.Responded)
                {
                    await context.SendActivityAsync($"message: {context.Activity.Text}");
                }
            });

            await flow.Test(activities).StartTestAsync();
        }
Beispiel #6
0
        /// <summary>
        /// reads the transcript from the binary reader
        /// </summary>
        public static Transcript Read(ExtendedBinaryReader reader, Gene[] cacheGenes, SimpleInterval[] cacheIntrons,
                                      SimpleInterval[] cacheMirnas, string[] cachePeptideSeqs)
        {
            // transcript
            var referenceIndex = reader.ReadUInt16();
            var start          = reader.ReadOptInt32();
            var end            = reader.ReadOptInt32();
            var id             = CompactId.Read(reader);

            // gene
            var geneIndex = reader.ReadOptInt32();
            var gene      = cacheGenes[geneIndex];

            // encoded data
            var encoded = new EncodedTranscriptData(reader.ReadUInt16(), reader.ReadByte());

            // exons & introns
            var introns  = encoded.HasIntrons  ? ReadIndices(reader, cacheIntrons) : null;
            var cdnaMaps = encoded.HasCdnaMaps ? ReadCdnaMaps(reader)              : null;

            // protein function predictions
            int siftIndex     = encoded.HasSift     ? reader.ReadOptInt32() : -1;
            int polyphenIndex = encoded.HasPolyPhen ? reader.ReadOptInt32() : -1;

            // translation
            var translation = encoded.HasTranslation ? Translation.Read(reader, cachePeptideSeqs) : null;

            // attributes
            var mirnas = encoded.HasMirnas ? ReadIndices(reader, cacheMirnas) : null;

            return(new Transcript(referenceIndex, start, end, id, encoded.Version, translation, encoded.BioType,
                                  gene, TranscriptUtilities.GetTotalExonLength(cdnaMaps), encoded.StartExonPhase, encoded.IsCanonical,
                                  introns, mirnas, cdnaMaps, siftIndex, polyphenIndex, encoded.TranscriptSource));
        }
Beispiel #7
0
        public async Task DateTimePrompt()
        {
            var activities = TranscriptUtilities.GetFromTestContext(TestContext);

            TestAdapter adapter = new TestAdapter()
                                  .Use(new ConversationState <Dictionary <string, object> >(new MemoryStorage()));

            await new TestFlow(adapter, async(turnContext) =>
            {
                var state  = ConversationState <Dictionary <string, object> > .Get(turnContext);
                var prompt = new DateTimePrompt(Culture.English);

                var dialogCompletion = await prompt.Continue(turnContext, state);
                if (!dialogCompletion.IsActive && !dialogCompletion.IsCompleted)
                {
                    await prompt.Begin(turnContext, state, new PromptOptions {
                        PromptString = "What date would you like?", RetryPromptString = "Sorry, but that is not a date. What date would you like?"
                    });
                }
                else if (dialogCompletion.IsCompleted)
                {
                    var dateTimeResult = (DateTimeResult)dialogCompletion.Result;
                    var resolution     = dateTimeResult.Resolution.First();
                    var reply          = $"Timex:'{resolution.Timex}' Value:'{resolution.Value}'";
                    await turnContext.SendActivityAsync(reply);
                }
            })
            .Test(activities)
            .StartTestAsync();
        }
Beispiel #8
0
        public async Task AttachmentPrompt()
        {
            var activities = TranscriptUtilities.GetFromTestContext(TestContext);

            TestAdapter adapter = new TestAdapter()
                                  .Use(new ConversationState <Dictionary <string, object> >(new MemoryStorage()));

            await new TestFlow(adapter, async(turnContext) =>
            {
                var state  = ConversationState <Dictionary <string, object> > .Get(turnContext);
                var prompt = new AttachmentPrompt();

                var dialogCompletion = await prompt.Continue(turnContext, state);
                if (!dialogCompletion.IsActive && !dialogCompletion.IsCompleted)
                {
                    await prompt.Begin(turnContext, state, new PromptOptions {
                        PromptString = "please add an attachment."
                    });
                }
                else if (dialogCompletion.IsCompleted)
                {
                    var attachmentResult = (AttachmentResult)dialogCompletion.Result;
                    var reply            = (string)attachmentResult.Attachments.First().Content;
                    await turnContext.SendActivityAsync(reply);
                }
            })
            .Test(activities)
            .StartTestAsync();
        }
        public async Task WaterfallNested()
        {
            var activities = TranscriptUtilities.GetFromTestContext(TestContext);

            var convState    = new ConversationState(new MemoryStorage());
            var testProperty = convState.CreateProperty <Dictionary <string, object> >("test");

            var adapter = new TestAdapter()
                          .Use(convState);

            await new TestFlow(adapter, async(turnContext, cancellationToken) =>
            {
                if (turnContext.Activity.Type == ActivityTypes.Message)
                {
                    var state   = await testProperty.GetAsync(turnContext, () => new Dictionary <string, object>());
                    var dialogs = new DialogSet();
                    dialogs.Add("test-waterfall-a", Create_Waterfall3());
                    dialogs.Add("test-waterfall-b", Create_Waterfall4());
                    dialogs.Add("test-waterfall-c", Create_Waterfall5());

                    var dc = dialogs.CreateContext(turnContext, state);

                    await dc.ContinueAsync();

                    if (!turnContext.Responded)
                    {
                        await dc.BeginAsync("test-waterfall-a");
                    }
                }
            })
            .Test(activities)
            .StartTestAsync();
        }
Beispiel #10
0
        public void FinalizeAndAddAnnotationObject(Transcript transcript, TranscriptAnnotation ta, string[] consequences)
        {
            if (!ta.AlternateAllele.IsStructuralVariant)
            {
                _currTranscript.ComplementaryDnaPosition = GetCdnaRangeString(ta);
                _currTranscript.HgvsCodingSequenceName   = ta.HgvsCodingSequenceName;

                if (ta.HasValidCdnaCodingStart)
                {
                    _currTranscript.ProteinID = TranscriptUtilities.GetProteinId(transcript);
                }
            }
            else
            {
                _currTranscript.ProteinID = ta.HasValidCdnaCodingStart ? TranscriptUtilities.GetProteinId(transcript) : null;
                if (ta.GeneFusionAnnotations != null && ta.GeneFusionAnnotations.Count == 1)
                {
                    var sb = new StringBuilder();
                    ta.GeneFusionAnnotations.First().SerializeJson(sb);
                    _currTranscript.GeneFusion = sb.ToString();
                }
                else if (ta.GeneFusionAnnotations != null && ta.GeneFusionAnnotations.Count > 1)
                {
                    throw new Exception("has mutiple gene fusions");
                }
            }

            _currTranscript.Consequence = consequences;
            _currJsonVariant.AddTranscript(_currTranscript, transcript.TranscriptSource);
        }
        public async Task Waterfall()
        {
            var activities = TranscriptUtilities.GetFromTestContext(TestContext);

            var convState    = new ConversationState(new MemoryStorage());
            var testProperty = convState.CreateProperty <Dictionary <string, object> >("test");

            var adapter = new TestAdapter()
                          .Use(convState);

            await new TestFlow(adapter, async(turnContext, cancellationToken) =>
            {
                if (turnContext.Activity.Type == ActivityTypes.Message)
                {
                    var state = await testProperty.GetAsync(turnContext, () => new Dictionary <string, object>());

                    var waterfall = new Waterfall(new WaterfallStep[]
                    {
                        async(dc, args, next) => { await dc.Context.SendActivityAsync("step1"); },
                        async(dc, args, next) => { await dc.Context.SendActivityAsync("step2"); },
                        async(dc, args, next) => { await dc.Context.SendActivityAsync("step3"); },
                    });


                    var dialogCompletion = await waterfall.ContinueAsync(turnContext, state);
                    if (!dialogCompletion.IsActive && !dialogCompletion.IsCompleted)
                    {
                        await waterfall.BeginAsync(turnContext, state);
                    }
                }
            })
            .Test(activities)
            .StartTestAsync();
        }
Beispiel #12
0
        /// <summary>
        /// parses the relevant data from each mapper unit object
        /// </summary>
        public static (int Start, int End, MapperUnitType Type) Parse(ObjectValueNode objectValue)
        {
            int start = -1;
            int end   = -1;
            var type  = MapperUnitType.Unknown;

            foreach (var node in objectValue.Values)
            {
                // sanity check: make sure we know about the keys are used for
                if (!KnownKeys.Contains(node.Key))
                {
                    throw new InvalidDataException($"Encountered an unknown key in the mapper unit object: {node.Key}");
                }

                switch (node.Key)
                {
                case ImportKeys.Id:
                    type = TranscriptUtilities.GetMapperUnitType(node);
                    break;

                case ImportKeys.End:
                    end = node.GetInt32();
                    break;

                case ImportKeys.Start:
                    start = node.GetInt32();
                    break;

                default:
                    throw new InvalidDataException($"Unknown key found: {node.Key}");
                }
            }

            return(start, end, type);
        }
        public async Task AttachmentPrompt()
        {
            var activities   = TranscriptUtilities.GetFromTestContext(TestContext);
            var convState    = new ConversationState(new MemoryStorage());
            var testProperty = convState.CreateProperty <Dictionary <string, object> >("test");

            var adapter = new TestAdapter()
                          .Use(convState);

            await new TestFlow(adapter, async(turnContext, cancellationToken) =>
            {
                if (turnContext.Activity.Type == ActivityTypes.Message)
                {
                    var state  = await testProperty.GetAsync(turnContext, () => new Dictionary <string, object>());
                    var prompt = new AttachmentPrompt();

                    var dialogCompletion = await prompt.ContinueAsync(turnContext, state);
                    if (!dialogCompletion.IsActive && !dialogCompletion.IsCompleted)
                    {
                        await prompt.BeginAsync(turnContext, state, new PromptOptions {
                            PromptString = "please add an attachment."
                        });
                    }
                    else if (dialogCompletion.IsCompleted)
                    {
                        var attachmentResult = (AttachmentResult)dialogCompletion.Result;
                        var reply            = (string)attachmentResult.Attachments.First().Content;
                        await turnContext.SendActivityAsync(reply);
                    }
                }
            })
            .Test(activities)
            .StartTestAsync();
        }
Beispiel #14
0
        public async Task TranslateToUserLanguage()
        {
            if (!EnvironmentVariablesDefined())
            {
                Assert.Inconclusive("Missing Translator Environment variables - Skipping test");
                return;
            }

            var nativeLanguages = new string[] { };
            var patterns        = new Dictionary <string, List <string> >();

            var activities   = TranscriptUtilities.GetFromTestContext(TestContext);
            var userState    = new UserState(new MemoryStorage());
            var userLangProp = userState.CreateProperty <string>("language");

            TestAdapter adapter = new TestAdapter()
                                  .Use(userState)
                                  .Use(new TranslationMiddleware(nativeLanguages, translatorKey, patterns, new CustomDictionary(), userLangProp, true));

            var flow = new TestFlow(adapter, async(context, cancellationToken) =>
            {
                if (!context.Responded)
                {
                    await context.SendActivityAsync($"message: {context.Activity.Text}");
                }
            });

            await flow.Test(activities).StartTestAsync();
        }
Beispiel #15
0
        public async Task Waterfall()
        {
            var activities = TranscriptUtilities.GetFromTestContext(TestContext);

            TestAdapter adapter = new TestAdapter()
                                  .Use(new ConversationState <Dictionary <string, object> >(new MemoryStorage()));

            await new TestFlow(adapter, async(turnContext) =>
            {
                var waterfall = new Waterfall(new WaterfallStep[]
                {
                    async(dc, args, next) => { await dc.Context.SendActivityAsync("step1"); },
                    async(dc, args, next) => { await dc.Context.SendActivityAsync("step2"); },
                    async(dc, args, next) => { await dc.Context.SendActivityAsync("step3"); },
                });

                var state = ConversationState <Dictionary <string, object> > .Get(turnContext);

                var dialogCompletion = await waterfall.Continue(turnContext, state);
                if (!dialogCompletion.IsActive && !dialogCompletion.IsCompleted)
                {
                    await waterfall.Begin(turnContext, state);
                }
            })
            .Test(activities)
            .StartTestAsync();
        }
Beispiel #16
0
            public SvOverlapTranscript(DataStructures.Transcript transcript, VariantAlternateAllele altAllele)
            {
                TranscriptID = TranscriptUtilities.GetTranscriptId(transcript);
                IsCanonical  = transcript.IsCanonical ? "true" : null;
                Hgnc         = transcript.Gene.Symbol;
                var isFullOverlap = altAllele.Start <= transcript.Start && altAllele.End >= transcript.End;

                IsPartialOverlap = isFullOverlap ? null : "true";
            }
Beispiel #17
0
        private void CreateTranscriptDictionary(List <Transcript> transcripts)
        {
            _transcriptsById.Clear();

            foreach (var transcript in transcripts)
            {
                _transcriptsById[TranscriptUtilities.GetTranscriptId(transcript)] = transcript;
            }
        }
Beispiel #18
0
        /// <summary>
        /// returns a new exon given an ObjectValue
        /// </summary>
        public static DataStructures.VEP.Exon Parse(ObjectValue objectValue, ushort currentReferenceIndex)
        {
            bool onReverseStrand = false;

            int  end   = -1;
            byte?phase = null;
            int  start = -1;

            string stableId = null;

            // loop over all of the key/value pairs in the exon object
            foreach (AbstractData ad in objectValue)
            {
                // sanity check: make sure we know about the keys are used for
                if (!KnownKeys.Contains(ad.Key))
                {
                    throw new GeneralException($"Encountered an unknown key in the dumper mapper object: {ad.Key}");
                }

                // handle each key
                switch (ad.Key)
                {
                case Transcript.EndKey:
                    end = DumperUtilities.GetInt32(ad);
                    break;

                case EndPhaseKey:
                    break;

                case PhaseKey:
                    int phaseInt = DumperUtilities.GetInt32(ad);
                    if (phaseInt != -1)
                    {
                        phase = (byte)phaseInt;
                    }
                    break;

                case Transcript.StableIdKey:
                    stableId = DumperUtilities.GetString(ad);
                    break;

                case Transcript.StartKey:
                    start = DumperUtilities.GetInt32(ad);
                    break;

                case Transcript.StrandKey:
                    onReverseStrand = TranscriptUtilities.GetStrand(ad);
                    break;

                default:
                    throw new GeneralException($"Unknown key found: {ad.Key}");
                }
            }

            return(new DataStructures.VEP.Exon(currentReferenceIndex, start, end, stableId, onReverseStrand, phase));
        }
        public async Task NumberPrompt()
        {
            var activities = TranscriptUtilities.GetFromTestContext(TestContext);


            PromptValidatorEx.PromptValidator <NumberResult <int> > validator = async(ctx, result) =>
            {
                if (result.Value < 0)
                {
                    result.Status = PromptStatus.TooSmall;
                }
                if (result.Value > 100)
                {
                    result.Status = PromptStatus.TooBig;
                }
                await Task.CompletedTask;
            };

            var convState    = new ConversationState(new MemoryStorage());
            var testProperty = convState.CreateProperty <Dictionary <string, object> >("test");

            var adapter = new TestAdapter()
                          .Use(convState);

            await new TestFlow(adapter, async(turnContext, cancellationToken) =>
            {
                if (turnContext.Activity.Type == ActivityTypes.Message)
                {
                    var state  = await testProperty.GetAsync(turnContext, () => new Dictionary <string, object>());
                    var prompt = new NumberPrompt <int>(Culture.English, validator);

                    var dialogCompletion = await prompt.ContinueAsync(turnContext, state);
                    if (!dialogCompletion.IsActive && !dialogCompletion.IsCompleted)
                    {
                        await prompt.BeginAsync(turnContext, state,
                                                new PromptOptions
                        {
                            PromptString      = "Enter a number.",
                            RetryPromptString = "You must enter a valid positive number less than 100."
                        });
                    }
                    else if (dialogCompletion.IsCompleted)
                    {
                        var numberResult = (NumberResult <int>)dialogCompletion.Result;
                        await turnContext.SendActivityAsync($"Bot received the number '{numberResult.Value}'.");
                    }
                }
            })
            .Test(activities)
            .StartTestAsync();
        }
        public async Task ConversationStateTest()
        {
            var testName   = "ConversationStateTest";
            var activities = TranscriptUtilities.GetActivitiesFromFile(ClassName, testName);

            var storage = new MemoryStorage();

            var convoState   = new ConversationState(new MemoryStorage());
            var testProperty = convoState.CreateProperty <ConversationStateObject>("test");

            var adapter = new TestAdapter(TestAdapter.CreateConversation(testName))
                          .Use(new AutoSaveStateMiddleware(convoState));

            var flow = new TestFlow(adapter, async(context, cancellationToken) =>
            {
                if (context.Activity.Type == ActivityTypes.Message)
                {
                    var(command, value) = GetCommandValue(context);
                    switch (command)
                    {
                    case "delete":
                        await testProperty.DeleteAsync(context);
                        break;

                    case "set":
                        {
                            var data   = await testProperty.GetAsync(context, () => new ConversationStateObject());
                            data.Value = value;
                            await testProperty.SetAsync(context, data);
                        }

                        break;

                    case "read":
                        {
                            var data = await testProperty.GetAsync(context, () => new ConversationStateObject());
                            await context.SendActivityAsync($"value:{data.Value}");
                        }

                        break;

                    default:
                        await context.SendActivityAsync("bot message");
                        break;
                    }
                }
            });

            await flow.Test(activities).StartTestAsync();
        }
Beispiel #21
0
        private static string GetAlternateCds(string cacheStub, string transcriptId, string ensemblRefName, int start, int end, string allele)
        {
            var transcript = DataUtilities.GetTranscript(cacheStub, transcriptId);

            Assert.NotNull(transcript);

            var sequence = DataUtilities.GetCompressedSequence(cacheStub, ensemblRefName);

            Assert.NotNull(sequence);

            return(TranscriptUtilities.GetAlternateCds(sequence, start, end, allele, transcript.CdnaMaps,
                                                       transcript.Gene.OnReverseStrand, transcript.StartExonPhase,
                                                       transcript.Translation.CodingRegion.CdnaStart));
        }
Beispiel #22
0
        public static (int Start, int End, string Id, bool OnReverseStrand) Parse(IImportNode importNode)
        {
            var objectValue = importNode.GetObjectValueNode();

            if (objectValue == null)
            {
                throw new InvalidDataException("Encountered a gene import node that could not be converted to an object value node.");
            }

            int    start           = -1;
            int    end             = -1;
            string stableId        = null;
            var    onReverseStrand = false;

            foreach (var node in objectValue.Values)
            {
                // sanity check: make sure we know about the keys are used for
                if (!KnownKeys.Contains(node.Key))
                {
                    throw new InvalidDataException($"Encountered an unknown key in the dumper gene object: {node.Key}");
                }

                // handle each key
                switch (node.Key)
                {
                case ImportKeys.End:
                    end = node.GetInt32();
                    break;

                case ImportKeys.StableId:
                    stableId = node.GetString();
                    break;

                case ImportKeys.Start:
                    start = node.GetInt32();
                    break;

                case ImportKeys.Strand:
                    onReverseStrand = TranscriptUtilities.GetStrand(node);
                    break;

                default:
                    throw new InvalidDataException($"Unknown key found: {node.Key}");
                }
            }

            return(start, end, stableId, onReverseStrand);
        }
        public async Task TextPrompt()
        {
            var activities = TranscriptUtilities.GetFromTestContext(TestContext);

            PromptValidatorEx.PromptValidator <TextResult> validator = async(ctx, result) =>
            {
                if (result.Value.Length <= 3)
                {
                    result.Status = PromptStatus.TooSmall;
                }
                await Task.CompletedTask;
            };

            var convState    = new ConversationState(new MemoryStorage());
            var testProperty = convState.CreateProperty <Dictionary <string, object> >("test");

            var adapter = new TestAdapter()
                          .Use(convState);

            await new TestFlow(adapter, async(turnContext, cancellationToken) =>
            {
                if (turnContext.Activity.Type == ActivityTypes.Message)
                {
                    var state  = await testProperty.GetAsync(turnContext, () => new Dictionary <string, object>());
                    var prompt = new TextPrompt(validator);

                    var dialogCompletion = await prompt.ContinueAsync(turnContext, state);
                    if (!dialogCompletion.IsActive && !dialogCompletion.IsCompleted)
                    {
                        await prompt.BeginAsync(turnContext, state,
                                                new PromptOptions
                        {
                            PromptString      = "Enter some text.",
                            RetryPromptString = "Make sure the text is greater than three characters."
                        });
                    }
                    else if (dialogCompletion.IsCompleted)
                    {
                        var textResult = (TextResult)dialogCompletion.Result;
                        await turnContext.SendActivityAsync($"Bot received the text '{textResult.Value}'.");
                    }
                }
            })
            .Test(activities)
            .StartTestAsync();
        }
        public async Task ConfirmPrompt()
        {
            var activities = TranscriptUtilities.GetFromTestContext(TestContext);

            var convState    = new ConversationState(new MemoryStorage());
            var testProperty = convState.CreateProperty <Dictionary <string, object> >("test");

            var adapter = new TestAdapter()
                          .Use(convState);

            await new TestFlow(adapter, async(turnContext, cancellationToken) =>
            {
                if (turnContext.Activity.Type == ActivityTypes.Message)
                {
                    var state  = await testProperty.GetAsync(turnContext, () => new Dictionary <string, object>());
                    var prompt = new ConfirmPrompt(Culture.English)
                    {
                        Style = ListStyle.None
                    };

                    var dialogCompletion = await prompt.ContinueAsync(turnContext, state);
                    if (!dialogCompletion.IsActive && !dialogCompletion.IsCompleted)
                    {
                        await prompt.BeginAsync(turnContext, state,
                                                new PromptOptions
                        {
                            PromptString      = "Please confirm.",
                            RetryPromptString = "Please confirm, say 'yes' or 'no' or something like that."
                        });
                    }
                    else if (dialogCompletion.IsCompleted)
                    {
                        if (((ConfirmResult)dialogCompletion.Result).Confirmation)
                        {
                            await turnContext.SendActivityAsync("Confirmed.");
                        }
                        else
                        {
                            await turnContext.SendActivityAsync("Not confirmed.");
                        }
                    }
                }
            })
            .Test(activities)
            .StartTestAsync();
        }
        public async Task UserStateTest()
        {
            var activities = TranscriptUtilities.GetFromTestContext(TestContext);

            var userState    = new UserState(new MemoryStorage());
            var testProperty = userState.CreateProperty <UserStateObject>("test");

            var adapter = new TestAdapter()
                          .Use(userState);

            var flow = new TestFlow(adapter, async(context, cancellationToken) =>
            {
                if (context.Activity.Type == ActivityTypes.Message)
                {
                    var(command, value) = GetCommandValue(context);
                    switch (command)
                    {
                    case "delete":
                        await testProperty.DeleteAsync(context);
                        break;

                    case "set":
                        {
                            var data   = await testProperty.GetAsync(context, () => new UserStateObject());
                            data.Value = value;
                            await testProperty.SetAsync(context, data);
                        }
                        break;

                    case "read":
                        {
                            var data = await testProperty.GetAsync(context, () => new UserStateObject());
                            await context.SendActivityAsync($"value:{data.Value}");
                        }
                        break;

                    default:
                        await context.SendActivityAsync("bot message");
                        break;
                    }
                }
            });

            await flow.Test(activities).StartTestAsync();
        }
Beispiel #26
0
        public async Task BotAdapted_Bracketing()
        {
            var testName   = "BotAdapted_Bracketing";
            var activities = TranscriptUtilities.GetActivitiesFromFile(ClassName, testName);

            TestAdapter adapter = new TestAdapter(TestAdapter.CreateConversation(testName))
                                  .Use(new BeforeAfterMiddleware());

            adapter.OnTurnError = async(context, exception) =>
            {
                await context.SendActivityAsync($"Caught: {exception.Message}");

                return;
            };

            var flow = new TestFlow(adapter, async(context, cancellationToken) =>
            {
                switch (context.Activity.Type)
                {
                case ActivityTypes.Message:
                    {
                        var userMessage = context.Activity.AsMessageActivity()?.Text;
                        switch (userMessage)
                        {
                        case "use middleware":
                            await context.SendActivityAsync("using middleware");
                            break;

                        case "catch exception":
                            await context.SendActivityAsync("generating exception");
                            throw new Exception("exception to catch");
                        }
                    }

                    break;

                default:
                    await context.SendActivityAsync(context.Activity.Type);
                    break;
                }
            });

            await flow.Test(activities).StartTestAsync();
        }
Beispiel #27
0
        public void AddFlankingTranscript(Transcript transcript, TranscriptAnnotation ta, string[] consequences)
        {
            _currTranscript = new JsonVariant.Transcript
            {
                IsCanonical  = transcript.IsCanonical ? TrueTag : null,
                Consequence  = consequences,
                ProteinID    = ta.HasValidCdnaCodingStart ? TranscriptUtilities.GetProteinId(transcript) : null,
                TranscriptID = TranscriptUtilities.GetTranscriptId(transcript),
                BioType      = BioTypeUtilities.GetBiotypeDescription(transcript.BioType),
                Gene         = transcript.TranscriptSource == TranscriptDataSource.Ensembl ? transcript.Gene.EnsemblId.ToString() : transcript.Gene.EntrezGeneId.ToString(),
                Hgnc         = transcript.Gene.Symbol
            };

            if (ta.HasValidCdnaStart && ta.HasValidCdnaEnd)
            {
                _currTranscript.ComplementaryDnaPosition = GetCdnaRangeString(ta);
            }

            _currJsonVariant.AddTranscript(_currTranscript, transcript.TranscriptSource);
        }
Beispiel #28
0
        public async Task LocaleConvertToEnglish()
        {
            var botLocale = "en-us";

            var activities = TranscriptUtilities.GetFromTestContext(TestContext);

            TestAdapter adapter = new TestAdapter()
                                  .Use(new UserState <LanguageState>(new MemoryStorage()))
                                  .Use(new LocaleConverterMiddleware(GetUserLanguage, SetUserLanguage, botLocale, LocaleConverter.Converter));

            var flow = new TestFlow(adapter, async(context) => {
                if (!context.Responded)
                {
                    await context.SendActivityAsync($"message: {context.Activity.Text}");
                }
            });

            await flow.Test(activities, (expected, actual) => {
                Assert.AreEqual(expected.AsMessageActivity().Text, actual.AsMessageActivity().Text);
            }).StartTestAsync();
        }
Beispiel #29
0
        public void CreateAnnotationObject(Transcript transcript, VariantAlternateAllele altAllele)
        {
            // while annotating alternate allele, the first output function to be called is AddExonData.
            // So, we set the current json variant and transcript here.
            // they will subsequently be used in other output functions.
            FindCorrespondingJsonVariant(altAllele);

            if (_currJsonVariant == null)
            {
                throw new GeneralException("Cannot find jsonVariant corresponding to alternate allele");
            }

            _currTranscript = new JsonVariant.Transcript
            {
                IsCanonical  = transcript.IsCanonical ? TrueTag : null,
                TranscriptID = TranscriptUtilities.GetTranscriptId(transcript),
                BioType      = BioTypeUtilities.GetBiotypeDescription(transcript.BioType),
                Gene         = transcript.TranscriptSource == TranscriptDataSource.Ensembl ? transcript.Gene.EnsemblId.ToString() : transcript.Gene.EntrezGeneId.ToString(),
                Hgnc         = transcript.Gene.Symbol
            };
        }
Beispiel #30
0
 /// <summary>
 /// constructor
 /// </summary>
 public Transcript(ushort referenceIndex, int start, int end, CompactId id, byte version,
                   Translation translation, BioType bioType, Gene gene, int totalExonLength, byte startExonPhase,
                   bool isCanonical, SimpleInterval[] introns, SimpleInterval[] microRnas, CdnaCoordinateMap[] cdnaMaps,
                   int siftIndex, int polyPhenIndex, TranscriptDataSource transcriptSource) : base(referenceIndex, start, end)
 {
     Id               = id;
     Version          = version;
     Translation      = translation;
     BioType          = bioType;
     Gene             = gene;
     TotalExonLength  = totalExonLength;
     StartExonPhase   = startExonPhase;
     IsCanonical      = isCanonical;
     Introns          = introns;
     MicroRnas        = microRnas;
     CdnaMaps         = cdnaMaps;
     SiftIndex        = siftIndex;
     PolyPhenIndex    = polyPhenIndex;
     TranscriptSource = transcriptSource;
     TotalExonLength  = TranscriptUtilities.GetTotalExonLength(cdnaMaps);
 }