コード例 #1
0
        public void FoodItemNodeViewModelRemoveFoodItem()
        {
            var configurationMock = new Mock<IConfiguration>();
             configurationMock.Setup( x => x.DataSource ).Returns( DataSourceType.XMLFile );
             configurationMock.Setup( x => x.FileName ).Returns( FullTestData.DataFileName );

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

             FoodItemNodeViewModel foodItemNodeViewModel = new FoodItemNodeViewModel( dataRepository, null );

             Int32 originalChildCount = foodItemNodeViewModel.Children.Count;

             FoodItem removedFoodItem = dataRepository.GetAllFoodItems().ElementAt( 0 );
             dataRepository.Remove( removedFoodItem );
             Assert.AreEqual( originalChildCount - 1, foodItemNodeViewModel.Children.Count );

             foreach (ClickableTreeNodeViewModel node in foodItemNodeViewModel.Children)
             {
            FoodItem foodItem = dataRepository.GetFoodItem( (Guid)node.Parameter );
            Assert.IsNotNull( foodItem );
            Assert.AreEqual( foodItem.Name, node.Name );
             }
        }
コード例 #2
0
        public void MealTemplateNodeViewModelRemoveMealTemplate()
        {
            var configurationMock = new Mock<IConfiguration>();
             configurationMock.Setup( x => x.DataSource ).Returns( DataSourceType.XMLFile );
             configurationMock.Setup( x => x.FileName ).Returns( FullTestData.DataFileName );

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

             MealTemplateNodeViewModel mealTemplateNodeViewModel = new MealTemplateNodeViewModel( dataRepository, null );

             Int32 originalChildCount = mealTemplateNodeViewModel.Children.Count;

             MealTemplate removedMealTemplate = dataRepository.GetAllMealTemplates().ElementAt( 0 );
             dataRepository.Remove( removedMealTemplate );
             Assert.AreEqual( originalChildCount - 1, mealTemplateNodeViewModel.Children.Count );

             foreach (ClickableTreeNodeViewModel node in mealTemplateNodeViewModel.Children)
             {
            MealTemplate mealTemplate = dataRepository.GetMealTemplate( (Guid)node.Parameter );
            Assert.IsNotNull( mealTemplate );
            Assert.AreEqual( mealTemplate.Name, node.Name );
             }
        }