Exemplo n.º 1
0
        public async Task MissingQParameterShouldReturnError400()
        {
            //Hack : https://alenjalex.github.io/dev/dev/Asp.Net-Core-ModelState-Validation-Using-UnitTest/
            _suggestions.ModelState.AddModelError("q", "The q field is required.");

            var response = await _suggestions.GetSuggestions(null);

            (response.Result as BadRequestResult).StatusCode.Should().Be(StatusCodes.Status400BadRequest);
        }
Exemplo n.º 2
0
        public async void GetSuggestions_AlwaysReturnsA200()
        {
            string userID = "Test-ID";

            List <UserGenre> genres = new List <UserGenre>()
            {
            };
            List <UserVenue> venues = new List <UserVenue>()
            {
            };

            ApplicationUser user = new ApplicationUser()
            {
                Id          = "Test-ID",
                Email       = "*****@*****.**",
                Name        = "Test-Name",
                UserName    = "******",
                Bio         = "Test Bio",
                LookingFor  = "Test Looking For",
                Lat         = 50.3755,
                Lon         = 4.1427,
                MatchRadius = 50,
                Genres      = genres,
                Venues      = venues,
            };

            List <ApplicationUser> matchesInRadius = new List <ApplicationUser>()
            {
                new ApplicationUser()
                {
                    Id          = "Returned-ID",
                    Email       = "*****@*****.**",
                    Name        = "Returned-Name",
                    UserName    = "******",
                    Bio         = "Returned Bio",
                    LookingFor  = "Returned Looking For",
                    Lat         = 50.3755,
                    Lon         = 4.1427,
                    MatchRadius = 50,
                    Genres      = genres,
                    Venues      = venues,
                },
                new ApplicationUser()
                {
                    Id          = "Returned2-ID",
                    Email       = "*****@*****.**",
                    Name        = "Returned2-Name",
                    UserName    = "******",
                    Bio         = "Returned2 Bio",
                    LookingFor  = "Returned2 Looking For",
                    Lat         = 50.3755,
                    Lon         = 4.1427,
                    MatchRadius = 50,
                    Genres      = genres,
                    Venues      = venues,
                }
            };

            sessionService.Setup(x => x.GetCurrentUserId()).Returns(userID);
            userRepository.Setup(x => x.GetUserAccount(It.IsAny <string>())).ReturnsAsync(user);
            suggesionsRepository.Setup(x => x.GetUsersInMatchRadius(It.IsAny <double>(), It.IsAny <double>(), It.IsAny <double>(), It.IsAny <double>())).ReturnsAsync(matchesInRadius);

            ObjectResult result = await subject.GetSuggestions();

            Assert.Equal(200, result.StatusCode);
        }