public void UpdateUser() { var generator = new RandomObjectGenerator(); var profileId = generator.Generate<string>(); var userId = generator.Generate<int>(); var value = new Models.User(); var user = new Mock<IUser>(MockBehavior.Strict); user.SetupSet(_ => _.BirthDate = value.BirthDate); user.SetupSet(_ => _.EmailAddress = value.EmailAddress); user.SetupSet(_ => _.FirstName = value.FirstName); user.SetupSet(_ => _.Gender = value.Gender); user.SetupSet(_ => _.LastName = value.LastName); user.SetupSet(_ => _.PostalCode = value.PostalCode); user.SetupSet(_ => _.UserName = value.UserName); user.SetupGet(_ => _.UserID).Returns(userId); user.SetupGet(_ => _.UserName).Returns(default(string)); user.SetupGet(_ => _.BirthDate).Returns(default(DateTime)); user.SetupGet(_ => _.EmailAddress).Returns(default(string)); user.SetupGet(_ => _.FirstName).Returns(default(string)); user.SetupGet(_ => _.Gender).Returns(default(string)); user.SetupGet(_ => _.LastName).Returns(default(string)); user.SetupGet(_ => _.PostalCode).Returns(default(string)); user.Setup(_ => _.Save()).Returns(null); var userFactory = new Mock<IObjectFactory<IUser>>(MockBehavior.Strict); userFactory.Setup(_ => _.Fetch(profileId)).Returns(user.Object); var auth = new Mock<IMyVoteAuthentication>(MockBehavior.Strict); auth.Setup(_ => _.GetCurrentUserID()).Returns(userId); var controller = new UserController(); controller.UserFactory = userFactory.Object; controller.MyVoteAuthentication = auth.Object; controller.Put(profileId, value); auth.VerifyAll(); userFactory.VerifyAll(); user.VerifyAll(); }
public void CreateUser() { var generator = new RandomObjectGenerator(); var profileId = generator.Generate<string>(); var entity = EntityCreator.Create<Models.User>(_ => _.ProfileID = profileId); var user = new Mock<IUser>(MockBehavior.Strict); user.SetupSet(_ => _.BirthDate = entity.BirthDate); user.SetupSet(_ => _.EmailAddress = entity.EmailAddress); user.SetupSet(_ => _.FirstName = entity.FirstName); user.SetupSet(_ => _.Gender = entity.Gender); user.SetupSet(_ => _.LastName = entity.LastName); user.SetupSet(_ => _.PostalCode = entity.PostalCode); user.SetupSet(_ => _.UserName = entity.UserName); user.Setup(_ => _.Save()).Returns(null); var userFactory = new Mock<IObjectFactory<IUser>>(MockBehavior.Strict); userFactory.Setup(_ => _.Create(profileId)).Returns(user.Object); var controller = new UserController(); controller.UserFactory = userFactory.Object; controller.Put(entity); userFactory.VerifyAll(); user.VerifyAll(); }