Пример #1
0
        public async Task <IActionResult> Login([FromBody] Restaurant_Auth restaurant)
        {
            /*if (ModelState.IsValid)
             * {
             *  _context.Add(restaurant);
             *  await _context.SaveChangesAsync();
             *  return RedirectToAction(nameof(Index));
             */

            List <Restaurant> restaurants = await _context.Restaurant.ToListAsync();

            bool found = false;

            // check if restaurant is in db
            restaurants.ForEach(rest =>
            {
                if (rest.EmailAddress.Equals(restaurant.EmailAddress) &&
                    rest.Password.Equals(restaurant.Password))
                {
                    found = true;
                }
            });

            if (found)
            {
                string valueToEncode = restaurant.EmailAddress + ":" + restaurant.Password;
                var    textBytes     = System.Text.Encoding.UTF8.GetBytes(valueToEncode);
                HttpContext.Response.Headers.Add("AuthValue", System.Convert.ToBase64String(textBytes));
                return(View());
            }

            return(NotFound());
        }
Пример #2
0
        public async Task LoginAsRestaurant()
        {
            // Arrange
            var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost:5002/Restaurant/login");

            Restaurant_Auth restaurantAuth = new Restaurant_Auth
            {
                EmailAddress = restaurantEmailAddress,
                Password = restaurantPassword,
               
            };
            var json = Newtonsoft.Json.JsonConvert.SerializeObject(restaurantAuth);

            
            request.Content = new StringContent(json,
                                    Encoding.UTF8,
                                    "application/json");

            var response = await _client.SendAsync(request);
            IEnumerable<string> headerValues = response.Headers.GetValues("AuthValue");
            // set auth value
            authorizationValue = headerValues.FirstOrDefault();
            

            // ASSERT TEST TO BE 200, OK
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
        }