public async Task Speech_ParseNOk()
        {
            var fixture = new Fixture();

            fixture.Behaviors
            .OfType <ThrowingRecursionBehavior>()
            .ToList()
            .ForEach(b => fixture.Behaviors.Remove(b));
            fixture.Behaviors.Add(new OmitOnRecursionBehavior());

            using (var test = new Flurl.Http.Testing.HttpTest())
            {
                test.RespondWith(@"{""error"":""could not do something""}", 502);

                var loggerMock = new Mock <ILogger <WitAi.WitAiClient> >(MockBehavior.Loose);
                var config     = new Core.Configuration.WitAiConfiguration
                {
                    ApiKey     = "someapikey",
                    ApiVersion = "someapiversion",
                    BaseUrl    = "http://someurl.fqdn.local"
                };
                var options = new Mock <IOptionsSnapshot <Core.Configuration.WitAiConfiguration> >(MockBehavior.Strict);
                options.Setup(o => o.Value)
                .Returns(() => config);

                var sut = new WitAi.WitAiClient(loggerMock.Object, options.Object);

                var task = sut.ParseSpeech(new byte[] { 0x30, 0x60, 0x1f, 0x4f });
                await Assert.ThrowsAsync <Flurl.Http.FlurlHttpException>(() => task);
            }
        }
Exemple #2
0
        public async Task Should_Return_CrimesFromRaleighOpenData()
        {
            using (var httpTest = new Flurl.Http.Testing.HttpTest())
            {
                // Arrange
                httpTest.RespondWith("Some Error", status: 500);

                // Act
                var response = await _client.GetAsync("/api/raleigh/crime");

                var responseString = await response.Content.ReadAsStringAsync();

                // Assert
                Assert.IsTrue(responseString.Contains("Some Error"));
                Assert.AreEqual(HttpStatusCode.InternalServerError, response.StatusCode);
                httpTest.ShouldHaveCalled("https://data.raleighnc.gov/resource/3bhm-we7a.json");
            }
        }
        public async Task Should_Return_CrimesFromRaleighOpenData()
        {
            using (var httpTest = new Flurl.Http.Testing.HttpTest())
            {
                // Arrange
                httpTest.RespondWith(_json);

                // Act
                var response = await _client.GetAsync("/api/raleigh/crime");

                response.EnsureSuccessStatusCode();
                var responseString = await response.Content.ReadAsStringAsync();

                // Assert
                Assert.IsTrue(responseString.Contains("Traffic/DWI (Driving While Impaired)"));
                httpTest.ShouldHaveCalled("https://data.raleighnc.gov/resource/3bhm-we7a.json");
            }
        }
        public async Task Should_Return_CrimesFromRaleighOpenData_When_Filtered()
        {
            using (var httpTest = new Flurl.Http.Testing.HttpTest())
            {
                // Arrange
                httpTest.RespondWith(_json);

                // Act
                var response = await _client.GetAsync("/api/raleigh/crime?query=Drug");

                response.EnsureSuccessStatusCode();
                var responseString = await response.Content.ReadAsStringAsync();

                // Assert
                Assert.IsFalse(responseString.Contains("Traffic/DWI (Driving While Impaired)"), "Filtered list should not have Traffic/DWI");
                Assert.IsTrue(responseString.Contains("Drug Violation/Misdemeanor"), "Fitered list should only have Drug crimes");
                httpTest.ShouldHaveCalled("https://data.raleighnc.gov/resource/3bhm-we7a.json");
            }
        }