public void GetByIdShouldReturnTheSameUser()
        {
            Guid guid = new Guid("50d3ebaa-eea3-453f-8e8b-b835605b3e85");
            ApplicationUser user = new ApplicationUser()
            {
                UserName = "******",
                Id = guid.ToString(),
                FirstName = "Ivan",
                LastName = "jorkov"
            };

           // 
            var usersRepoMock = new Mock<IRepository<ApplicationUser>>();

            usersRepoMock.Setup(x => x.GetById(guid.ToString())).Returns(user);


            var uofMock = new Mock<IUnitOfWorkData>();
            uofMock.Setup(x => x.Users).Returns(usersRepoMock.Object);
           
            var controller = new UserController(uofMock.Object);

            var viewResult = controller.Details(guid.ToString()) as ViewResult;
            Assert.IsNotNull(viewResult, "Index action returns null.");

            var model = viewResult.Model as UserViewModel;
            Assert.IsNotNull(model, "The model is null.");
            Assert.AreEqual(user.LastName, model.LastName);
            Assert.AreEqual(user.FirstName, model.FirstName);
            Assert.AreEqual(user.Id, model.Id);            
        }
Пример #2
0
 public static UserViewModel CreateFromUser(ApplicationUser user)
 {
     return new UserViewModel()
     {
         Id = user.Id,
         FirstName = user.FirstName,
         LastName = user.LastName,
         ShoppingCart = user.ShoppingCart
     };
 }
        public void IndexShouldReturnTheProperNumberOfUsers()
        {
            Guid guid = new Guid("50d3ebaa-eea3-453f-8e8b-b835605b3e85");
            Guid guid1 = new Guid("50d3ebaa-eea3-453f-8e8b-b835605b3e81");
            ApplicationUser user = new ApplicationUser()
            {
                UserName = "******",
                Id = guid.ToString(),
                FirstName = "Ivan",
                LastName = "jorkov"
            };

            ApplicationUser user1 = new ApplicationUser()
            {
                UserName = "******",
                Id = guid1.ToString(),
                FirstName = "Ivan",
                LastName = "jorkov"
            };
            List<ApplicationUser> users = new List<ApplicationUser>();
            users.Add(user);
            users.Add(user1);
            var usersRepoMock = new Mock<IRepository<ApplicationUser>>();

            usersRepoMock.Setup(x => x.All()).Returns(users.AsQueryable());


            var uofMock = new Mock<IUnitOfWorkData>();
            uofMock.Setup(x => x.Users).Returns(usersRepoMock.Object);

            var controller = new UserController(uofMock.Object);

            var viewResult = controller.Index() as ViewResult;
            Assert.IsNotNull(viewResult, "Index action returns null.");

            var model = viewResult.Model as IEnumerable<UserViewModel>;
            Assert.IsNotNull(model, "The model is null.");
            Assert.AreEqual(2, model.Count());            
        }
Пример #4
0
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                // Create a local login before signing in the user
                var user = new ApplicationUser()
                {
                    UserName = model.UserName,
                    FirstName = model.FirstName,
                    LastName = model.LastName
                };

                // Added by Yoan : additonal information

                user.ShoppingCart = new ShoppingCart()
                {
                    Id = Guid.NewGuid(),
                    Owner = user
                };

                user.CreditCard = new CreditCard()
                {
                    Id = Guid.NewGuid(),
                    Funds = 10000,
                    CardNumber = model.CardNumber,
                    Owner = user
                };

                var result = await IdentityManager.Users.CreateLocalUserAsync(user, model.Password);
                if (result.Success)
                {
                    await IdentityManager.Authentication.SignInAsync(AuthenticationManager, user.Id, isPersistent: false);
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    AddErrors(result);
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }