public async Task AddItemForUser_ShouldDoNothing_IfValidArgumentsAndMaximumNumberOfItemsNotReached() { using (ApplicationDbContext context = ApplicationDbContextHelper.GetContext()) { // Arrange IMapper mapper = GetAutoMapperMapper(); var userItemQueries = new UserItemQueries(context, mapper); int itemId = 1; int userId = 1; context.Add(new User { Id = userId, Name = "Rick Sanchez" }); context.Add(new Item { Id = itemId, Name = "Weapon" }); for (int i = 0; i < UserItemDto.MaximumNumberOfAnyItemAllowed - 1; i++) { context.Add(new UserItem { ItemId = itemId, UserId = userId }); } context.SaveChanges(); // Act await userItemQueries.AddItemForUser(userId, new ItemDto { Id = itemId }); // Assert Assert.Equal(UserItemDto.MaximumNumberOfAnyItemAllowed, context.UserItems.Count()); } }
public async Task AddItemForUser_ShouldDoNothing_IfItemCannotBeMatched() { using (ApplicationDbContext context = ApplicationDbContextHelper.GetContext()) { // Arrange IMapper mapper = GetAutoMapperMapper(); var userItemQueries = new UserItemQueries(context, mapper); int userId = 1; context.Add(new User { Id = userId, Name = "Rick Sanchez" }); context.SaveChanges(); // Act await userItemQueries.AddItemForUser(userId, new ItemDto { Id = 1 }); await userItemQueries.AddItemForUser(userId, new ItemDto { Name = "Weapon" }); // Assert Assert.Empty(context.UserItems); } }