public void Load_IfBadIngredientFormat_ShouldThrowFileFormatException() { // arrange RecipeRepository repository = new RecipeRepository(@"..\..\App_Data\Recipes_BadIngredientFormat.txt"); // act repository.Load(); // assert is partly handled by ExpectedException Assert.Fail("Expected a FileFormatException, but no one thrown."); }
public void Load_After_RecipesShouldBeSorted() { // arrange RecipeRepository repository = new RecipeRepository(@"..\..\App_Data\Recipes_OK.txt"); // act repository.Load(); var sorted = repository.GetAll().OrderBy(r => r.Name); // assert Assert.IsTrue(sorted.SequenceEqual(repository.GetAll())); }
public void Load_After_IsModifiedShouldBeFalse() { // arrange RecipeRepository repository = new RecipeRepository(@"..\..\App_Data\Recipes_OK.txt"); typeof(RecipeRepository).GetProperty("IsModified").SetValue(repository, true); // act repository.Load(); // assert Assert.IsFalse(repository.IsModified); }
public void Load_After_ShouldFireRecipesChangeEvent() { // arrange RecipeRepository repository = new RecipeRepository(@"..\..\App_Data\Recipes_OK.txt"); bool eventHandled = false; repository.RecipesChangedEvent += (s, e) => { eventHandled = true; }; // act repository.Load(); // assert Assert.IsTrue(eventHandled); }
public void Load_IfEmptyRow_ShouldNotThrowException() { // arrange RecipeRepository repository = new RecipeRepository(@"..\..\App_Data\Recipes_EmptyRows.txt"); try { // act repository.Load(); } catch (Exception ex) { // assert Assert.Fail("Expected no exception, but got: " + ex.GetType()); } }
public void Load_IfFileNotFound_ShouldThrowFileNotFoundException() { // arrange RecipeRepository repository = new RecipeRepository(@"..\..\App_Data\Recipes_FileNotFound.txt"); // act repository.Load(); // assert is handled by ExpectedException }