public async Task AddToFavoritesListShouldBeEmptyAutopartAddedToFavoritesTwice() { var list = new List <Favorite>(); var mockRepository = new Mock <IDeletableEntityRepository <Favorite> >(); mockRepository .Setup(x => x.AllAsNoTracking()) .Returns(list.AsQueryable()); mockRepository .Setup(x => x.AddAsync(It.IsAny <Favorite>())) .Callback( (Favorite favorite) => list.Add(favorite)); mockRepository .Setup(x => x.HardDelete(It.IsAny <Favorite>())) .Callback( (Favorite favorite) => list.Remove(favorite)); var service = new FavoritesService(mockRepository.Object); var userId = "User_01"; await service.AddToFavoriteAsync(userId, 1); await service.AddToFavoriteAsync(userId, 1); Assert.Empty(list); }
public async Task OneUserShouldBeAbleToAddMultipleAutoparts() { var list = new List <Favorite>(); var mockRepository = new Mock <IDeletableEntityRepository <Favorite> >(); mockRepository .Setup(x => x.AllAsNoTracking()) .Returns(list.AsQueryable()); mockRepository .Setup(x => x.AddAsync(It.IsAny <Favorite>())).Callback( (Favorite favorite) => list.Add(favorite)); mockRepository .Setup(x => x.HardDelete(It.IsAny <Favorite>())).Callback( (Favorite favorite) => list.Remove(favorite)); var service = new FavoritesService(mockRepository.Object); var userId = "User_01"; var favoritesCount = 4; for (int i = 0; i < favoritesCount; i++) { await service.AddToFavoriteAsync(userId, i); } Assert.Equal(favoritesCount, list.Count); }
public async Task AddToFavoritesListShouldHaveCountOfOneWhenDoneOnce() { var list = new List <Favorite>(); var mockRepository = new Mock <IDeletableEntityRepository <Favorite> >(); mockRepository .Setup(x => x.AllAsNoTracking()) .Returns(list.AsQueryable()); mockRepository .Setup(x => x.AddAsync(It.IsAny <Favorite>())) .Callback( (Favorite favorite) => list.Add(favorite)); var service = new FavoritesService(mockRepository.Object); var userId = "User_01"; await service.AddToFavoriteAsync(userId, 1); Assert.Single(list); }