Ejemplo n.º 1
0
        public async Task GetMatchingItemsForUser_ShouldReturnNull_IfUserCannotBeMatchedOrDataDoesntExist()
        {
            using (ApplicationDbContext context = ApplicationDbContextHelper.GetContext())
            {
                // Arrange
                IMapper mapper          = GetAutoMapperMapper();
                var     userItemQueries = new UserItemQueries(context, mapper);

                // Act
                UserItemDto userItem = await userItemQueries
                                       .GetMatchingItemsForUser(1, new ItemDto { Id = 1, Name = "Weapon" });

                // Assert
                Assert.Null(userItem);
            }
        }
Ejemplo n.º 2
0
        public async Task GetMatchingItemsForUser_ShouldReturnUserItem_IfUserAndItemIdCanBeMatched()
        {
            using (ApplicationDbContext context = ApplicationDbContextHelper.GetContext())
            {
                // Arrange
                int    userId   = 1;
                string userName = "******";
                context.Add(new User {
                    Id = userId, Name = userName
                });

                int    numberOfSwords = 46;
                int    swordId        = 1;
                string swordName      = "Longsword";
                context.Add(new Item {
                    Id = swordId, Name = swordName
                });

                for (int i = 0; i < numberOfSwords; i++)
                {
                    context.Add(new UserItem {
                        ItemId = swordId, UserId = userId
                    });
                }

                context.SaveChanges();

                IMapper mapper          = GetAutoMapperMapper();
                var     userItemQueries = new UserItemQueries(context, mapper);

                // Act
                UserItemDto userItem = await userItemQueries
                                       .GetMatchingItemsForUser(userId, new ItemDto { Id = swordId });

                // Assert
                Assert.NotNull(userItem);
                Assert.Equal(userId, userItem.UserId);
                Assert.Equal(userName, userItem.UserName);
                Assert.Equal(numberOfSwords, userItem.ItemCount);
                Assert.Equal(swordId, userItem.ItemId);
                Assert.Equal(swordName, userItem.ItemName);
            }
        }