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); } }
/// <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); }
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(); }
/// <summary> /// Erzeugt eine neue Instanz von <see cref="UserCreateCommand" /> /// </summary> public UserCreateCommand() { UserContactDto = new UserContactDto(); UserDataDto = new UserDataDto(); UserPermissionDto = new UserPermissionDto(); UserPaymentDto = new UserPaymentDto(); }
private IPaymentTarget BuildPaymentAdapter(UserPaymentDto userPayment) { var mechantAccount = new MerchantAccount(); mechantAccount.SetMerchantAccountType(userPayment.Provider); IPaymentTarget paymentTarget = _paymentAdapterFactory.BuildPaymentAdapter(mechantAccount); return(paymentTarget); }
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 User Register(string username, string passwordHash, UserContactDto userContactDto, UserDataDto userDataDto, UserPaymentDto userPaymentDto, UserPermissionDto userPermissionDto, EntityCreatedDto entityCreatedDto, string baseLink) { Require.NotNullOrWhiteSpace(username, "username"); Require.NotNull(userContactDto); Require.NotNull(userDataDto); Require.NotNull(entityCreatedDto, "entityCreatedDto"); User user = new User(passwordHash, userContactDto, userDataDto, userPaymentDto, /*Standardmäßig alle Benachrichtigungen an*/ UserNotificationOptionsDto.AllOn, userPermissionDto, new List <Document>(), entityCreatedDto); Guid.NewGuid(); user = UserDao.Save(user); return(user); }
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); }
/// <summary> /// Aktualisiert alle Eigenschaften des Nutzer und markiert ihn als geändert. /// </summary> /// <param name="passwordHash"></param> /// <param name="userContactDto"></param> /// <param name="userDataDto"></param> /// <param name="userPaymentDto"></param> /// <param name="userNotificationOptionsDto"></param> /// <param name="userPermissionDto"></param> /// <param name="documents"> /// Liste mit Dokumenten, die am Nutzer hinterlegt sein soll. Die Liste enthält sowohl neue, als /// auch weiterhin hinterlegte Dokumente /// </param> /// <param name="entityChangedDto"></param> public virtual void Update(string passwordHash, UserContactDto userContactDto, UserDataDto userDataDto, UserPaymentDto userPaymentDto, UserNotificationOptionsDto userNotificationOptionsDto, UserPermissionDto userPermissionDto, IList <Document> documents, EntityChangedDto entityChangedDto) { Require.NotNullOrWhiteSpace(passwordHash, "passwordHash"); Require.NotNull(userContactDto, "userContactDto"); Require.NotNull(userDataDto, "userDataDto"); Require.NotNull(userPermissionDto, "userPermissionDto"); Require.NotNull(entityChangedDto, "entityChangedDto"); Require.NotNull(documents, "documents"); Require.NotNull(userPaymentDto, "userPaymentDto"); Require.NotNull(userNotificationOptionsDto, "userNotificationOptionsDto"); _passwordHash = passwordHash; Update(userContactDto); Update(userDataDto); Update(userPermissionDto); Update(documents); Update(userPaymentDto); Update(userNotificationOptionsDto); Update(entityChangedDto); }
public void TestCreateAndLoadUser() { // when: UserContactDto updateUserContactDto = UserCreator.CreateUserContactDto("*****@*****.**", "Teststraße", "?", "01234", "Teststadt", Country.DE, "Testunternehmen", "http://www.url.test", "phone", "privat", "mobile"); UserDataDto updateUserDataDto = UserCreator.CreateUserDataDto("Vorname", "Nachname", new DateTime(1984, 04, 26), "UserName"); UserPermissionDto updateUserPermissionDto = UserCreator.CreateUserPermissionDto(new List <string>() { Roles.Administrator }, true); UserPaymentDto userPaymentDto = UserCreator.CreateUserPaymentDto("PayPal", true); EntityCreatedDto creationDto = new EntityCreatedDto(UserCreator.Create(), new DateTime(2016, 12, 12, 15, 30, 0)); User user = UserService.Create("passwordHash", updateUserContactDto, updateUserDataDto, userPaymentDto, updateUserPermissionDto, creationDto); User actualUser = UserService.GetByBusinessId(user.BusinessId); // then: Assert.AreEqual(user, actualUser); DtoAssert.AreEqual(updateUserContactDto, actualUser.GetUserContactDto()); DtoAssert.AreEqual(updateUserDataDto, actualUser.GetUserDataDto()); DtoAssert.AreEqual(updateUserPermissionDto, actualUser.GetUserPermissionDto()); actualUser.CreatedBy.Should().Be(creationDto.CreatedBy); actualUser.CreatedAt.Should().Be(creationDto.CreatedAt); }
public User(string passwordHash, UserContactDto userContactDto, UserDataDto userDataDto, UserPaymentDto userPaymentDto, UserNotificationOptionsDto userNotificationOptions, UserPermissionDto userPermissionDto, IList <Document> documents, EntityCreatedDto entityCreatedDto) { // TODO: Muss hier ein Passwort angegeben werden oder nicht? // Require.NotNullOrWhiteSpace(passwordHash, "passwordHash"); Require.NotNull(userContactDto, "userContactDto"); Require.NotNull(userDataDto, "userDataDto"); Require.NotNull(userPermissionDto, "userPermissionDto"); Require.NotNull(entityCreatedDto, "entityCreatedDto"); Require.NotNull(userPaymentDto, "userPaymentDto"); Require.NotNull(documents, "documents"); Require.NotNull(userNotificationOptions, "userNotificationOptions"); _passwordHash = passwordHash; Update(userContactDto); Update(userDataDto); Update(userPermissionDto); Update(entityCreatedDto); Update(userPaymentDto); Update(userNotificationOptions); Update(documents); }
private void Update(UserPaymentDto paymentDto) { _payPalBusinessName = paymentDto.PayPalBusinessName; _autoAcceptPayPalPayments = paymentDto.AutoAcceptPayPalPayments; }
/// <summary> /// Aktualisiert die Profildaten des Nutzers und markiert ihn als geändert. /// </summary> /// <param name="userContactDto"></param> /// <param name="userDataDto"></param> /// <param name="userPaymentDto"></param> /// <param name="userNotificationOptionsDto"></param> /// <param name="entityChangedDto"></param> public virtual void Update(UserContactDto userContactDto, UserDataDto userDataDto, UserPaymentDto userPaymentDto, UserNotificationOptionsDto userNotificationOptionsDto, EntityChangedDto entityChangedDto) { Require.NotNull(userContactDto, "userContactDto"); Require.NotNull(userDataDto, "userDataDto"); Require.NotNull(entityChangedDto, "entityChangedDto"); Require.NotNull(userPaymentDto, "userPaymentDto"); Require.NotNull(userNotificationOptionsDto, "userNotificationOptionsDto"); Update(userContactDto); Update(userDataDto); Update(userPaymentDto); Update(userNotificationOptionsDto); Update(entityChangedDto); }
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); }
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 User Create(string passwordHash, UserContactDto userContactDto, UserDataDto userDataDto, UserPaymentDto userPaymentDto, UserPermissionDto userPermissionDto, EntityCreatedDto entityCreatedDto) { Require.NotNull(userContactDto); Require.NotNull(userDataDto); Require.NotNull(entityCreatedDto, "entityCreatedDto"); User user = new User(passwordHash, userContactDto, userDataDto, userPaymentDto, /*Standardmäßig alle Benachrichtigungen an*/ UserNotificationOptionsDto.AllOn, userPermissionDto, new List <Document>(), entityCreatedDto); return(UserDao.Save(user)); }