Exemple #1
0
        /// <summary>
        /// Get music genre based on the weather, derived from user's location
        /// </summary>
        /// <param name="client"></param>
        /// <returns></returns>
        public ActionResult <Models.Weather> GetGenre(Models.User client)
        {
            //authenticate

            IEnumerable <Preference> allPreference;

            Domain.DomainEntities.User user = udb.Find(client.username);

            ExternalApis.WeatherApi       weatherApi = new ExternalApis.WeatherApi();
            Domain.DomainEntities.Weather weather    = weatherApi.GetWeatherByLocation(user.location);
            weather = wdb.GetWeather(weather);
            Domain.DomainEntities.Preference preference = new Domain.DomainEntities.Preference();

            allPreference = pdb.GetPreferences(udb.Find(user.username).id);

            preference = allPreference.Where(x => weather.weather_id == x.weather_id).FirstOrDefault();
            if (preference != null)
            {
                Domain.DomainEntities.Weather weatherPreference = new Domain.DomainEntities.Weather()
                {
                    type = weather.type, description = weather.description, default_genre = preference.genre
                };
                return(Ok(ModelMapper.Map(weatherPreference)));
            }
            else
            {
                return(Ok(ModelMapper.Map(weather)));
            }
        }
Exemple #2
0
        public void DeletePreference_validPreference_Null()
        {
            Domain.DomainEntities.Preference testPreference = new Domain.DomainEntities.Preference();
            Domain.DomainEntities.User       testUser       = udb.Find("backendTest");
            var preferences = pdb.GetPreferences(testUser.id);

            foreach (var p in preferences)
            {
                if (p.genre == "testGenre")
                {
                    testPreference = p;
                }
            }

            pdb.DeletePreference(testPreference);
            udb.Delete(testUser);

            Domain.DomainEntities.Weather testWeather = new Domain.DomainEntities.Weather();
            testWeather.type          = "testType";
            testWeather.description   = "testDescription";
            testWeather.default_genre = "testGenre";
            wdb.DeleteWeather(wdb.GetWeather(testWeather));

            Assert.IsTrue(true);
        }
Exemple #3
0
        public void GetPreferences_Nothing_True()
        {
            Domain.DomainEntities.User testUser = udb.Find("backendTest");
            var preferences = pdb.GetPreferences(testUser.id);

            foreach (var p in preferences)
            {
                if (p.genre == "testGenre")
                {
                    Assert.IsTrue(true);
                }
            }
        }
        public static Entities.Users Map(DomainEntities.User u)
        {
            if (u == null)
            {
                return(null);
            }

            return(new Entities.Users
            {
                Id = u.id,
                Username = u.username,
                Password = u.password,
                Location = u.location
            });
        }
Exemple #5
0
        public void SetPreference_validPreference_True()
        {
            Domain.DomainEntities.User testUser = new Domain.DomainEntities.User();
            testUser.username = "******";
            testUser.password = "******";
            testUser.location = "98908";
            udb.Create(testUser);

            Domain.DomainEntities.Weather testWeather = new Domain.DomainEntities.Weather();
            testWeather.type          = "testType";
            testWeather.description   = "testDescription";
            testWeather.default_genre = "testGenre";
            wdb.CreateWeather(testWeather);

            Domain.DomainEntities.Preference testPreference = new Domain.DomainEntities.Preference();
            testPreference.genre      = "testGenre";
            testPreference.weather_id = wdb.GetWeather(testWeather).weather_id;
            testPreference.user_id    = udb.Find(testUser.username).id;
            pdb.SetPreference(testPreference);
            Assert.IsTrue(true);
        }