Exemplo n.º 1
0
        public void AddUser()
        {
            bool insertwasCalled = false;
            var  user            = new DM.User()
            {
                FirstName = "John", LastName = "Smith", Gender = "Male", City = "Edision", Password = "******", IsDeleted = false
            };
            var entityuser = new DE.User()
            {
                UserFirstName = "John", UserLastName = "Smith", Gender = "Male", City = "Edision", Password = "******", IsDeleted = false
            };

            Mock <IUserRepository> repositoryMock = new Mock <IUserRepository>();

            repositoryMock.Setup(x => x.Add(entityuser)).Callback(() =>
            {
                insertwasCalled = true;
            });

            var userService = new UserService(repositoryMock.Object);

            userService.Add(user);
            Assert.IsFalse(insertwasCalled, "Search was not called.");

            //Assert.AreEqual(true, result);
            // userService.VerifyAll();
            //Assert.AreEqual(result, true);
        }
Exemplo n.º 2
0
 public static DE.tblUser Map(DM.User user)
 {
     return(new DE.tblUser
     {
         UserId = user.UserId,
         UserFirstName = user.FirstName,
         UserLastName = user.LastName,
         Password = user.Password,
         City = user.City,
         Gender = user.Gender,
         //Department = new DE.Department
         //{
         //    DepartmentID = user.Department.DepartmentId,
         //    Name = user.Department.DepartmentName
         //},
         LastModifiedOn = DateTime.Now,
         LastModifiedBy = "TestUser",
         IsDeleted = false
     });
 }
Exemplo n.º 3
0
        public void UserControllerCreateTest()
        {
            bool insertwasCalled = false;
            var  user            = new DM.User()
            {
                FirstName = "", LastName = "Smith", Gender = "Male", City = "Edision", Password = "******", IsDeleted = false, Department = new DM.Department()
                {
                    DepartmentName = "test", DepartmentId = 1
                }
            };
            Mock <IUserService>       userServiceMoq       = new Mock <IUserService>();
            Mock <IDepartmentService> departmentServiceMoq = new Mock <IDepartmentService>();

            userServiceMoq.Setup(x => x.Add(user)).Callback(() =>
            {
                insertwasCalled = true;
            });

            departmentServiceMoq.Setup(x => x.GetAllDepartments()).Returns(() =>
            {
                return(new List <DM.Department>()
                {
                    new DM.Department()
                    {
                        DepartmentId = 1, DepartmentName = "test"
                    },
                    new DM.Department()
                    {
                        DepartmentId = 2, DepartmentName = "dgfdg"
                    }
                });
            });

            UserController controller = new UserController(userServiceMoq.Object, departmentServiceMoq.Object);
            ViewResult     result     = controller.Create(user) as ViewResult;

            Assert.IsTrue(insertwasCalled, "something wrong");
        }
Exemplo n.º 4
0
 public void Delete(DM.User user)
 {
     userRepo.Delete(Mapper.Map <DE.User>(user));
 }
Exemplo n.º 5
0
 public void Edit(DM.User user)
 {
     userRepo.Edit(Mapper.Map <DE.User>(user));
 }
Exemplo n.º 6
0
 public void Add(DM.User user)
 {
     userRepo.Add(Mapper.Map <DE.User>(user));
 }