Exemplo n.º 1
0
        public void ShouldRemoveUserInMemory()
        {
            var user = new User()
            {
                Email          = "*****@*****.**",
                Guid           = System.Guid.NewGuid().ToString(),
                HashedPassword = "******",
                Name           = "name",
                Role           = "admin",
                Surname        = "dksk"
            };

            var mockSet = new MockDbSet <User>();

            var mockContext = new Mock <WorkSiteDbContext>();

            mockContext.Setup(c => c.Set <User>()).Returns(mockSet.Object);

            using (var uow = new WorkSiteUow(mockContext.Object))
            {
                uow.Users.Create(user);
                uow.Save();
                uow.Users.Delete(user.Guid);
                uow.Save();
            }

            mockSet.Verify(u => u.Remove(It.IsNotIn(user)), Times.Never);
        }
Exemplo n.º 2
0
        public void ShouldFindUser()
        {
            var user = new User()
            {
                Email          = "*****@*****.**",
                Guid           = System.Guid.NewGuid().ToString(),
                HashedPassword = "******",
                Name           = "name",
                Role           = "admin",
                Surname        = "dksk"
            };

            var mockSet = new MockDbSet <User>();

            var mockContext = new Mock <WorkSiteDbContext>();

            mockContext.Setup(c => c.Set <User>()).Returns(mockSet.Object);

            User res;

            using (var uow = new WorkSiteUow(mockContext.Object))
            {
                uow.Users.Create(user);
                uow.Save();
                res = uow.Users.Read(user.Guid);
            }
            Assert.Null(res);
        }
Exemplo n.º 3
0
        public void CreateUser(UserDto u, string password, string role)
        {
            u.Guid           = Guid.NewGuid().ToString();
            u.Role           = role;
            u.HashedPassword = SecurePasswordHasher.Hash(password);

            var mapper = _businessDbUser.CreateMapper();

            var destination = mapper.Map <UserDto, User>(u);

            try
            {
                _uow.Users.Create(destination);
                _uow.Save();
            }
            catch (Exception)
            {
                throw new InvalidUserException();
            }
        }
Exemplo n.º 4
0
        public void AddVacation(VacationDto vacation, UserDto user)
        {
            vacation.Guid = System.Guid.NewGuid().ToString();
            vacation.User = user;

            var mapper = _businessDbVacationConfig.CreateMapper();

            var dest = mapper.Map <VacationDto, Vacation>(vacation);

            try
            {
                _uow.Vacations.Create(dest);
                _uow.Save();
            }
            catch (Exception)
            {
                throw new InvalidVacationException();
            }
        }