public void ExportsAndImportsMealsAndMealNamesAndProductsAndCategories() { var meal = factories.Meals[0]; var mealName = factories.MealNames[0]; var product = factories.Products[0]; var category = factories.Categories[0]; var sut = new ExportAndImportImpl(factories); var data = sut.Export(); factories.Meals.Clear(); factories.MealNames.Clear(); factories.Products.Clear(); factories.Categories.Clear(); var empty = new Meal(); empty.InitializeItems(new List<MealItem>()); meal.CopyItemsFrom(empty); Assert.IsEmpty(meal.Items); sut.Import(data); Assert.AreEqual(meal.Id, factories.Meals[0].Id); Assert.AreEqual(meal.Items[0].Value, factories.Meals[0].Items[0].Value); Assert.AreEqual(mealName.Id, factories.MealNames[0].Id); Assert.AreEqual(product.Id, factories.Products[0].Id); Assert.AreEqual(category.Id, factories.Categories[0].Id); sut.Import(data); Assert.AreEqual(1, factories.Meals.Count); Assert.AreEqual(1, factories.MealNames.Count); Assert.AreEqual(1, factories.Products.Count); Assert.AreEqual(1, factories.Categories.Count); }
public void TestInitialize() { factories = Substitute.For<Factories>(); meal = new Meal(); sut = new MealViewModel(meal, factories); meal.SetOwner(factories); meal.InitializeItems(new List<MealItem>()); factories.CreateMealItem().Returns(_ => { var mealItem = new MealItem(); mealItem.SetOwner(factories); return mealItem; }); var fixture = new Fixture(); factories.Products.Returns(fixture.CreateMany<Product>(10).ToList()); factories.Finder.Returns(new FinderImpl(factories)); }
private void SetupMeals() { var meal = new Meal(); meal.SetOwner(factories); meal.Id = Guid.NewGuid(); var mealItem = new MealItem(); mealItem.SetOwner(factories); mealItem.Value = 100; meal.InitializeItems(new List<MealItem> { mealItem }); factories.Meals.Returns(new List<Meal> { meal }); factories.CreateMeal().Returns(_ => { factories.Meals.Add(meal); return meal; }); }
public void TestInitialize() { meal = new Meal { Id = Guid.NewGuid() }; meal.InitializeItems(new List<MealItem>()); factories = Substitute.For<Factories>(); factories.Finder.FindMealById(meal.Id).Returns(meal); factories.MealNames.Returns(new List<MealName>()); factories.MealNames.Add(new MealName { Id = Guid.NewGuid() }); factories.DefaultEntities.MealName.Returns(new MealName { Id = Guid.NewGuid() }); trial = Substitute.For<TrialViewModel>(); backNavigation = new MealEditingViewModel.BackNavigation(); messageDialog = Substitute.For<MessageDialog>(); sut = new MealEditingViewModel(factories, new BackgroundWorkerSyncFactory(), trial, backNavigation, new MealItemEditingViewModel(), messageDialog); sut.Navigator = Substitute.For<Navigator>(); stateProvider = Substitute.For<StateProvider>(); sut.StateProvider = stateProvider; sut.Init(new MealEditingViewModel.Navigation { MealIdToEdit = meal.Id }); }