コード例 #1
0
ファイル: Program.cs プロジェクト: vinla/mockapi
        static void Main(string[] args)
        {
            var task = Task.Run(async() =>
            {
                Console.WriteLine("Starting test");

                var path    = "api/person/{id}/details";
                var mockApi = new MockApiClient("http://localhost:5000");
                await mockApi.Setup("GET", path).Returns("{id: {id}}");

                // Perfom an action
                var result = await "http://localhost:5000/api/person/12/details".GetAsync().ReceiveString();


                var calls = (await mockApi.Calls("GET", path)).ToList();

                Console.WriteLine(calls.Count);   // Assert the number of calls made to the end point
                Console.WriteLine(calls[0].Path); // Assert the actual path (for checking url params)
                //Console.WriteLine(calls[0].Body.SelectToken("request.accounts[0].id")); // Assert information sent in the request

                Console.ReadLine();
            });

            task.Wait();
            Console.WriteLine("Test complete");
        }
コード例 #2
0
ファイル: TestSample.cs プロジェクト: vinla/mockapi
        public async void MyWebTest()
        {
            // Arrange
            var path    = "api/person/{id}/details";
            var mockApi = new MockApiClient("http://localhost:56729");
            await mockApi.Setup("GET", path).Returns("{id: {id}}");

            //Act - do something

            //Assert
            var calls = (await mockApi.Calls("GET", path)).ToList();

            Assert.Equal(1, calls.Count);
            Assert.Equal("api/person/12/details", calls[0].Path);
            Assert.Equal("test", calls[0].Body.SelectToken("request.accounts[0].id"));
        }