예제 #1
0
        public void GetMealTemplate()
        {
            var configurationMock = new Mock<IConfiguration>();
             configurationMock.Setup( x => x.DataSource ).Returns( DataSourceType.XMLFile );
             configurationMock.Setup( x => x.FileName ).Returns( FullTestData.DataFileName );

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

             // Request a food group that does not exist, should be null
             MealTemplate item = dataRepository.GetMealTemplate( Guid.NewGuid() );
             Assert.IsNull( item );

             // Request a food group that exists, show that a deep copy is returned
             // Find a food group that does exist, show that a deep copy is returned
             item = dataRepository.GetMealTemplate( FullTestData.FruitSaladBreakfastID );
             Assert.AreEqual( "Fruity Breakfast", item.Name );
             Assert.AreEqual( FullTestData.FruitSaladBreakfastID, item.ID );
             MealTemplate sameItem = dataRepository.GetMealTemplate( FullTestData.FruitSaladBreakfastID );
             Assert.AreEqual( item.ID, sameItem.ID );
             Assert.AreNotEqual( item, sameItem );  // Show deep copy

             // Verify that changes to the first found food group do not affect changes to what is logically
             // the same food group returned by the second find (IOW, show they are deep copies).
             item.Name = "Something healthy, for a change";
             Assert.AreEqual( "Something healthy, for a change", item.Name );
             Assert.AreEqual( "Fruity Breakfast", sameItem.Name );
        }