Example #1
0
        public async void Test_InnerApiNoUsers()
        {
            var mockLog = new Mock <ILogger>();

            string cdata = "[]";
            string adata = "[]";

            var mock = new Mock <IRestApi>();

            mock.Setup(m => m.GetEndPointAsync(It.Is <string>(s => s.Equals(ALL_USERS_ENDPOINT)))).Returns(Task.FromResult(adata));
            mock.Setup(m => m.GetEndPointAsync(It.Is <string>(s => s.Equals(CTY_USERS_ENDPOINT)))).Returns(Task.FromResult(cdata));

            var api = new PeopleApi();

            var res = await api.GetLondonPeople(mock.Object, mockLog.Object);

            var okObjectResult = res as OkObjectResult;

            Assert.NotNull(okObjectResult);

            var    json = okObjectResult.Value as string;
            JArray a    = JArray.Parse(json);

            Assert.True(a.Count == 0);
        }
Example #2
0
        public async void Test_InnerApiAllReturnsUsers()
        {
            var mockLog = new Mock <ILogger>();

            string cdata = "[]";
            string adata = "[{\"id\": 266,\"first_name\": \"Ancell\",\"last_name\": \"Garnsworthy\",\"email\": \"[email protected]\",\"ip_address\": \"67.4.69.137\",\"latitude\": 51.6553959,\"longitude\": 0.057255}]";

            var mock = new Mock <IRestApi>();

            mock.Setup(m => m.GetEndPointAsync(It.Is <string>(s => s.Equals(ALL_USERS_ENDPOINT)))).Returns(Task.FromResult(adata));
            mock.Setup(m => m.GetEndPointAsync(It.Is <string>(s => s.Equals(CTY_USERS_ENDPOINT)))).Returns(Task.FromResult(cdata));

            var api = new PeopleApi();

            var res = await api.GetLondonPeople(mock.Object, mockLog.Object);

            var okObjectResult = res as OkObjectResult;

            Assert.NotNull(okObjectResult);

            var    json = okObjectResult.Value as string;
            JArray a    = JArray.Parse(json);

            Assert.True(a.Count == 1);
        }
Example #3
0
        public async void Test_InnerApiWrongFormat()
        {
            var mockLog = new Mock <ILogger>();

            string cdata = "[]";
            string adata = "{\"id\": 266,\"first_name\": \"Ancell\",\"last_name\": \"Garnsworthy\",\"email\": \"[email protected]\",\"ip_address\": \"67.4.69.137\",\"latitude\": 51.6553959,\"longitude\": 0.057255}";

            var mock = new Mock <IRestApi>();

            mock.Setup(m => m.GetEndPointAsync(It.Is <string>(s => s.Equals(ALL_USERS_ENDPOINT)))).Returns(Task.FromResult(adata));
            mock.Setup(m => m.GetEndPointAsync(It.Is <string>(s => s.Equals(CTY_USERS_ENDPOINT)))).Returns(Task.FromResult(cdata));

            var api = new PeopleApi();

            var res = await api.GetLondonPeople(mock.Object, mockLog.Object);

            var exceptionResult = res as ExceptionResult;

            Assert.NotNull(exceptionResult);
        }