Exemplo n.º 1
0
        public void DeleteWillNotDeleteYourself()
        {
            var userid = new ObjectId("abc123");
            var email = "*****@*****.**";
            var user = new User {Id = userid, Email=email};

            var contextuser = new Mock<IPrincipal>();
            var context = new Mock<HttpContextBase>();
            var response = new Mock<HttpResponseBase>();
            var identity = new Mock<IIdentity>();
            identity.SetupGet(i => i.Name).Returns(email);
            contextuser.Setup(u => u.Identity).Returns(identity.Object);
            context.Setup(h => h.Response).Returns(response.Object);
            context.Setup(h => h.User).Returns(contextuser.Object);

            var session = new Mock<IPersistenceSession>();
            session.Setup(s => s.Single<User>(It.IsAny<Expression<Func<User, bool>>>())).Returns(user);

            var controller = new UserController(session.Object);
            controller.ControllerContext = new ControllerContext(context.Object, new RouteData(), controller);

            var result = controller.Delete(userid) as ViewResult;
            session.Verify(s => s.Single<User>(It.IsAny<Expression<Func<User, bool>>>()), Times.Once());
            session.Verify(s => s.Delete<User>(It.IsAny<User>()), Times.Never());
        }
Exemplo n.º 2
0
        public void IndexShouldReturnView()
        {
            var controller = new UserController(M<IPersistenceSession>());

            var result = controller.Index(null) as ViewResult;

            Assert.That(result,Is.Not.Null);
            Assert.That(result.Model, Is.InstanceOf(typeof(IList<UserViewModel>)));
        }