public async void VerifySubscriberExists_ValidSubscriber_UserLoggedIn(string email)
        {
            _webApp.Load(_webApp.DBContext);

            string googleAuth = GoogleAuth.getGoogleAuth(_client);

            _client.DefaultRequestHeaders.Add("GoogleAuth", googleAuth);

            //Getting subscriber token from api
            var response = await _client.GetAsync("api/subscribers/email-d=" + email);

            var responseString = await response.Content.ReadAsStringAsync();

            _client.DefaultRequestHeaders.Remove("Authorization");
            _client.DefaultRequestHeaders.Add("Authorization", "Bearer " + responseString);

            //make get request to api with email passed in
            response = await _client.GetAsync("api/Subscribers/email=" + email);

            //get the response
            responseString = await response.Content.ReadAsStringAsync();

            Subscriber subscriber = JsonConvert.DeserializeObject <Subscriber>(responseString);

            Assert.Equal(email, subscriber.email);                //ensure expectecd value is returned
            Assert.Equal(HttpStatusCode.OK, response.StatusCode); //ensure sattus code 200 returned
        }
        public async void VerifyGetPickupDatesForOtherLocation_ValidSubscriber_SubscriberIsUnauthorized()
        {
            string googleAuth = GoogleAuth.getGoogleAuth(_client);

            _client.DefaultRequestHeaders.Add("GoogleAuth", googleAuth);

            //Getting subscriber token from api
            var response = await _client.GetAsync("api/subscribers/[email protected]");

            var responseString = await response.Content.ReadAsStringAsync();

            _client.DefaultRequestHeaders.Remove("Authorization");
            _client.DefaultRequestHeaders.Add("Authorization", "Bearer " + responseString);

            response = await _client.GetAsync("api/Regions/regionID-c=1");

            Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
        }
        public async void VerifyGetSortedSubscribers_ValidSubscriber_SubscriberIsUnauthorized()
        {
            string googleAuth = GoogleAuth.getGoogleAuth(_client);

            _client.DefaultRequestHeaders.Add("GoogleAuth", googleAuth);

            //Getting subscriber token from api
            var response = await _client.GetAsync("api/subscribers/[email protected]");

            var responseString = await response.Content.ReadAsStringAsync();

            _client.DefaultRequestHeaders.Remove("Authorization");
            _client.DefaultRequestHeaders.Add("Authorization", "Bearer " + responseString);

            response = await _client.GetAsync("api/Subscribers/sortBy-sascsizePerPage-p5currentPage-c1");

            Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
        }
        public async void VerifyPostAdmin_ValidSubscriber_SubscriberIsUnauthorized()
        {
            string googleAuth = GoogleAuth.getGoogleAuth(_client);

            _client.DefaultRequestHeaders.Add("GoogleAuth", googleAuth);

            //Getting subscriber token from api
            var response = await _client.GetAsync("api/subscribers/[email protected]");

            var responseString = await response.Content.ReadAsStringAsync();

            _client.DefaultRequestHeaders.Remove("Authorization");
            _client.DefaultRequestHeaders.Add("Authorization", "Bearer " + responseString);

            var StringContent = new StringContent(JsonConvert.SerializeObject(admin), Encoding.UTF8, "application/json");

            response = await _client.PostAsync("api/Admins", StringContent);

            Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
        }
        public async void UpdateSubscriber_ValidSubscriber_SubscriberUpdatedInDB()
        {
            _webApp.Load(_webApp.DBContext);

            //setting up login token
            var StringContent            = new StringContent(JsonConvert.SerializeObject(admin), Encoding.UTF8, "application/json");
            HttpResponseMessage response = await _client.PostAsync("api/Admins", StringContent);

            string adminToken = await response.Content.ReadAsStringAsync();

            _client.SetBearerToken(adminToken);

            //get a subscriber form the database
            response = await _client.GetAsync("api/Subscribers");

            //deserialize the retrieved subscribers into a list of Subscriber objects
            string responseJSON = await response.Content.ReadAsStringAsync();

            List <Subscriber> actualSubscribers = JsonConvert.DeserializeObject <List <Subscriber> >(responseJSON);

            //use the first subscriber in the list as the subscriber to update
            //Subscriber UpdateSubscriber = actualSubscribers[100];
            Subscriber UpdateSubscriber = actualSubscribers.FirstOrDefault(sub => sub.email.Equals("*****@*****.**"));

            //update the phone number
            UpdateSubscriber.phoneNumber = "2222222222";

            //Getting valid Google OAuth token
            string googleAuth = GoogleAuth.getGoogleAuth(_client);

            _client.DefaultRequestHeaders.Add("GoogleAuth", googleAuth);

            //Getting subscriber token from api
            response = await _client.GetAsync("api/Subscribers/email-d=" + UpdateSubscriber.email);

            var responseString = await response.Content.ReadAsStringAsync();

            _client.DefaultRequestHeaders.Remove("Authorization");

            _client.DefaultRequestHeaders.Add("Authorization", "Bearer " + responseString);

            //convert the subsciber to a string for posting to the database
            var stringContent = new StringContent(JsonConvert.SerializeObject(UpdateSubscriber), Encoding.UTF8, "application/json");

            response = await _client.PutAsync("api/Subscribers/" + UpdateSubscriber.subscriberID, stringContent);

            //API will send back the update Subscriber object.
            //deserialize that object into a Subscriber object
            responseJSON = await response.Content.ReadAsStringAsync();

            //no content status code is 204
            Assert.Equal(HttpStatusCode.NoContent, response.StatusCode);
            _client.SetBearerToken(adminToken);
            //send a get request with the updated subscriber ID to the database and retrieve the updated subscriber
            response = await _client.GetAsync("api/Subscribers/" + UpdateSubscriber.subscriberID);

            responseJSON = await response.Content.ReadAsStringAsync();

            //deserialize the response into a Subscriber object
            Subscriber GetSubscriber = JsonConvert.DeserializeObject <Subscriber>(responseJSON);


            //check each field of the retrieved Subscriber and make sure it matches each field of the initial subscriber after the phone number was modified with the
            //updated value
            Assert.IsType <int>(UpdateSubscriber.subscriberID);
            Assert.Equal(UpdateSubscriber.firstName, GetSubscriber.firstName);
            Assert.Equal(UpdateSubscriber.lastName, GetSubscriber.lastName);
            //Assert.Equal(UpdateSubscriber.Password, GetSubscriber.Password);
            Assert.Equal(UpdateSubscriber.email, GetSubscriber.email);
            Assert.Equal(UpdateSubscriber.phoneNumber, GetSubscriber.phoneNumber);
            Assert.Equal(UpdateSubscriber.isBusiness, GetSubscriber.isBusiness);
            //Assert.IsType<int>(UpdateSubscriber.locationID);
        }
        public async void AddSubscriber_ValidSubscriber_SubscriberAddedToDB()
        {
            //obtained from google

            string googleAuth = GoogleAuth.getGoogleAuth(_client);

            _client.DefaultRequestHeaders.Add("GoogleAuth", googleAuth);

            //Reload the database.
            //SubscriberFixture.Reload(_webApp.DBContext);
            _webApp.Load(_webApp.DBContext);
            //create a new subscriber to add to the database with valid fields
            //Subscriber NewSubscriber = DatabaseSubscriberFixture.GetDerivedSubscribers()[0];

            Subscriber NewSubscriber = new Subscriber
            {
                firstName   = "John",
                lastName    = "Doe",
                email       = "*****@*****.**",
                phoneNumber = "1234567890",
                isBusiness  = false
            };

            Location location = _webApp.DBContext.Location.First();

            NewSubscriber.locationID = location.locationID;

            //convert the subsciber to a string for posting to the database
            StringContent stringContent = new StringContent(JsonConvert.SerializeObject(NewSubscriber), Encoding.UTF8, "application/json");

            //send a post request to the api with the Subscriber object in JSON form
            var response = await _client.PostAsync("api/Subscribers", stringContent);

            //get the response from the api and read it into a string
            string responseString = await response.Content.ReadAsStringAsync();

            //deserialize the response into a Subscriber object
            Subscriber deserializedSubscriber = JsonConvert.DeserializeObject <Subscriber>(responseString);

            //created status code is 201
            Assert.Equal(HttpStatusCode.Created, response.StatusCode);

            AdminFixture.Load(_webApp.DBContext);

            //setting up login token
            var StringContent = new StringContent(JsonConvert.SerializeObject(admin), Encoding.UTF8, "application/json");

            response = await _client.PostAsync("api/Admins", StringContent);

            string adminToken = await response.Content.ReadAsStringAsync();

            _client.SetBearerToken(adminToken);

            //try to get the added subscriber form the database using the response data from earlier request.
            response = await _client.GetAsync("api/Subscribers/" + deserializedSubscriber.subscriberID);

            //read the response as a string
            responseString = await response.Content.ReadAsStringAsync();

            //deserialize the object retrieved from the database
            Subscriber GetSubscriber = JsonConvert.DeserializeObject <Subscriber>(responseString);

            //check each field of the retrieved Subscriber and ensure it is equal to the subscriber that was initially send in the POST request
            Assert.IsType <int>(deserializedSubscriber.subscriberID);
            Assert.Equal(NewSubscriber.firstName, GetSubscriber.firstName);
            Assert.Equal(NewSubscriber.lastName, GetSubscriber.lastName);
            //Assert.Equal(NewSubscriber.Password, GetSubscriber.Password);
            Assert.Equal(NewSubscriber.email, GetSubscriber.email);
            Assert.Equal(NewSubscriber.phoneNumber, GetSubscriber.phoneNumber);
            Assert.Equal(NewSubscriber.isBusiness, GetSubscriber.isBusiness);
            Assert.IsType <int>(GetSubscriber.locationID);
        }