コード例 #1
0
        public async Task GetByIdAsync_WithExistentId_ShouldReturnCorrectResult()
        {
            var errorMessagePrefix = "ShoppingListService GetByIdAsync() method does not work properly.";

            // Arrange
            MapperInitializer.InitializeMapper();
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();

            await this.SeedDataAsync(context);

            var shoppingListRepository = new EfDeletableEntityRepository <ShoppingList>(context);
            var shoppingListService    = new ShoppingListService(shoppingListRepository);
            var existentId             = shoppingListRepository.All().First().Id;

            // Act
            var actualResult = await shoppingListService.GetByIdAsync(existentId);

            var expectedResult = (await shoppingListRepository
                                  .All()
                                  .SingleOrDefaultAsync(x => x.Id == existentId))
                                 .To <ShoppingListServiceModel>();

            // Assert
            Assert.True(actualResult.Id == expectedResult.Id, errorMessagePrefix + " " + "Id is not returned properly.");
            Assert.True(actualResult.Ingredients == expectedResult.Ingredients, errorMessagePrefix + " " + "Ingredients are not returned properly.");
            Assert.True(actualResult.RecipeId == expectedResult.RecipeId, errorMessagePrefix + " " + "RecipeId is not returned properly.");
        }
コード例 #2
0
        public async Task GetByIdAsync_WithNonExistentId_ShouldThrowArgumentNullException()
        {
            // Arrange
            MapperInitializer.InitializeMapper();
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();
            var shoppingListRepository = new EfDeletableEntityRepository <ShoppingList>(context);
            var shoppingListService    = new ShoppingListService(shoppingListRepository);
            var nonExistentId          = Guid.NewGuid().ToString();

            // Act

            // Assert
            await Assert.ThrowsAsync <ArgumentNullException>(async() =>
            {
                await shoppingListService.GetByIdAsync(nonExistentId);
            });
        }