private static User MapRecord(IDataRecord record) { var user = new User { Id = record.Get<Guid>(SelectParameters.UserId), UserName = record.Get<string>(SelectParameters.UserName), Extension = new UserExtension { UserId = record.Get<Guid>(SelectParameters.UserId), UserStatusCode = record.Get<string>(SelectParameters.UserStatusCode), FirstName = record.Get<string>(SelectParameters.FirstName), LastName = record.Get<string>(SelectParameters.LastName), PrimaryBusinessId = record.Get<long?>(SelectParameters.PrimaryBusinessId), CultureCode = record.Get<string>(SelectParameters.CultureCode) }, UserMembership = new UserMembership { Email = record.Get<string>(SelectParameters.Email) } }; if (!record.IsNull(SelectParameters.UpdatedByUserId)) { user.Extension.UpdatedByUserId = record.Get<Guid>(SelectParameters.UpdatedByUserId); user.Extension.UpdatedDateTime = record.Get<DateTime>(SelectParameters.UpdatedDatetime); } return user; }
/// <summary> /// Modify User /// </summary> /// <param name="user">User</param> public void Modify(User user) { int rowsAffected = new StoredProcedures.Security.UpdateUserMapper().Execute(user.Id, user.UserName); // Check if the update was successful and return if (rowsAffected == 0) { throw new ExpectedResultException(ErrorFactory.CreateAndLogError(Errors.SRVEX30027, "UserDao.Modify", additionalDescriptionParameters: (new object[] { user.GetType().Name, user.Id }), arguments: new object[] { user.GetType().Name, user.Id })); } }
public void GetUserIsSuccessful() { // Arrange const string USERNAME = "******"; var userManager = new Mock<IUserManager>(); PropertyManagementSystemService.UserManager = userManager.Object; var user = new User { UserName = USERNAME, Extension = new UserExtension { CultureCode = "en-GB", FirstName = "Test", LastName = "Tester", PrimaryBusinessId = 1234, UserId = Guid.NewGuid() } }; userManager.Setup(u => u.GetByUserName(USERNAME)).Returns(user); // Act var userDto = PropertyManagementSystemService.GetUser(USERNAME); // Assert userManager.VerifyAll(); Assert.IsNotNull(userDto, "User object is null"); Assert.AreEqual(USERNAME, userDto.UserName, "Incorrect user object has been returned"); }
public void CreateUserWithEmptyFirstNameExpectExceptionThrown() { // Arrange var mockUserExtensionDao = new Mock<IUserExtensionDao>(); var mockUserEventDao = new Mock<IUserEventDao>(); userManager.UserEventDao = mockUserEventDao.Object; userManager.UserExtensionDao = mockUserExtensionDao.Object; var newUser = new User { UserName = TEST_USERNAME, Extension = new UserExtension {FirstName = string.Empty, LastName = "LastName", CultureCode = "en-GB"} }; mockUserExtensionDao.Setup(userExtensionDao => userExtensionDao.Create(Arg<UserExtension>.Is.Anything)); mockUserEventDao.Setup(e => e.Create(Arg<UserEvent>.Is.Anything)); try { // Act userManager.Create(newUser); // Assert Assert.Fail("An exception SRVEX30052 of type ValidationException should have been thrown"); } catch (ValidationException ex) { // Assert Assert.AreEqual(Errors.SRVEX30052.ToString(), ex.Code, "The Validation exception is not returning the right error code"); } }
public void CreateUserExpectSuccessUpdate() { // Arrange var mockUserExtensionDao = new Mock<IUserExtensionDao>(); var mockUserEventDao = new Mock<IUserEventDao>(); userManager.UserEventDao = mockUserEventDao.Object; userManager.UserExtensionDao = mockUserExtensionDao.Object; var newUser = new User { UserName = TEST_USERNAME, Extension = new UserExtension {FirstName = "FirstName", LastName = "LastName", CultureCode = "en-GB"} }; mockUserExtensionDao.Setup(userExtensionDao => userExtensionDao.Create(Arg<UserExtension>.Is.Anything)); mockUserEventDao.Setup(e => e.Create(Arg<UserEvent>.Is.Anything)); //Act userManager.Create(newUser); // Assert Assert.That(newUser, Is.Not.Null); }
public void ModifyUserWithEmptyLastNameExpectExceptionThrown() { // Arrange var updatedUser = new User() { UserName = "******", Extension = new UserExtension() { FirstName = "FirstName", LastName = string.Empty, CultureCode = "en-GB" } }; var mockUserDao = MockRepository.GenerateMock<IUserDao>(); var mockUserExtensionDao = MockRepository.GenerateMock<IUserExtensionDao>(); userManager.UserExtensionDao = mockUserExtensionDao; userManager.UserDao = mockUserDao; mockUserDao.Stub(userDao => userDao.Modify(Arg<User>.Matches(u => u == updatedUser))); mockUserExtensionDao.Stub(userExtensionDao => userExtensionDao.Modify(Arg<UserExtension>.Matches(ue => ue.LastName == updatedUser.Extension.LastName && ue.FirstName == string.Empty && ue.CultureCode == updatedUser.Extension.CultureCode))).Return(true); try { // Act userManager.Modify(updatedUser); // Assert Assert.Fail("An exception SRVEX30051 of type ValidationException should have been thrown"); } catch (ValidationException ex) { // Assert Assert.AreEqual(Errors.SRVEX30051.ToString(), ex.Code, "The Validation exception is not returning the right error code"); } }
public void ModifyUserExpectSuccessUpdate() { // Arrange var updatedUser = new User() { UserName = "******", Extension = new UserExtension() { FirstName = "FirstName", LastName = "LastName", CultureCode = "en-GB" } }; var mockUserDao = MockRepository.GenerateMock<IUserDao>(); var mockUserExtensionDao = MockRepository.GenerateMock<IUserExtensionDao>(); var mockUserEventDao = MockRepository.GenerateMock<IUserEventDao>(); userManager.UserExtensionDao = mockUserExtensionDao; userManager.UserDao = mockUserDao; userManager.UserEventDao = mockUserEventDao; mockUserDao.Expect(userDao => userDao.Modify(updatedUser)); mockUserExtensionDao.Expect(userExtensionDao => userExtensionDao.Modify(updatedUser.Extension)).Return(true); mockUserEventDao.Expect(e => e.Create(Arg<UserEvent>.Is.Anything)); // Act userManager.Modify(updatedUser); // Assert mockUserDao.VerifyAllExpectations(); mockUserExtensionDao.VerifyAllExpectations(); }