Пример #1
0
        public async void Login_Successful(string userName, string password)
        {
            //ARRANGE
            var fakeUserManager = new Mock <FakeUserManager>();

            _context.Users.AddRange(GetFakeData().AsQueryable());
            _context.SaveChanges();

            var userToCheck = await _context.Users.FirstOrDefaultAsync(u => u.UserName == userName);

            fakeUserManager.Setup(x => x.Users)
            .Returns(_context.Users);

            fakeUserManager.Setup(x => x.CheckPasswordAsync(userToCheck, "12345678"))
            .ReturnsAsync(true);
            fakeUserManager.Setup(x => x.GetRolesAsync(userToCheck)).ReturnsAsync(new List <string> {
                "Admin", "Member", "Moderator"
            });

            var mediator = new Mock <IMediator>();

            LoginUserCommandHandler loginHandler = new LoginUserCommandHandler(_context, mediator.Object, _mapper, _configuration, fakeUserManager.Object);

            //ACT
            var result = await loginHandler.Handle(new UserForLoginDto { Username = userName, Password = password }, new System.Threading.CancellationToken());

            //ASSERT
            Assert.NotNull(result.Data.Token);
        }
Пример #2
0
        private bool SavePhoto(Photo newPhoto)
        {
            bool result = false;

            try
            {
                _context.Photos.Add(newPhoto);
                _context.SaveChanges();
                result = true;
            }
            catch (System.Exception ex)
            {
                _logger.LogError(ex.Message);
            }

            return(result);
        }
Пример #3
0
        public bool SaveMessage(Message message)
        {
            var result = false;

            try
            {
                _context.Messages.Add(message);
                _context.SaveChanges();
                result = true;
            }
            catch (System.Exception ex)
            {
                _logger.LogError(ex.Message);
            }

            return(result);
        }
Пример #4
0
        public bool SaveUser(User user)
        {
            var result = false;

            try
            {
                _context.Users.Add(user);
                _context.SaveChanges();
                result = true;
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
            }

            return(result);
        }
Пример #5
0
 public static void SeedUsers(DatingDbContext datingDbContext)
 {
     if (!datingDbContext.Users.Any())
     {
         var userData = System.IO.File.ReadAllText("../DatingApp.Data/SeedData/UserSeedData.json");
         var users    = JsonConvert.DeserializeObject <List <User> >(userData);
         foreach (var user in users)
         {
             CreatePasswordHash("password", out byte[] passwordSalt, out byte[] passwordHash);
             user.PasswordHash = passwordHash;
             user.PasswordSalt = passwordSalt;
             user.Username     = user.Username.ToLower();
         }
         datingDbContext.AddRange(users);
         datingDbContext.SaveChanges();
     }
 }
Пример #6
0
        public bool SaveLike(string userId, string receiverId)
        {
            var result = false;

            try
            {
                var newLike = new Like {
                    SenderId   = userId,
                    ReceivedId = receiverId
                };

                _context.Likes.Add(newLike);
                _context.SaveChanges();

                result = true;
            }
            catch (System.Exception ex)
            {
                _logger.LogError(ex.Message);
            }

            return(result);
        }