Пример #1
0
        public void MealCopy()
        {
            var configurationMock = new Mock<IConfiguration>();
             configurationMock.Setup( x => x.DataSource ).Returns( DataSourceType.XMLFile );
             configurationMock.Setup( x => x.FileName ).Returns( FullTestData.DataFileName );

             FullTestData.Reset();
             var dataRepository = new DataRepository( configurationMock.Object );

             DateTime theTime = DateTime.Now;
             Meal mealModel = new Meal(
            new Guid( "d88a6942-663d-4f6f-831d-ea9127ccc0e9" ),
            dataRepository.FindMealType( mt => mt.Name == "Lunch" ),
            theTime, "Lunch", null );

             mealModel.FoodItemServings.Add( new Serving<FoodItem>( dataRepository.FindFoodItem( food => food.Name == "Baby Carrots" ), 2.5M ) );
             mealModel.FoodItemServings.Add( new Serving<FoodItem>( dataRepository.FindFoodItem( food => food.Name == "Deluxe Bacon Cheese Burger" ), 1 ) );
             mealModel.FoodItemServings.Add( new Serving<FoodItem>( dataRepository.FindFoodItem( food => food.Name == "Glass of Skim Milk" ), 2 ) );

             Assert.IsTrue( mealModel.IsValid );

             Meal meal = new Meal( mealModel );
             Assert.IsNotNull( meal.ID );
             Assert.AreEqual( mealModel.ID, meal.ID );
             Assert.IsTrue( meal.IsValid );
             Assert.AreEqual( mealModel.TypeOfMeal, meal.TypeOfMeal );
             Assert.AreEqual( mealModel.DateAndTimeOfMeal, meal.DateAndTimeOfMeal );
             Assert.AreEqual( mealModel.Calories, meal.Calories );
             Assert.AreEqual( mealModel.FoodItemServings.Count, meal.FoodItemServings.Count );
             for (Int32 idx = 0; idx < mealModel.FoodItemServings.Count; idx++)
             {
            Assert.AreEqual( mealModel.FoodItemServings[idx].Quantity, meal.FoodItemServings[idx].Quantity );
            Assert.AreEqual( mealModel.FoodItemServings[idx].Entity, meal.FoodItemServings[idx].Entity );
             }
             Assert.AreEqual( mealModel.FoodGroupServings.Count, meal.FoodGroupServings.Count );
        }
Пример #2
0
        public void MealTemplateValidationTests()
        {
            var configurationMock = new Mock<IConfiguration>();
             configurationMock.Setup( x => x.DataSource ).Returns( DataSourceType.XMLFile );
             configurationMock.Setup( x => x.FileName ).Returns( FullTestData.DataFileName );

             FullTestData.Reset();
             var dataRepository = new DataRepository( configurationMock.Object );

             DateTime theTime = DateTime.Now;
             MealTemplate mealTemplate = new MealTemplate( Guid.NewGuid(), default( MealType ), default( DateTime ), null, null );

             Assert.IsFalse( mealTemplate.IsValid );
             Assert.IsNull( mealTemplate["ID"] );
             Assert.AreEqual( Messages.Error_No_MealType, mealTemplate["TypeOfMeal"] );
             Assert.IsNull( mealTemplate["TimeOfMeal"] );
             Assert.AreEqual( Messages.Error_No_FoodItems, mealTemplate["FoodItemServings"] );
             Assert.AreEqual( Messages.Error_No_Name, mealTemplate["Name"] );

             // Add a valid mealTemplate type
             mealTemplate.TypeOfMeal = dataRepository.FindMealType( mt => mt.Name == "Lunch" );
             Assert.IsFalse( mealTemplate.IsValid );
             Assert.IsNull( mealTemplate["ID"] );
             Assert.IsNull( mealTemplate["TypeOfMeal"] );
             Assert.IsNull( mealTemplate["TimeOfMeal"] );
             Assert.AreEqual( Messages.Error_No_FoodItems, mealTemplate["FoodItemServings"] );
             Assert.AreEqual( Messages.Error_No_Name, mealTemplate["Name"] );

             // Add a valid time for the mealTemplate
             mealTemplate.DateAndTimeOfMeal = theTime;
             Assert.IsFalse( mealTemplate.IsValid );
             Assert.IsNull( mealTemplate["ID"] );
             Assert.IsNull( mealTemplate["TypeOfMeal"] );
             Assert.IsNull( mealTemplate["TimeOfMeal"] );
             Assert.AreEqual( Messages.Error_No_FoodItems, mealTemplate["FoodItemServings"] );
             Assert.AreEqual( Messages.Error_No_Name, mealTemplate["Name"] );

             // Add a food item serving
             mealTemplate.FoodItemServings.Add( new Serving<FoodItem>( dataRepository.FindFoodItem( food => food.Name == "Baby Carrots" ), 2.5M ) );
             Assert.IsFalse( mealTemplate.IsValid );
             Assert.IsNull( mealTemplate["ID"] );
             Assert.IsNull( mealTemplate["TypeOfMeal"] );
             Assert.IsNull( mealTemplate["TimeOfMeal"] );
             Assert.IsNull( mealTemplate["FoodItemServings"] );
             Assert.AreEqual( Messages.Error_No_Name, mealTemplate["Name"] );

             // Assign a valid name
             mealTemplate.Name = "A test mealTemplate template";
             Assert.IsTrue( mealTemplate.IsValid );
             Assert.IsNull( mealTemplate["ID"] );
             Assert.IsNull( mealTemplate["TypeOfMeal"] );
             Assert.IsNull( mealTemplate["TimeOfMeal"] );
             Assert.IsNull( mealTemplate["FoodItemServings"] );
             Assert.IsNull( mealTemplate["Name"] );
        }
Пример #3
0
        public void MealTemplateMeal()
        {
            var configurationMock = new Mock<IConfiguration>();
             configurationMock.Setup( x => x.DataSource ).Returns( DataSourceType.XMLFile );
             configurationMock.Setup( x => x.FileName ).Returns( FullTestData.DataFileName );

             FullTestData.Reset();
             var dataRepository = new DataRepository( configurationMock.Object );

             DateTime theTime = DateTime.Now;
             Meal meal = new Meal( Guid.NewGuid(), dataRepository.FindMealType( mt => mt.Name == "Lunch" ), theTime, "Lunch", null );
             meal.FoodItemServings.Add( new Serving<FoodItem>( dataRepository.FindFoodItem( food => food.Name == "Baby Carrots" ), 2.5M ) );
             meal.FoodItemServings.Add( new Serving<FoodItem>( dataRepository.FindFoodItem( food => food.Name == "Deluxe Bacon Cheese Burger" ), 1 ) );
             Assert.IsTrue( meal.IsValid );
             Assert.AreEqual( 750, meal.Calories );

             MealTemplate mealTemplate = new MealTemplate( meal );
             Assert.AreEqual( meal.ID, mealTemplate.ID );
             Assert.AreEqual( meal.TypeOfMeal, mealTemplate.TypeOfMeal );
             Assert.AreEqual( meal.DateAndTimeOfMeal, mealTemplate.DateAndTimeOfMeal );
             Assert.AreEqual( 2, mealTemplate.FoodItemServings.Count );
             Assert.IsNotNull( mealTemplate.FoodItemServings.Find( s => s.Entity.Name == "Baby Carrots" ) );
             Assert.IsNotNull( mealTemplate.FoodItemServings.Find( s => s.Entity.Name == "Deluxe Bacon Cheese Burger" ) );
             Assert.IsTrue( mealTemplate.IsValid );
             Assert.IsNull( mealTemplate["Name"] );
        }
Пример #4
0
        public void MealTemplateIDTypeTimeNameDescription()
        {
            var configurationMock = new Mock<IConfiguration>();
             configurationMock.Setup( x => x.DataSource ).Returns( DataSourceType.XMLFile );
             configurationMock.Setup( x => x.FileName ).Returns( FullTestData.DataFileName );

             FullTestData.Reset();
             var dataRepository = new DataRepository( configurationMock.Object );

             DateTime theTime = DateTime.Now;
             MealTemplate mealTemplate = new MealTemplate( new Guid( "1c456eca-17c6-4395-a14f-85800a5c9d35" ),
            dataRepository.FindMealType( mt => mt.Name == "Dinner" ),
            theTime, "Just a test mealTemplate", "And this is the description" );

             // Should be invalid when instantiated since there is a lot of missing data
             Assert.IsFalse( mealTemplate.IsValid );
             Assert.IsNull( mealTemplate["TypeOfMeal"] );
             Assert.IsNull( mealTemplate["TimeOfMeal"] );
             Assert.AreEqual( Messages.Error_No_FoodItems, mealTemplate["FoodItemServings"] );
             Assert.IsNull( mealTemplate["Name"] );
             Assert.IsNull( mealTemplate["ID"] );
             Assert.AreEqual( new Guid( "1c456eca-17c6-4395-a14f-85800a5c9d35" ), mealTemplate.ID );
             Assert.AreEqual( "Dinner", mealTemplate.TypeOfMeal.Name );
             Assert.ReferenceEquals( dataRepository.FindMealType( mt => mt.Name == "Dinner" ), mealTemplate.TypeOfMeal );
             Assert.AreEqual( theTime, mealTemplate.DateAndTimeOfMeal );
             Assert.AreEqual( "Just a test mealTemplate", mealTemplate.Name );
             Assert.AreEqual( "And this is the description", mealTemplate.Description );
             Assert.AreEqual( 0, mealTemplate.FoodItemServings.Count );
             Assert.AreEqual( 0, mealTemplate.Calories );
             Assert.AreEqual( 0, mealTemplate.FoodGroupServings.Count );

             // Add missing data, show that it is now valid
             mealTemplate.FoodItemServings.Add( new Serving<FoodItem>( dataRepository.FindFoodItem( food => food.Name == "Baby Carrots" ), 2.5M ) );
             mealTemplate.FoodItemServings.Add( new Serving<FoodItem>( dataRepository.FindFoodItem( food => food.Name == "Deluxe Bacon Cheese Burger" ), 1 ) );
             mealTemplate.FoodItemServings.Add( new Serving<FoodItem>( dataRepository.FindFoodItem( food => food.Name == "Glass of Skim Milk" ), 2 ) );
             mealTemplate.FoodItemServings.Add( new Serving<FoodItem>( dataRepository.FindFoodItem( food => food.Name == "Fruit Salad" ), 1.5M ) );

             Assert.IsTrue( mealTemplate.IsValid );
             Assert.IsNull( mealTemplate["TypeOfMeal"] );
             Assert.IsNull( mealTemplate["TimeOfMeal"] );
             Assert.IsNull( mealTemplate["FoodItemServings"] );
             Assert.IsNull( mealTemplate["Name"] );
             Assert.AreEqual( (2.5M * 40) + 650 + (2 * 90) + (1.5M * 150), mealTemplate.Calories );
             Assert.AreEqual( 5, mealTemplate.FoodGroupServings.Count );
             Assert.AreEqual( 3, mealTemplate.FoodGroupServings.Find( fg => fg.Entity.Name == "Vegetable" ).Quantity );
             Assert.AreEqual( 1, mealTemplate.FoodGroupServings.Find( fg => fg.Entity.Name == "Grain" ).Quantity );
             Assert.AreEqual( 1.5M, mealTemplate.FoodGroupServings.Find( fg => fg.Entity.Name == "Meat" ).Quantity );
             Assert.AreEqual( 5, mealTemplate.FoodGroupServings.Find( fg => fg.Entity.Name == "Dairy" ).Quantity );
             Assert.AreEqual( 3, mealTemplate.FoodGroupServings.Find( fg => fg.Entity.Name == "Fruit" ).Quantity );
        }
Пример #5
0
        public void MealIdTypeAndTime()
        {
            var configurationMock = new Mock<IConfiguration>();
             configurationMock.Setup( x => x.DataSource ).Returns( DataSourceType.XMLFile );
             configurationMock.Setup( x => x.FileName ).Returns( FullTestData.DataFileName );

             FullTestData.Reset();
             var dataRepository = new DataRepository( configurationMock.Object );

             DateTime theTime = DateTime.Now;
             Meal meal = new Meal(
            new Guid( "d678325f-6bd0-4fae-8847-ebb07323b9bc" ),
            dataRepository.FindMealType( mt => mt.Name == "Lunch" ),
            theTime, "Lunch", null );

             // Should be invalid when instantiated since there is a lot of missing data
             Assert.IsFalse( meal.IsValid );
             Assert.IsNull( meal["TypeOfMeal"] );
             Assert.IsNull( meal["TimeOfMeal"] );
             Assert.AreEqual( Messages.Error_No_FoodItems, meal["FoodItemServings"] );
             Assert.AreEqual( new Guid( "d678325f-6bd0-4fae-8847-ebb07323b9bc" ), meal.ID );
             Assert.AreEqual( "Lunch", meal.TypeOfMeal.Name );
             Assert.ReferenceEquals( dataRepository.FindMealType( mt => mt.Name == "Lunch" ), meal.TypeOfMeal );
             Assert.AreEqual( theTime, meal.DateAndTimeOfMeal );
             Assert.AreEqual( 0, meal.FoodItemServings.Count );
             Assert.AreEqual( 0, meal.Calories );
             Assert.AreEqual( 0, meal.FoodGroupServings.Count );

             // Add missing data, show that it is now valid
             meal.FoodItemServings.Add( new Serving<FoodItem>( dataRepository.FindFoodItem( food => food.Name == "Baby Carrots" ), 2.5M ) );
             meal.FoodItemServings.Add( new Serving<FoodItem>( dataRepository.FindFoodItem( food => food.Name == "Deluxe Bacon Cheese Burger" ), 1 ) );
             meal.FoodItemServings.Add( new Serving<FoodItem>( dataRepository.FindFoodItem( food => food.Name == "Glass of Skim Milk" ), 2 ) );

             Assert.IsTrue( meal.IsValid );
             Assert.IsNull( meal["TypeOfMeal"] );
             Assert.IsNull( meal["TimeOfMeal"] );
             Assert.IsNull( meal["FoodItemServings"] );
             Assert.AreEqual( (2.5M * 40) + 650 + (2 * 90), meal.Calories );
             Assert.AreEqual( 4, meal.FoodGroupServings.Count );
             Assert.AreEqual( 3, meal.FoodGroupServings.Find( fg => fg.Entity.Name == "Vegetable" ).Quantity );
             Assert.AreEqual( 1, meal.FoodGroupServings.Find( fg => fg.Entity.Name == "Grain" ).Quantity );
             Assert.AreEqual( 1.5M, meal.FoodGroupServings.Find( fg => fg.Entity.Name == "Meat" ).Quantity );
             Assert.AreEqual( 5, meal.FoodGroupServings.Find( fg => fg.Entity.Name == "Dairy" ).Quantity );
        }
        public void MealTemplateViewModelIsValid()
        {
            var loggerMock = new Mock<ILoggerFacade>();
             var regionNavigationServiceMock = new Mock<IRegionNavigationService>();
             var regionManagerMock = new Mock<IRegionManager>();
             var interactionServiceMock = new Mock<IInteractionService>();

             var configurationMock = new Mock<IConfiguration>();
             configurationMock.Setup( x => x.DataSource ).Returns( DataSourceType.XMLFile );
             configurationMock.Setup( x => x.FileName ).Returns( FullTestData.DataFileName );

             FullTestData.Reset();
             var dataRepository = new DataRepository( configurationMock.Object );

             MealTemplateViewModel testMealTemplateViewModel =
            new MealTemplateViewModel( dataRepository, regionManagerMock.Object, interactionServiceMock.Object, loggerMock.Object );
             NavigationContext navigationContext = new NavigationContext( regionNavigationServiceMock.Object, new Uri( "MealTemplateView", UriKind.Relative ) );
             testMealTemplateViewModel.OnNavigatedTo( navigationContext );
             Assert.IsFalse( testMealTemplateViewModel.IsValid );
             Assert.AreEqual( Messages.Error_No_Name, testMealTemplateViewModel["Name"] );
             Assert.IsNull( testMealTemplateViewModel["TimeOfMeal"] );
             Assert.AreEqual( Messages.Error_No_MealType, testMealTemplateViewModel["TypeOfMeal"] );
             Assert.AreEqual( Messages.Error_No_FoodItems, testMealTemplateViewModel["FoodItemServings"] );
             Assert.IsNull( testMealTemplateViewModel["Description"] );

             testMealTemplateViewModel.Name = "Cheeseburger Lunch";
             testMealTemplateViewModel.TimeOfMeal = DateTime.Now;
             testMealTemplateViewModel.TypeOfMeal =
            dataRepository.FindMealType( mt => mt.Name == "Lunch" );
             testMealTemplateViewModel.FoodItemServings.Add(
            new ServingViewModel<FoodItem>(
               dataRepository.FindFoodItem( f => f.Name == "Fruit Salad" ), 1 ) );
             Assert.IsFalse( testMealTemplateViewModel.IsValid );
             Assert.AreEqual( Messages.Error_MealTemplate_Exists, testMealTemplateViewModel.Error );
             Assert.AreEqual( Messages.Error_MealTemplate_Exists, testMealTemplateViewModel["Name"] );
             Assert.IsTrue( String.IsNullOrEmpty( testMealTemplateViewModel["TimeOfMeal"] ) );
             Assert.IsTrue( String.IsNullOrEmpty( testMealTemplateViewModel["TypeOfMeal"] ) );
             Assert.IsTrue( String.IsNullOrEmpty( testMealTemplateViewModel["FoodItemServings"] ) );
             Assert.IsTrue( String.IsNullOrEmpty( testMealTemplateViewModel["Description"] ) );

             testMealTemplateViewModel.Name = "Some Unique Name";
             Assert.IsTrue( testMealTemplateViewModel.IsValid );
             Assert.IsTrue( String.IsNullOrEmpty( testMealTemplateViewModel.Error ) );
             Assert.IsTrue( String.IsNullOrEmpty( testMealTemplateViewModel["Name"] ) );
             Assert.IsTrue( String.IsNullOrEmpty( testMealTemplateViewModel["TimeOfMeal"] ) );
             Assert.IsTrue( String.IsNullOrEmpty( testMealTemplateViewModel["TypeOfMeal"] ) );
             Assert.IsTrue( String.IsNullOrEmpty( testMealTemplateViewModel["FoodItemServings"] ) );
             Assert.IsTrue( String.IsNullOrEmpty( testMealTemplateViewModel["Description"] ) );
        }