コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }