예제 #1
0
        public async Task RemoveItemForUser_ShouldRemoveItem_IfUserItemCanBeFoundByItemName()
        {
            using (ApplicationDbContext context = ApplicationDbContextHelper.GetContext())
            {
                // Arrange
                IMapper mapper          = GetAutoMapperMapper();
                var     userItemQueries = new UserItemQueries(context, mapper);
                int     userId          = 1;
                int     itemId          = 1;
                string  itemName        = "Shortsword";
                context.Add(new Item {
                    Id = itemId, Name = itemName
                });
                context.Add(new UserItem {
                    ItemId = itemId, UserId = userId
                });
                context.SaveChanges();

                // Act
                await userItemQueries.RemoveItemForUser(userId, new ItemDto { Name = itemName });

                // Assert
                Assert.Empty(context.UserItems);
            }
        }
예제 #2
0
        public async Task RemoveItemForUser_ShouldDoNothing_IfUserItemCannotBeFound()
        {
            using (ApplicationDbContext context = ApplicationDbContextHelper.GetContext())
            {
                // Arrange
                IMapper mapper          = GetAutoMapperMapper();
                var     userItemQueries = new UserItemQueries(context, mapper);
                int     itemId          = 1;
                context.Add(new UserItem {
                    Id = itemId, UserId = 2
                });
                context.SaveChanges();

                // Act
                await userItemQueries.RemoveItemForUser(1, new ItemDto { Id = itemId });

                // Assert
                Assert.Single(context.UserItems);
            }
        }