public void GetCaloriesAmount_GivenFruitAndAmount_ReturnsTotalCalories() { var result = FruitRepository.GetCaloriesAmount("Apple", 350); //Apple 52cal/100g --> (52 x 350) / 100 = 182 var expectedResult = 182; Assert.Equal(expectedResult, result); }
public void GetCaloriesAmount_GivenFruitAndAmount_ReturnsZero() { var result = FruitRepository.GetCaloriesAmount("Mango", 350); //Mango is not in the fruit list var expectedResult = 0; Assert.Equal(expectedResult, result); }
protected override IEnumerable <Fruit> GetFruits() { var freshUnspoiledFruits = FruitRepository.GetAll().Where( f => IsFresh(f) && !f.IsSpoiled && f.Size == FruitSizes.Small); return(freshUnspoiledFruits); }
public void GetFruits_NewInstance_HasFourFruits() { var repo = new FruitRepository(); var fruits = repo.GetFruits(); Assert.Equal(4, fruits.Count); var anySelected = fruits.Any(x => x.Selected); Assert.False(anySelected); }
public void SelectFruits_FirstFruitSelected_NoOtherFruitShouldBeSelected() { var repo = new FruitRepository(); var ids = new[] { 1 }; repo.SelectFruits(ids); var notSelectedFruits = repo.GetFruits().Where(x => x.Selected == false); Assert.Equal(3, notSelectedFruits.Count()); }
public async Task FruitsBasketViewComponent_InitialState_ShouldHaveNoneSelected() { var repo = new FruitRepository(); var vc = new FruitsBasketViewComponent(repo); var result = await vc.InvokeAsync(VcDemoType.RazorPagesPrg) as ViewViewComponentResult; var model = result.ViewData.Model as List <Fruit>; Assert.Equal(7, model.Count); Assert.All(model, f => Assert.False(f.Selected)); }
public void SelectFruits_FirstFruitSelected_ShouldBeSelected() { var repo = new FruitRepository(); var ids = new[] { 1 }; repo.SelectFruits(ids); var firstFruit = repo.GetFruitById(ids.First()); Assert.True(firstFruit.Selected); }
public void GetFruits_NewInstance_HasNoSelectedFruits() { var repo = new FruitRepository(); var fruits = repo.GetFruits(); var anySelected = fruits.Any(x => x.Selected); Assert.False(anySelected); var selected = repo.GetSelectedFruits(); Assert.Empty(selected); }
public void GetAll_NoItems_ReturnsEmptyList() { using (var context = new ApplicationDbContext(GetDbContextOptions("GetAll_NoItems_ReturnsEmptyList"))) { // Arrange var repo = new FruitRepository(context); // Act var list = repo.GetAll().Result; // Assert Assert.Empty(list); } }
public void GetById_ItemDoesntExist_ReturnsNull() { using (var context = new ApplicationDbContext(GetDbContextOptions("GetById_ItemDoesntExist_ReturnsNull"))) { // Arrange var repo = new FruitRepository(context); // Act var item = repo.GetById(123).Result; // Assert Assert.Null(item); } }
public void DeleteById_ItemDoesntExist_ThrowsException() { using (var context = new ApplicationDbContext(GetDbContextOptions("Delete_ItemDoesntExist_ThrowsException"))) { // Arrange var repo = new FruitRepository(context); // Assert Assert.ThrowsAny <Exception>(() => { // Act repo.DeleteById(123).Wait(); }); } }
public void GetFruitWithLessCalories_GivenCaloriesAmount_ReturnsFruit() { var result = FruitRepository.GetFruitWithLessCalories(50); var expectedResult = new Fruit { Name = "Peach", Calories = 39, GramsPer = 100, GeoDistribution = "Temperate" }; var resultSerializedObject = JsonConvert.SerializeObject(result); var expectedResultSerializedObject = JsonConvert.SerializeObject(expectedResult); Assert.Equal(expectedResultSerializedObject, resultSerializedObject); }
public void GetAll_SingleItem_ReturnsListWithSingleItem() { using (var context = new ApplicationDbContext(GetDbContextOptions("GetAll_SingleItem_ReturnsListWithSingleItem"))) { // Arrange context.Fruits.Add(new Fruit { Id = 1, Color = Color.Red, Name = "Apple", Price = 2.99m, Rating = 5, Description = "An apple" }); context.SaveChanges(); var repo = new FruitRepository(context); // Act var list = repo.GetAll().Result; // Assert Assert.Single(list); } }
public void Update_ItemDoesntExist_ThrowsException() { using (var context = new ApplicationDbContext(GetDbContextOptions("Update_ItemDoesntExist_ThrowsException"))) { // Arrange var repo = new FruitRepository(context); var itemToUpdate = new Fruit { Id = 5, Color = Color.Red, Name = "Apple", Price = 2.99m, Rating = 5, Description = "An apple" }; // Assert Assert.ThrowsAny <Exception>(() => { // Act repo.Update(itemToUpdate).Wait(); }); } }
public void GetFruits_GivenGeoDistribution_ReturnsFruitList() { var result = FruitRepository.GetFruitsByGeoDistribution("Tropical"); var expectedResult = new List <Fruit> { new Fruit { Name = "Banana", Calories = 89, GramsPer = 100, GeoDistribution = "Tropical" }, new Fruit { Name = "Pineapple", Calories = 50, GramsPer = 100, GeoDistribution = "Tropical" } }; var resultSerializedObject = JsonConvert.SerializeObject(result); var expectedResultSerializedObject = JsonConvert.SerializeObject(expectedResult); Assert.Equal(expectedResultSerializedObject, resultSerializedObject); }
public void DeleteById_ItemExists_DeletesItemSuccessfully() { using (var context = new ApplicationDbContext(GetDbContextOptions("DeleteById_ItemExists_DeletesItemSuccessfully"))) { // Arrange var repo = new FruitRepository(context); var item = new Fruit { Id = 5, Color = Color.Red, Name = "Apple", Price = 2.99m, Rating = 5, Description = "An apple" }; repo.Add(item).Wait(); // Act repo.DeleteById(5).Wait(); // Assert var deletedItem = repo.GetById(5).Result; Assert.Null(deletedItem); } }
public void GetById_ItemExists_ReturnsItem() { using (var context = new ApplicationDbContext(GetDbContextOptions("GetById_ItemExists_ReturnsTheItem"))) { // Arrange context.Fruits.Add(new Fruit { Id = 1, Color = Color.Red, Name = "Apple", Price = 2.99m, Rating = 5, Description = "An apple" }); context.SaveChanges(); var repo = new FruitRepository(context); // Act var item = repo.GetById(1).Result; // Assert Assert.Equal(1, item.Id); Assert.Equal("Apple", item.Name); } }
public void Add_SingleItem_ItemAddedSuccessfully() { using (var context = new ApplicationDbContext(GetDbContextOptions("Add_SingleItem_ItemAddedSuccessfully"))) { // Arrange var repo = new FruitRepository(context); var itemToAdd = new Fruit { Id = 5, Color = Color.Red, Name = "Apple", Price = 2.99m, Rating = 5, Description = "An apple" }; // Act repo.Add(itemToAdd).Wait(); // Assert var item = repo.GetById(5).Result; Assert.NotNull(item); Assert.Equal(5, item.Id); Assert.Equal("Apple", item.Name); } }
public void Update_ItemExists_UpdatesItemSuccessfully() { using (var context = new ApplicationDbContext(GetDbContextOptions("Update_ItemExists_UpdatesItemSuccessfully"))) { // Arrange var repo = new FruitRepository(context); var item = new Fruit { Id = 5, Color = Color.Red, Name = "Apple", Price = 2.99m, Rating = 5, Description = "An apple" }; repo.Add(item).Wait(); // Act item.Name = "Banana"; repo.Update(item).Wait(); // Assert var updatedItem = repo.GetById(5).Result; Assert.NotNull(updatedItem); Assert.Equal("Banana", updatedItem.Name); } }
public async Task FruitsBasketViewComponent_SelectFruits_ShouldHaveSelected() { var repo = new FruitRepository(); var vc = new FruitsBasketViewComponent(repo); repo.SelectFruits(new[] { 1, 2, 7 }); var result = await vc.InvokeAsync(VcDemoType.RazorPagesPrg) as ViewViewComponentResult; var model = result.ViewData.Model as List <Fruit>; Assert.Equal(7, model.Count); Assert.Collection(model, f => Assert.True(f.Selected), f => Assert.True(f.Selected), f => Assert.False(f.Selected), f => Assert.False(f.Selected), f => Assert.False(f.Selected), f => Assert.False(f.Selected), f => Assert.True(f.Selected) ); }
public void ExistFruit_GivenFruitName_ReturnsFalse() { var result = FruitRepository.ExistFruit("Mango"); Assert.False(result); }
protected AbstractFruitStore() { FruitRepository = new FruitRepository(); }
public void GetFruitWithLessCalories_GivenCaloriesAmount_ReturnsNull() { var result = FruitRepository.GetFruitWithLessCalories(10); Assert.Null(result); }
public void ExistFruit_GivenFruitName_ReturnsTrue() { var result = FruitRepository.ExistFruit("Apple"); Assert.True(result); }
public MadisonAvenueFruitStore() { _fruitRepository = new FruitRepository(); }
public void GetFruits_GivenGeoDistribution_ReturnsEmpty() { var result = FruitRepository.GetFruitsByGeoDistribution("Wrong GeoDistribution"); Assert.Empty(result); }
public LexingtonAvenueFruitStore() { _fruitRepository = new FruitRepository(); }
public JsonResult GetFruits() { IList <Fruit> FruitsList = new FruitRepository().GetFruits(); return(Json(FruitsList, JsonRequestBehavior.AllowGet)); }