Example #1
0
        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);
        }
Example #2
0
        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);
        }