Beispiel #1
0
        public async Task ListAllUsersAsync_ReturnUsers()
        {
            var userId = "userId";

            var userManagerWrapperMocked = new Mock <IUserManagerWrapper <User> >();
            var mappingProviderMocked    = new Mock <IMappingProvider>();
            var dateTimeWrapperMocked    = new Mock <IDateTimeWrapper>();

            AccountTestUtils.ResetAutoMapper();
            AccountTestUtils.InitializeAutoMapper();
            AccountTestUtils.GetContextWithUser(nameof(ListAllUsersAsync_ReturnUsers), userId);

            using (var assertContext = new AlphaHotelDbContext(AccountTestUtils.GetOptions(nameof(ListAllUsersAsync_ReturnUsers))))
            {
                var accountService = new AccountService(assertContext, userManagerWrapperMocked.Object, mappingProviderMocked.Object, dateTimeWrapperMocked.Object);

                var accountDTO = await accountService.ListAllUsersAsync();

                Assert.AreEqual(1, accountDTO.Count);
            }
        }
        public async Task ReturnUser_WhenUserIsFound()
        {
            var userId = "userId";
            var user   = new User()
            {
                Id = userId
            };

            var userManagerWrapperMocked = new Mock <IUserManagerWrapper <User> >();
            var mappingProviderMocked    = new Mock <IMappingProvider>();
            var dateTimeWrapperMocked    = new Mock <IDateTimeWrapper>();
            var role  = "manager";
            var roles = new List <string> {
                role
            };
            var accountDetailsDTO = new AccountDetailsDTO
            {
                Id = userId
            };

            userManagerWrapperMocked.Setup(um => um.GetRolesAsync(It.IsAny <User>())).ReturnsAsync(roles);

            User mapInput = user;

            mappingProviderMocked.Setup(mpm => mpm.MapTo <AccountDetailsDTO>(It.IsAny <User>()))
            .Returns(accountDetailsDTO);

            AccountTestUtils.GetContextWithUser(nameof(ReturnUser_WhenUserIsFound), userId);

            using (var assertContext = new AlphaHotelDbContext(AccountTestUtils.GetOptions(nameof(ReturnUser_WhenUserIsFound))))
            {
                var accountService = new AccountService(assertContext, userManagerWrapperMocked.Object, mappingProviderMocked.Object, dateTimeWrapperMocked.Object);

                var account = await accountService.FindAccountAsync(userId);

                Assert.AreEqual(userId, mapInput.Id);
                Assert.AreEqual(role, account.Role);
            }
        }