Пример #1
0
 public PlanForm(string placeName, string placeId, DateTime startDate, TimeSpan startTime, DateTime endDate, TimeSpan endTime, LanguageType language, bool hasAccomodationBooked, string accomodationId,
                 IList <GoogleTravelMode> preferedTravelModes, int maxWalkingKmsPerDay, DistanceTypePreference distanceTypePreference,
                 PricePreference pricePreference, FoodPreference foodPreference, int averageSleep, AtractionPopularityPreference atractionPopularityPreference, AtractionDurationPreference atractionDurationPreference,
                 IList <PlanElementType> sortedPlanElements, IList <PlanElementType> preferedPlanElements)
     : this()
 {
     PlaceName                     = placeName;
     PlaceId                       = placeId;
     StartDate                     = startDate;
     StartTime                     = startTime;
     EndDate                       = endDate;
     EndTime                       = endTime;
     Language                      = language;
     HasAccomodationBooked         = hasAccomodationBooked;
     AccomodationId                = accomodationId;
     PreferedTravelModes           = preferedTravelModes;
     PreferedTravelModesString     = String.Join(';', preferedTravelModes.Select(x => (int)x).ToArray());
     MaxWalkingKmsPerDay           = maxWalkingKmsPerDay;
     DistanceTypePreference        = distanceTypePreference;
     PricePreference               = PricePreference;
     FoodPreference                = FoodPreference;
     AverageSleep                  = averageSleep;
     AtractionPopularityPreference = atractionPopularityPreference;
     AtractionDurationPreference   = atractionDurationPreference;
     SortedPlanElements            = sortedPlanElements;
     SortedPlanElementsString      = String.Join(';', sortedPlanElements.Select(x => (int)x).ToArray());
     PreferedPlanElements          = preferedPlanElements;
     PreferedPlanElementsString    = String.Join(';', preferedPlanElements.Select(x => (int)x).ToArray());
 }
Пример #2
0
        public void Should_FailValidation_When_FoodPreferenceIsNull()
        {
            // Arrange
            var validator  = new FoodPreferenceValidator();
            var preference = new FoodPreference();

            // Act
            var result  = validator.Validate(preference);
            var isValid = result.IsValid;

            // Assert
            isValid.Should().Be(false);
        }
Пример #3
0
        public void Should_PassValidation_When_AllRulesPass()
        {
            // Arrange
            var validator  = new FoodPreferenceValidator();
            var preference = new FoodPreference("Vegan");

            // Act
            var result  = validator.Validate(preference);
            var isValid = result.IsValid;

            // Assert
            isValid.Should().Be(true);
        }
 public IHttpActionResult Put(FoodPreference foodPreference)
 {
     using (var helper = new DataBaseHelper())
     {
         var response = helper.UpdateFoodPreference(foodPreference);
         if (response)
         {
             return(Ok("Uppdateringen lyckades"));
         }
         else
         {
             return(BadRequest("Något gick fel"));
         }
     }
 }
Пример #5
0
    public static DishCategory ToCategory(FoodPreference pref)
    {
        switch (pref)
        {
        case FoodPreference.AMERICAN:
            return(DishCategory.AMERICAN);

        case FoodPreference.ITALIAN:
            return(DishCategory.ITALIAN);

        case FoodPreference.MEXICAN:
            return(DishCategory.MEXICAN);
        }
        return(0);
    }
        public bool UpdateFoodPreference(FoodPreference foodPreference)
        {
            var existingFoodPreference = Session.Query <FoodPreference>().Where(f => f.Id == foodPreference.Id).FirstOrDefault();

            if (existingFoodPreference == null)
            {
                return(false);
            }
            existingFoodPreference.SwedishName = foodPreference.SwedishName;
            existingFoodPreference.EnglishName = foodPreference.EnglishName;
            using (var transaction = Session.BeginTransaction())
            {
                Session.Update(existingFoodPreference);
                transaction.Commit();
            }
            return(true);
        }
Пример #7
0
            public void AddAnimal_ShouldWork(Size size, FoodPreference foodPreference)
            {
                // Arrange
                int    expected        = 2;
                Wagon  wagon           = new Wagon();
                Animal bigCarnivore    = new Animal(Size.Large, FoodPreference.Herbivore);
                Animal mediumHerbivore = new Animal(size, foodPreference);

                // Act
                wagon.IsAnimalAdded(bigCarnivore);
                wagon.IsAnimalAdded(mediumHerbivore);
                int result = wagon.Animals.Count;

                // Assert
                Assert.Equal(expected, result);
                Assert.Equal(bigCarnivore, wagon.Animals[0]);
            }
Пример #8
0
            public void AddAnimal_ShouldFail(Size firstAnimalSize, FoodPreference firstFoodPreference, Size secAnimalSize, FoodPreference secFoodPreference)
            {
                // Arrange
                int    expected     = 1;
                Wagon  wagon        = new Wagon();
                Animal firstAnimal  = new Animal(firstAnimalSize, firstFoodPreference);
                Animal secondAnimal = new Animal(secAnimalSize, secFoodPreference);

                // Act
                wagon.IsAnimalAdded(firstAnimal);
                wagon.IsAnimalAdded(secondAnimal);
                int result = wagon.Animals.Count;

                // Assert
                Assert.Equal(expected, result);
                Assert.Equal(firstAnimal, wagon.Animals[0]);
            }
Пример #9
0
        public List <Animal> Spawnanimals(int number)
        {
            sortAnimals = new SortAnimals();
            List <Animal> animals = new List <Animal>();

            Array foodPreferences = Enum.GetValues(typeof(FoodPreference));
            Array sizes           = Enum.GetValues(typeof(Size));

            Random rnd = new Random();

            for (int i = 0; i < number; i++)
            {
                FoodPreference randomFoodPreference = (FoodPreference)foodPreferences.GetValue(rnd.Next(foodPreferences.Length));
                Size           randomSize           = (Size)sizes.GetValue(rnd.Next(sizes.Length));
                animals.Add(new Animal(randomSize, randomFoodPreference));
            }
            return(sortAnimals.BySizeAndFoodPreference(animals));
        }
        public Guid RegisterCompany(CompanyPostDto company, string accessCode)
        {
            Company newCompany = new Company();

            newCompany = new Company
            {
                Comment    = company.Comment,
                AccessCode = accessCode
            };

            using (var companyTransaction = Session.BeginTransaction())
            {
                Session.Save(newCompany);
                companyTransaction.Commit();
            }
            foreach (var person in company.Persons)
            {
                var newPerson = new Person
                {
                    FirstName       = person.FirstName,
                    LastName        = person.LastName,
                    Phone           = person.Phone,
                    Email           = person.Email,
                    FoodPreferences = new List <FoodPreference>(),
                    Going           = person.Going,
                    Company         = newCompany
                };
                if (person.FoodPreferences != null)
                {
                    foreach (var foodPreference in person.FoodPreferences)
                    {
                        Guid foodPreferenceId;
                        var  foodPreferenceQuery = Session.Query <FoodPreference>().Where(f => (f.SwedishName.ToLower() == foodPreference.SwedishName.ToLower() && !string.IsNullOrWhiteSpace(foodPreference.SwedishName)) || (f.EnglishName.ToLower() == foodPreference.EnglishName.ToLower() && !string.IsNullOrWhiteSpace(foodPreference.EnglishName)));
                        if (foodPreferenceQuery.Any())
                        {
                            foodPreferenceId = foodPreferenceQuery.First().Id;
                        }
                        else
                        {
                            var newFoodPreference = new FoodPreference {
                                SwedishName = foodPreference.SwedishName, EnglishName = foodPreference.EnglishName
                            };
                            using (var foodPreferenceTransaction = Session.BeginTransaction())
                            {
                                Session.Save(newFoodPreference);
                                foodPreferenceTransaction.Commit();
                            }
                            foodPreferenceId = newFoodPreference.Id;
                        }
                        newPerson.FoodPreferences.Add(new FoodPreference {
                            Id = foodPreferenceId
                        });
                    }
                }
                using (var personTransaction = Session.BeginTransaction())
                {
                    Session.Save(newPerson);
                    personTransaction.Commit();
                }
            }
            return(newCompany.Id);
        }
Пример #11
0
 public Animal(Size size, FoodPreference foodPreference)
 {
     Size           = size;
     FoodPreference = foodPreference;
 }