public void TestUpdateUserProfileProperties() { // given: User user = UserCreator.Create(); User userToUpdate = UserDao.Get(user.Id); UserContactDto userContactDto = UserCreator.CreateUserContactDto("*****@*****.**", "Nürnberger Ei", "0", "01067", "Dresden", Country.DE, "Nürnberger Eieruhren GmbH", "http://www.nuernberger-eier.de", "phone", "privat", "mobile"); UserDataDto userDataDto = UserCreator.CreateUserDataDto("neuerVorname", "neuerNachname", new DateTime(1990, 01, 03), "UserName"); UserPaymentDto userPaymentDto = new UserPaymentDto("paypal", true); UserNotificationOptionsDto notificationsDto = UserNotificationOptionsDto.AllOn; User changedBy = UserCreator.Create(); EntityChangedDto entityChangedDto = new EntityChangedDto(changedBy, new DateTime(2017, 01, 01, 01, 01, 01)); // when: userToUpdate.Update(userContactDto, userDataDto, userPaymentDto, notificationsDto, entityChangedDto); UserDao.FlushAndClear(); User actualUser = UserDao.Get(userToUpdate.Id); // then: DtoAssert.AreEqual(userContactDto, actualUser.GetUserContactDto()); DtoAssert.AreEqual(userDataDto, actualUser.GetUserDataDto()); actualUser.ChangedBy.Should().Be(entityChangedDto.ChangedBy); actualUser.ChangedAt.Should().Be(entityChangedDto.ChangedAt); }
/// <summary>Initialisiert eine neue Instanz der <see cref="T:System.Object" />-Klasse.</summary> public UpdateMeCommand() { UserContactDto = new UserContactDto(); UserDataDto = new UserDataDto(); UserPaymentDto = new UserPaymentDto(); UserNotificationOptionsDto = new UserNotificationOptionsDto(); }
public void Update(User user, string passwordHash, UserContactDto userContactDto, UserDataDto userDataDto, UserPaymentDto userPaymentDto, UserNotificationOptionsDto userNotificationOptionsDto, UserPermissionDto userPermissionDto, IList <UploadedFile> newDocuments, IList <Document> documentsToDelete, EntityChangedDto entityChangedDto) { Require.NotNull(user, "user"); Require.NotNull(userContactDto, "userContactDto"); Require.NotNull(userDataDto, "userDataDto"); Require.NotNull(userPermissionDto, "userPermissionDto"); Require.NotNull(entityChangedDto, "entityChangedDto"); Require.NotNull(documentsToDelete, "documentsToDelete"); Require.NotNull(newDocuments, "newDocuments"); IList <Document> documentsToAssign = newDocuments.Select(uf => DocumentRepository.Create(uf)).ToList(); IList <Document> userDocuments = user.Documents.Except(documentsToDelete).Concat(documentsToAssign).ToList(); if (IsDirty(user, passwordHash, userContactDto, userDataDto, userPaymentDto, userNotificationOptionsDto, userPermissionDto, userDocuments)) { user.Update(passwordHash, userContactDto, userDataDto, userPaymentDto, userNotificationOptionsDto, userPermissionDto, userDocuments, entityChangedDto); } }
public void TestUpdateUserAllProperties() { // given: User user = UserCreator.Create(); User userToUpdate = UserDao.Get(user.Id); UserContactDto userContactDto = UserCreator.CreateUserContactDto("*****@*****.**", "Nürnberger Ei", "0", "01067", "Dresden", Country.DE, "Nürnberger Eieruhren GmbH", "http://www.nuernberger-eier.de", "phone", "privat", "mobile"); string username = "******"; UserDataDto userDataDto = UserCreator.CreateUserDataDto("neuerVorname", "neuerNachname", null, username); User changedBy = UserCreator.Create(); EntityChangedDto entityChangedDto = new EntityChangedDto(changedBy, new DateTime(2017, 01, 01, 01, 01, 01)); UserPermissionDto userPermissionDto = new UserPermissionDto(new List <string> { Roles.Administrator }, true); UserNotificationOptionsDto notificationsDto = UserNotificationOptionsDto.AllOn; string passwordHash = "newPasswordhash"; List <Document> documents = new List <Document> { DocumentCreator.Create() }; UserPaymentDto userPaymentDto = new UserPaymentDto("", false); // when: userToUpdate.Update(passwordHash, userContactDto, userDataDto, userPaymentDto, notificationsDto, userPermissionDto, documents, entityChangedDto); UserDao.FlushAndClear(); User actualUser = UserDao.Get(userToUpdate.Id); // then: DtoAssert.AreEqual(userContactDto, actualUser.GetUserContactDto()); DtoAssert.AreEqual(userDataDto, actualUser.GetUserDataDto()); DtoAssert.AreEqual(notificationsDto, actualUser.GetNotificationOptions()); DtoAssert.AreEqual(userPermissionDto, actualUser.GetUserPermissionDto()); actualUser.ChangedBy.Should().Be(entityChangedDto.ChangedBy); actualUser.ChangedAt.Should().Be(entityChangedDto.ChangedAt); actualUser.UserName.Should().Be(username); actualUser.PasswordHash.Should().Be(passwordHash); actualUser.Documents.ShouldBeEquivalentTo(documents); }
/// <summary> /// Erzeugt eine neue Instanz von <see cref="UserUpdateCommand" /> /// </summary> public UserUpdateCommand() { UserContactDto = new UserContactDto(); UserDataDto = new UserDataDto(); UserPermissionDto = new UserPermissionDto(); UserPaymentDto = new UserPaymentDto(); NewDocuments = new List <UploadedFile>(); DeleteDocuments = new List <Document>(); UserNotificationOptionsDto = new UserNotificationOptionsDto(); }
/// <summary> /// Erzeugt einen neuen Nutzer /// </summary> /// <returns></returns> public User Create(string username = null, string email = "*****@*****.**", string lastname = NACHNAME_CONST, string firstname = VORNAME_CONST, string passwordHash = null, string street = STREET_CONST, string streetNumber = STREET_NUMBER_CONST, string postalCode = POSTALCODE_CONST, string city = CITY_CONST, Country countryTwoLetterIsoCode = COUNTRY_CONST, string company = COMPANY_CONST, string url = URL_CONST, string phone = null, string phonePrivate = null, string mobile = null, string fax = null, string payPalBusinessName = null, bool autoAcceptPayPalPayments = true, EntityCreatedDto creationDto = null, EntityChangedDto latestChangeDto = null, IList <string> roles = null, bool isEnabled = true, IList <Document> documents = null, DateTime?birthday = null, bool persist = true) { if (username == null) { username = GetRandomString(10); } if (firstname == VORNAME_CONST) { firstname = firstname + GetRandomString(4); } if (roles == null) { roles = new List <string> { Roles.Member }; } if (documents == null) { documents = new List <Document>(); } UserContactDto userContactDto = CreateUserContactDto(email, street, streetNumber, postalCode, city, countryTwoLetterIsoCode, company, url, phone, phonePrivate, mobile); UserDataDto userDataDto = CreateUserDataDto(firstname, lastname, birthday, username); UserPermissionDto userPermissionDto = CreateUserPermissionDto(roles, isEnabled); UserPaymentDto userPaymentDto = CreateUserPaymentDto(payPalBusinessName, autoAcceptPayPalPayments); UserNotificationOptionsDto userNotifications = UserNotificationOptionsDto.AllOn; if (creationDto == null) { creationDto = new EntityCreatedDto(null, DateTime.Now.Date); } User user = Create(username, passwordHash, userDataDto, userContactDto, userPaymentDto, userNotifications, userPermissionDto, creationDto, latestChangeDto, documents, persist); return(user); }
public override User Build() { EntityCreatedDto entityCreatedDto = new EntityCreatedDto(_createdBy, _createdAt); UserContactDto userContactDto = new UserContactDto(_email, _street, _streetNumber, _postalCode, _city, _country, _company, _url, _phone, _privatePhone, _mobile); UserDataDto userDataDto = new UserDataDto(_firstname, _lastname, _birthday, _username); UserPaymentDto userPaymentDto = new UserPaymentDto(); UserNotificationOptionsDto notificationOptions = UserNotificationOptionsDto.AllOn; UserPermissionDto userPermissionDto = new UserPermissionDto(_roles, _isEnabled); User user = new User(_passwordHash, userContactDto, userDataDto, userPaymentDto, notificationOptions, userPermissionDto, _documents, entityCreatedDto); _userDao.Save(user); _userDao.Flush(); return(user); }
/// <summary> /// Überprüft, ob es Änderungen am Nutzer gab. /// </summary> /// <param name="user">Der Nutzer in seiner ungeänderten Form.</param> /// <param name="passwordHash">Der neue PasswordHash</param> /// <param name="userContactDto">Die neuen Kontaktdaten</param> /// <param name="userDataDto">Die neuen Nutzerdaten</param> /// <param name="userPaymentDto">Die neuen Zahlungsinformationen</param> /// <param name="userPermissionDto">Die neuen Berechtigungsinformationen</param> /// <param name="userDocuments"></param> /// <returns></returns> /// <remarks> /// Wenn ein Dto oder eine Eigenschaft sowieso nicht geändert werden soll, dann den Wert nutzen, der am Nutzer /// hinterlegt ist. /// </remarks> private bool IsDirty(User user, string passwordHash, UserContactDto userContactDto, UserDataDto userDataDto, UserPaymentDto userPaymentDto, UserNotificationOptionsDto userNotificationOptionsDto, UserPermissionDto userPermissionDto, IList <Document> userDocuments) { Require.NotNull(user, "user"); Require.NotNull(userContactDto, "userContactDto"); Require.NotNull(userDataDto, "userDataDto"); Require.NotNull(userPermissionDto, "userPermissionDto"); Require.NotNull(userPaymentDto, "userPaymentDto"); Require.NotNull(userNotificationOptionsDto, "userNotificationOptionsDto"); if (user.PasswordHash != passwordHash) { return(true); } if (!Equals(user.GetUserContactDto(), userContactDto)) { return(true); } if (!Equals(user.GetUserPaymentDto(), userPaymentDto)) { return(true); } if (!Equals(user.GetUserPermissionDto(), userPermissionDto)) { return(true); } if (!Equals(user.GetUserDataDto(), userDataDto)) { return(true); } if (!Equals(user.GetNotificationOptions(), userNotificationOptionsDto)) { return(true); } if (!ListHelper.AreEquivalent(user.Documents, userDocuments)) { return(true); } return(false); }
public void Update(User user, UserContactDto userContactDto, UserDataDto userDataDto, UserPaymentDto userPaymentDto, UserNotificationOptionsDto userNotificationOptionsDto, EntityChangedDto entityChangedDto) { Require.NotNull(user, "user"); Require.NotNull(userContactDto, "userContactDto"); Require.NotNull(userDataDto, "userDataDto"); Require.NotNull(entityChangedDto, "entityChangedDto"); Require.NotNull(userPaymentDto, "userPaymentDto"); if (IsDirty(user, user.PasswordHash, userContactDto, userDataDto, userPaymentDto, userNotificationOptionsDto, user.GetUserPermissionDto(), user.Documents)) { user.Update(userContactDto, userDataDto, userPaymentDto, userNotificationOptionsDto, entityChangedDto); } }
public void TestUpdateUserProfile() { // given: User userToUpdate = UserCreator.Create(); UserContactDto userContactDto = new UserContactDto("*****@*****.**", "Straße", "1", "01234", "Stadt", Country.DE, "Unternehmen", "http://www.test.url", "phone", "privat", "mobile"); UserDataDto userDataDto = new UserDataDto("neuerVorname", "neuerNachname", new DateTime(1950, 05, 05), "UserName"); UserPaymentDto userPaymentDto = new UserPaymentDto("PayPal", true); EntityChangedDto changeDto = new EntityChangedDto(UserCreator.Create(), new DateTime(2017, 01, 01, 01, 02, 03)); UserNotificationOptionsDto notificationsDto = UserNotificationOptionsDto.AllOff; // when: UserService.Update(userToUpdate, userContactDto, userDataDto, userPaymentDto, notificationsDto, changeDto); UserService.UserDao.FlushAndClear(); User actualUser = UserService.GetById(userToUpdate.Id); // then: DtoAssert.AreEqual(userContactDto, actualUser.GetUserContactDto()); DtoAssert.AreEqual(userDataDto, actualUser.GetUserDataDto()); DtoAssert.AreEqual(notificationsDto, actualUser.GetNotificationOptions()); actualUser.ChangedBy.Should().Be(changeDto.ChangedBy); actualUser.ChangedAt.Should().Be(changeDto.ChangedAt); }
public void TestUpdateUser() { // given: Service.UserService userService = new UserService(); userService.UserDao = ContextRegistry.GetContext().GetObject <IUserDao>(); Document document1 = DocumentCreator.Create(); Document document2 = DocumentCreator.Create(); Document document3 = DocumentCreator.Create(); User userToUpdate = UserCreator.Create(documents: new [] { document1, document2 }); UploadedFile uploadedFile = new UploadedFile(new FileInfo("C:\\Temp\\passbild.png")); Mock <IDocumentRepository> fileServiceMock = new Mock <IDocumentRepository>(); fileServiceMock.Setup(s => s.Create(uploadedFile)).Returns(document3); userService.DocumentRepository = fileServiceMock.Object; // when: // UserLoginDto userLoginDto = UserUtil.CreateUserLoginDto("neuernutzer", "anderesPasswort", false); UserContactDto userContactDto = new UserContactDto("*****@*****.**", "Straße", "1", "01234", "Stadt", Country.DE, "Unternehmen", "http://www.test.url", "phone", "privat", "mobile"); const string NEW_USERNAME = "******"; const string NEW_PASSWORDHASH = "andererPasswortHash"; UserDataDto userDataDto = new UserDataDto("neuerVorname", "neuerNachname", new DateTime(2000, 02, 02), NEW_USERNAME); UserPaymentDto userPaymentDto = new UserPaymentDto("PayPal", true); UserPermissionDto userPermissionDto = UserCreator.CreateUserPermissionDto(new List <string>() { Roles.Administrator }, false); EntityChangedDto changeDto = new EntityChangedDto(UserCreator.Create(), new DateTime(2017, 01, 01, 01, 02, 03)); UserNotificationOptionsDto userNotificationsDto = UserNotificationOptionsDto.AllOff; userService.Update(userToUpdate, NEW_PASSWORDHASH, userContactDto, userDataDto, userPaymentDto, userNotificationsDto, userPermissionDto, new List <UploadedFile>() { uploadedFile }, new List <Document> { document2 }, changeDto); userService.UserDao.FlushAndClear(); User actualUser = UserService.GetById(userToUpdate.Id); // then: Assert.AreEqual(NEW_USERNAME, actualUser.UserName, "Der Nutzername wurde nicht korrekt übernommen."); Assert.AreEqual(NEW_PASSWORDHASH, actualUser.PasswordHash, "Das Passwort wurde nicht korrekt übernommen."); DtoAssert.AreEqual(userContactDto, actualUser.GetUserContactDto()); DtoAssert.AreEqual(userDataDto, actualUser.GetUserDataDto()); DtoAssert.AreEqual(userNotificationsDto, actualUser.GetNotificationOptions()); DtoAssert.AreEqual(userPermissionDto, actualUser.GetUserPermissionDto()); actualUser.Documents.Should().BeEquivalentTo(document1, document3); actualUser.ChangedBy.Should().Be(changeDto.ChangedBy); actualUser.ChangedAt.Should().Be(changeDto.ChangedAt); }
/// <summary> /// Erstellt einen zufälligen Benutzer und gibt diesen zurück wenn keine Dtos übergeben werden /// </summary> /// <returns></returns> public User Create(string username, string passwordHash, UserDataDto userDataDto, UserContactDto userContactDto, UserPaymentDto userPaymentDto, UserNotificationOptionsDto userNotifications, UserPermissionDto userPermissionDto, EntityCreatedDto entityCreatedDto, EntityChangedDto entityChangedDto, IList <Document> documents, bool persist = true) { User user = new User(passwordHash, userContactDto, userDataDto, userPaymentDto, userNotifications, userPermissionDto, documents, entityCreatedDto); if (entityChangedDto != null) { user.Update(userContactDto, userDataDto, userPaymentDto, userNotifications, entityChangedDto); } if (persist) { UserDao.Save(user); UserDao.Flush(); } return(user); }