Example #1
0
        public async Task GetShoppingListsByUserIdAsync_WithExistentUserId_ShouldReturnCorrectResult()
        {
            var errorMessagePrefix = "UserShoppingListService GetShoppingListsByUserIdAsync() method does not work properly.";

            // Arrange
            MapperInitializer.InitializeMapper();
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();
            var userShoppingListRepository = new EfRepository <UserShoppingList>(context);
            var userShoppingListService    = new UserShoppingListService(userShoppingListRepository);

            await this.SeedDataAsync(context);

            var userId = context.Users.First(x => x.FullName == "User 1").Id;

            // Act
            var actualResult = (await userShoppingListService
                                .GetShoppingListsByUserIdAsync(userId))
                               .ToList();
            var expectedResult = userShoppingListRepository
                                 .All()
                                 .Where(x => x.UserId == userId)
                                 .OrderBy(x => x.AddedOn)
                                 .Select(x => x.ShoppingList)
                                 .To <ShoppingListServiceModel>()
                                 .ToList();

            // Assert
            Assert.True(expectedResult.Count() == actualResult.Count(), errorMessagePrefix + " " + "Collections count mismatch.");

            for (int i = 0; i < actualResult.Count(); i++)
            {
                Assert.True(expectedResult[i].Id == actualResult[i].Id, errorMessagePrefix + " " + "ShoppingList is not returned properly.");
            }
        }
Example #2
0
        public async Task GetShoppingListsByUserIdAsync_WithNonExistentUserId_ShouldReturnEmptyCollection()
        {
            var errorMessagePrefix = "UserShoppingListService GetShoppingListsByUserIdAsync() method does not work properly.";

            // Arrange
            MapperInitializer.InitializeMapper();
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();
            var userShoppingListRepository = new EfRepository <UserShoppingList>(context);
            var userShoppingListService    = new UserShoppingListService(userShoppingListRepository);

            await this.SeedDataAsync(context);

            var nonExistentUserId = Guid.NewGuid().ToString();

            // Act
            var actualResult = (await userShoppingListService
                                .GetShoppingListsByUserIdAsync(nonExistentUserId))
                               .ToList()
                               .Count;
            var expectedResult = 0;

            // Assert
            Assert.True(expectedResult == actualResult, errorMessagePrefix + " " + "Collection is not empty.");
        }