예제 #1
0
        public async Task PostShouldReturnTrueFor2()
        {
            GeoLocation FirstGeoLoc = new GeoLocation("31.60.48.215", "Ochota", "Poland", "Europe")
            {
                ID = 1
            };
            GeoLocation SecondGeoLoc = new GeoLocation("134.201.250.155", "Los Angeles", "USA", "North America")
            {
                ID = 2
            };
            var builder = new DbContextOptionsBuilder <GeoLocApiContext>().UseInMemoryDatabase(Guid.NewGuid().ToString());

            using var context = new GeoLocApiContext(builder.Options);
            context.GeoLocations.Add(FirstGeoLoc);
            context.SaveChanges();

            var controller = new GeoLocationsController(context);
            await controller.PostGeoLocation(new InputModel()
            {
                ip = "134.201.250.155"
            });

            int num = await context.GeoLocations.CountAsync();

            Assert.Equal(2, num);
        }
예제 #2
0
        public void GetGeoLocationShouldreturnSuccess()
        {
            GeoLocation FirstGeoLoc = new GeoLocation("31.60.48.215", "Ochota", "Poland", "Europe")
            {
                ID = 1
            };
            GeoLocation SecondGeoLoc = new GeoLocation("134.201.250.155", "Los Angeles", "USA", "North America")
            {
                ID = 2
            };
            var builder = new DbContextOptionsBuilder <GeoLocApiContext>().UseInMemoryDatabase(Guid.NewGuid().ToString());

            using var context = new GeoLocApiContext(builder.Options);
            context.GeoLocations.Add(FirstGeoLoc);
            context.GeoLocations.Add(SecondGeoLoc);
            context.SaveChanges();

            var controller            = new GeoLocationsController(context);
            Task <IActionResult> task = controller.GetGeoLocation("31.60.48.215");

            Assert.True(task.IsCompletedSuccessfully);
        }