Example #1
0
        public async Task UsersAPI_Test01()
        {
            Assert.AreEqual(0, usersAPI.Users.Count());
            Assert.AreEqual(2, usersAPI.Organizations.Count());

            Assert.IsTrue(usersAPI.OrganizationExists(Organization_Id.Parse("NoOwner")));
            Assert.IsTrue(usersAPI.OrganizationExists(Organization_Id.Parse("admins")));


            var result01a = await usersAPI.AddUser(new User(
                                                       User_Id.Parse("apiAdmin01"),
                                                       "API Admin 01",
                                                       SimpleEMailAddress.Parse("*****@*****.**"),
                                                       MobilePhone : PhoneNumber.Parse("+49 170 111111")
                                                       ),
                                                   User2OrganizationEdgeLabel.IsAdmin,
                                                   usersAPI.GetOrganization(Organization_Id.Parse("admins")));

            Assert.IsNotNull(result01a);
            Assert.IsTrue(result01a.IsSuccess);
            Assert.AreEqual(1, usersAPI.Users.Count());

            await usersAPI.AddEMailNotification(result01a.User,
                                                new NotificationMessageType[] {
                UsersAPI.addUser_MessageType,
                UsersAPI.updateUser_MessageType,
                UsersAPI.deleteUser_MessageType,

                UsersAPI.addUserToOrganization_MessageType,
                UsersAPI.removeUserFromOrganization_MessageType,

                UsersAPI.addOrganization_MessageType,
                UsersAPI.updateOrganization_MessageType,
                UsersAPI.deleteOrganization_MessageType,

                UsersAPI.linkOrganizations_MessageType,
                UsersAPI.unlinkOrganizations_MessageType
            });

            await usersAPI.AddSMSNotification(result01a.User,
                                              new NotificationMessageType[] {
                UsersAPI.addUser_MessageType,
                UsersAPI.updateUser_MessageType,
                UsersAPI.deleteUser_MessageType,

                UsersAPI.addUserToOrganization_MessageType,
                UsersAPI.removeUserFromOrganization_MessageType,

                UsersAPI.addOrganization_MessageType,
                UsersAPI.updateOrganization_MessageType,
                UsersAPI.deleteOrganization_MessageType,

                UsersAPI.linkOrganizations_MessageType,
                UsersAPI.unlinkOrganizations_MessageType
            });


            var result01b = await usersAPI.AddUser(new User(
                                                       User_Id.Parse("apiAdmin02"),
                                                       "API Admin 02",
                                                       SimpleEMailAddress.Parse("*****@*****.**")
                                                       ),
                                                   User2OrganizationEdgeLabel.IsAdmin,
                                                   usersAPI.GetOrganization(Organization_Id.Parse("admins")));

            Assert.IsNotNull(result01b);
            Assert.IsTrue(result01b.IsSuccess);
            Assert.AreEqual(2, usersAPI.Users.Count());


            var result01c = await usersAPI.AddUser(new User(
                                                       User_Id.Parse("apiMember01"),
                                                       "API Member 01",
                                                       SimpleEMailAddress.Parse("*****@*****.**"),
                                                       MobilePhone : PhoneNumber.Parse("+49 170 222222")
                                                       ),
                                                   User2OrganizationEdgeLabel.IsMember,
                                                   usersAPI.GetOrganization(Organization_Id.Parse("admins")));

            Assert.IsNotNull(result01c);
            Assert.IsTrue(result01c.IsSuccess);
            Assert.AreEqual(3, usersAPI.Users.Count());

            await usersAPI.AddEMailNotification(result01c.User,
                                                new NotificationMessageType[] {
                UsersAPI.addUser_MessageType,
                UsersAPI.updateUser_MessageType,
                UsersAPI.deleteUser_MessageType,

                UsersAPI.addUserToOrganization_MessageType,
                UsersAPI.removeUserFromOrganization_MessageType,

                UsersAPI.addOrganization_MessageType,
                UsersAPI.updateOrganization_MessageType,
                UsersAPI.deleteOrganization_MessageType,

                UsersAPI.linkOrganizations_MessageType,
                UsersAPI.unlinkOrganizations_MessageType
            });

            await usersAPI.AddSMSNotification(result01c.User,
                                              new NotificationMessageType[] {
                UsersAPI.addUser_MessageType,
                UsersAPI.updateUser_MessageType,
                UsersAPI.deleteUser_MessageType,

                UsersAPI.addUserToOrganization_MessageType,
                UsersAPI.removeUserFromOrganization_MessageType,

                UsersAPI.addOrganization_MessageType,
                UsersAPI.updateOrganization_MessageType,
                UsersAPI.deleteOrganization_MessageType,

                UsersAPI.linkOrganizations_MessageType,
                UsersAPI.unlinkOrganizations_MessageType
            });


            var result01d = await usersAPI.AddUser(new User(
                                                       User_Id.Parse("apiMember02"),
                                                       "API Member 02",
                                                       SimpleEMailAddress.Parse("*****@*****.**")
                                                       ),
                                                   User2OrganizationEdgeLabel.IsMember,
                                                   usersAPI.GetOrganization(Organization_Id.Parse("admins")));

            Assert.IsNotNull(result01d);
            Assert.IsTrue(result01d.IsSuccess);
            Assert.AreEqual(4, usersAPI.Users.Count());


            #region Setup FirstOrg

            var result03 = await usersAPI.AddOrganization(new Organization(
                                                              Organization_Id.Parse("firstOrg"),
                                                              I18NString.Create(Languages.en, "First Organization")
                                                              ),
                                                          ParentOrganization : result01a.Organization);

            Assert.AreEqual(3, usersAPI.Organizations.Count());
            Assert.IsTrue(usersAPI.OrganizationExists(Organization_Id.Parse("firstOrg")));

            var IsChildOrganizationEdge1 = result03.Organization.Organization2OrganizationOutEdges.FirstOrDefault();

            Assert.IsNotNull(IsChildOrganizationEdge1);
            Assert.AreEqual(Organization_Id.Parse("firstOrg"), IsChildOrganizationEdge1.Source.Id);
            Assert.AreEqual(usersAPI.AdminOrganizationId, IsChildOrganizationEdge1.Target.Id);


            var result04a = await usersAPI.AddUser(new User(
                                                       User_Id.Parse("firstOrgAdmin01"),
                                                       "First Org Admin 01",
                                                       SimpleEMailAddress.Parse("*****@*****.**"),
                                                       MobilePhone : PhoneNumber.Parse("+49 170 333333")
                                                       ),
                                                   User2OrganizationEdgeLabel.IsAdmin,
                                                   result03.Organization);

            Assert.IsNotNull(result04a);
            Assert.IsTrue(result04a.IsSuccess);
            Assert.AreEqual(5, usersAPI.Users.Count());

            await usersAPI.AddEMailNotification(result04a.User,
                                                new NotificationMessageType[] {
                UsersAPI.addUser_MessageType,
                UsersAPI.updateUser_MessageType,
                UsersAPI.deleteUser_MessageType,

                UsersAPI.addUserToOrganization_MessageType,
                UsersAPI.removeUserFromOrganization_MessageType,

                UsersAPI.addOrganization_MessageType,
                UsersAPI.updateOrganization_MessageType,
                UsersAPI.deleteOrganization_MessageType,

                UsersAPI.linkOrganizations_MessageType,
                UsersAPI.unlinkOrganizations_MessageType
            });

            await usersAPI.AddSMSNotification(result04a.User,
                                              new NotificationMessageType[] {
                UsersAPI.addUser_MessageType,
                UsersAPI.updateUser_MessageType,
                UsersAPI.deleteUser_MessageType,

                UsersAPI.addUserToOrganization_MessageType,
                UsersAPI.removeUserFromOrganization_MessageType,

                UsersAPI.addOrganization_MessageType,
                UsersAPI.updateOrganization_MessageType,
                UsersAPI.deleteOrganization_MessageType,

                UsersAPI.linkOrganizations_MessageType,
                UsersAPI.unlinkOrganizations_MessageType
            });


            var result04b = await usersAPI.AddUser(new User(
                                                       User_Id.Parse("firstOrgAdmin02"),
                                                       "First Org Admin 02",
                                                       SimpleEMailAddress.Parse("*****@*****.**")
                                                       ),
                                                   User2OrganizationEdgeLabel.IsAdmin,
                                                   result03.Organization);

            Assert.IsNotNull(result04b);
            Assert.IsTrue(result04b.IsSuccess);
            Assert.AreEqual(6, usersAPI.Users.Count());


            var result04c = await usersAPI.AddUser(new User(
                                                       User_Id.Parse("firstOrgMember01"),
                                                       "First Org Member 01",
                                                       SimpleEMailAddress.Parse("*****@*****.**"),
                                                       MobilePhone : PhoneNumber.Parse("+49 170 444444")
                                                       ),
                                                   User2OrganizationEdgeLabel.IsMember,
                                                   result03.Organization);


            Assert.IsNotNull(result04c);
            Assert.IsTrue(result04c.IsSuccess);
            Assert.AreEqual(7, usersAPI.Users.Count());

            await usersAPI.AddEMailNotification(result04c.User,
                                                new NotificationMessageType[] {
                UsersAPI.addUser_MessageType,
                UsersAPI.updateUser_MessageType,
                UsersAPI.deleteUser_MessageType,

                UsersAPI.addUserToOrganization_MessageType,
                UsersAPI.removeUserFromOrganization_MessageType,

                UsersAPI.addOrganization_MessageType,
                UsersAPI.updateOrganization_MessageType,
                UsersAPI.deleteOrganization_MessageType,

                UsersAPI.linkOrganizations_MessageType,
                UsersAPI.unlinkOrganizations_MessageType
            });

            await usersAPI.AddSMSNotification(result04c.User,
                                              new NotificationMessageType[] {
                UsersAPI.addUser_MessageType,
                UsersAPI.updateUser_MessageType,
                UsersAPI.deleteUser_MessageType,

                UsersAPI.addUserToOrganization_MessageType,
                UsersAPI.removeUserFromOrganization_MessageType,

                UsersAPI.addOrganization_MessageType,
                UsersAPI.updateOrganization_MessageType,
                UsersAPI.deleteOrganization_MessageType,

                UsersAPI.linkOrganizations_MessageType,
                UsersAPI.unlinkOrganizations_MessageType
            });


            var result04d = await usersAPI.AddUser(new User(
                                                       User_Id.Parse("firstOrgMember02"),
                                                       "First Org Member 02",
                                                       SimpleEMailAddress.Parse("*****@*****.**")
                                                       ),
                                                   User2OrganizationEdgeLabel.IsMember,
                                                   result03.Organization);

            Assert.IsNotNull(result04d);
            Assert.IsTrue(result04d.IsSuccess);
            Assert.AreEqual(8, usersAPI.Users.Count());

            #endregion

            #region Setup SecondOrg

            var result13 = await usersAPI.AddOrganization(new Organization(
                                                              Organization_Id.Parse("secondOrg"),
                                                              I18NString.Create(Languages.en, "Second Organization")
                                                              ),
                                                          ParentOrganization : result03.Organization);

            Assert.AreEqual(4, usersAPI.Organizations.Count());
            Assert.IsTrue(usersAPI.OrganizationExists(Organization_Id.Parse("secondOrg")));

            var IsChildOrganizationEdge2 = result13.Organization.Organization2OrganizationOutEdges.FirstOrDefault();

            Assert.IsNotNull(IsChildOrganizationEdge2);
            Assert.AreEqual(Organization_Id.Parse("secondOrg"), IsChildOrganizationEdge2.Source.Id);
            Assert.AreEqual(Organization_Id.Parse("firstOrg"), IsChildOrganizationEdge2.Target.Id);


            var result14a = await usersAPI.AddUser(new User(
                                                       User_Id.Parse("secondOrgAdmin01"),
                                                       "Second Org Admin 01",
                                                       SimpleEMailAddress.Parse("*****@*****.**"),
                                                       MobilePhone : PhoneNumber.Parse("+49 170 555555")
                                                       ),
                                                   User2OrganizationEdgeLabel.IsAdmin,
                                                   result13.Organization);

            Assert.IsNotNull(result14a);
            Assert.IsTrue(result14a.IsSuccess);
            Assert.AreEqual(9, usersAPI.Users.Count());

            await usersAPI.AddEMailNotification(result14a.User,
                                                new NotificationMessageType[] {
                UsersAPI.addUser_MessageType,
                UsersAPI.updateUser_MessageType,
                UsersAPI.deleteUser_MessageType,

                UsersAPI.addUserToOrganization_MessageType,
                UsersAPI.removeUserFromOrganization_MessageType,

                UsersAPI.addOrganization_MessageType,
                UsersAPI.updateOrganization_MessageType,
                UsersAPI.deleteOrganization_MessageType,

                UsersAPI.linkOrganizations_MessageType,
                UsersAPI.unlinkOrganizations_MessageType
            });

            await usersAPI.AddSMSNotification(result14a.User,
                                              new NotificationMessageType[] {
                UsersAPI.addUser_MessageType,
                UsersAPI.updateUser_MessageType,
                UsersAPI.deleteUser_MessageType,

                UsersAPI.addUserToOrganization_MessageType,
                UsersAPI.removeUserFromOrganization_MessageType,

                UsersAPI.addOrganization_MessageType,
                UsersAPI.updateOrganization_MessageType,
                UsersAPI.deleteOrganization_MessageType,

                UsersAPI.linkOrganizations_MessageType,
                UsersAPI.unlinkOrganizations_MessageType
            });


            var result14b = await usersAPI.AddUser(new User(
                                                       User_Id.Parse("secondOrgAdmin02"),
                                                       "Second Org Admin 02",
                                                       SimpleEMailAddress.Parse("*****@*****.**")
                                                       ),
                                                   User2OrganizationEdgeLabel.IsAdmin,
                                                   result13.Organization);

            Assert.IsNotNull(result14b);
            Assert.IsTrue(result14b.IsSuccess);
            Assert.AreEqual(10, usersAPI.Users.Count());


            var result14c = await usersAPI.AddUser(new User(
                                                       User_Id.Parse("secondOrgMember01"),
                                                       "Second Org Member 01",
                                                       SimpleEMailAddress.Parse("*****@*****.**"),
                                                       MobilePhone : PhoneNumber.Parse("+49 170 666666")
                                                       ),
                                                   User2OrganizationEdgeLabel.IsMember,
                                                   result13.Organization);


            Assert.IsNotNull(result14c);
            Assert.IsTrue(result14c.IsSuccess);
            Assert.AreEqual(11, usersAPI.Users.Count());

            await usersAPI.AddEMailNotification(result14c.User,
                                                new NotificationMessageType[] {
                UsersAPI.addUser_MessageType,
                UsersAPI.updateUser_MessageType,
                UsersAPI.deleteUser_MessageType,

                UsersAPI.addUserToOrganization_MessageType,
                UsersAPI.removeUserFromOrganization_MessageType,

                UsersAPI.addOrganization_MessageType,
                UsersAPI.updateOrganization_MessageType,
                UsersAPI.deleteOrganization_MessageType,

                UsersAPI.linkOrganizations_MessageType,
                UsersAPI.unlinkOrganizations_MessageType
            });

            await usersAPI.AddSMSNotification(result14c.User,
                                              new NotificationMessageType[] {
                UsersAPI.addUser_MessageType,
                UsersAPI.updateUser_MessageType,
                UsersAPI.deleteUser_MessageType,

                UsersAPI.addUserToOrganization_MessageType,
                UsersAPI.removeUserFromOrganization_MessageType,

                UsersAPI.addOrganization_MessageType,
                UsersAPI.updateOrganization_MessageType,
                UsersAPI.deleteOrganization_MessageType,

                UsersAPI.linkOrganizations_MessageType,
                UsersAPI.unlinkOrganizations_MessageType
            });


            var result14d = await usersAPI.AddUser(new User(
                                                       User_Id.Parse("secondOrgMember02"),
                                                       "Second Org Member 02",
                                                       SimpleEMailAddress.Parse("*****@*****.**")
                                                       ),
                                                   User2OrganizationEdgeLabel.IsMember,
                                                   result13.Organization);

            Assert.IsNotNull(result14d);
            Assert.IsTrue(result14d.IsSuccess);
            Assert.AreEqual(12, usersAPI.Users.Count());

            #endregion


            Assert.IsTrue(nullMailer.EMails.Any(), "Not a single notification e-mail was sent!");

            var maxEMailSubjectLength = nullMailer.EMails.Max(emailEnvelope => emailEnvelope.Mail.Subject.Length);
            var allEMailNotifications = nullMailer.EMails.Select(emailEnvelope => emailEnvelope.Mail.Subject.PadRight(maxEMailSubjectLength + 2) + " => " + emailEnvelope.RcptTo.Select(email => email.Address).OrderBy(_ => _).AggregateWith(", ")).ToArray();
            var eMailOverview         = allEMailNotifications.AggregateWith(Environment.NewLine);

            // User 'API Admin 02' was successfully created.                                            => [email protected]
            // User 'API Admin 02' was added to organization 'Admins' as admin.                         => [email protected]
            // User 'API Member 01' was successfully created.                                           => [email protected]
            // User 'API Member 01' was added to organization 'Admins' as member.                       => [email protected]
            // User 'API Member 02' was successfully created.                                           => [email protected], [email protected]
            // User 'API Member 02' was added to organization 'Admins' as member.                       => [email protected], [email protected]
            //
            // Organization 'First Organization' was successfully created.                              => [email protected], [email protected]
            // Organization 'First Organization' was linked to organization 'Admins'.                   => [email protected], [email protected]
            // User 'First Org Admin 01' was successfully created.                                      => [email protected], [email protected]
            // User 'First Org Admin 01' was added to organization 'First Organization' as admin.       => [email protected], [email protected]
            // User 'First Org Admin 02' was successfully created.                                      => [email protected], [email protected], [email protected]
            // User 'First Org Admin 02' was added to organization 'First Organization' as admin.       => [email protected], [email protected], [email protected]
            // User 'First Org Member 01' was successfully created.                                     => [email protected], [email protected], [email protected]
            // User 'First Org Member 01' was added to organization 'First Organization' as member.     => [email protected], [email protected], [email protected]
            // User 'First Org Member 02' was successfully created.                                     => [email protected], [email protected], [email protected], [email protected]
            // User 'First Org Member 02' was added to organization 'First Organization' as member.     => [email protected], [email protected], [email protected], [email protected]
            //
            // Organization 'Second Organization' was successfully created.                             => [email protected], [email protected], [email protected], [email protected]
            // Organization 'Second Organization' was linked to organization 'First Organization'.      => [email protected], [email protected], [email protected], [email protected]
            // User 'Second Org Admin 01' was successfully created.                                     => [email protected], [email protected], [email protected], [email protected]
            // User 'Second Org Admin 01' was added to organization 'Second Organization' as admin.     => [email protected], [email protected], [email protected], [email protected]
            // User 'Second Org Admin 02' was successfully created.                                     => [email protected], [email protected], [email protected], [email protected], [email protected]
            // User 'Second Org Admin 02' was added to organization 'Second Organization' as admin.     => [email protected], [email protected], [email protected], [email protected], [email protected]
            // User 'Second Org Member 01' was successfully created.                                    => [email protected], [email protected], [email protected], [email protected], [email protected]
            // User 'Second Org Member 01' was added to organization 'Second Organization' as member.   => [email protected], [email protected], [email protected], [email protected], [email protected]
            // User 'Second Org Member 02' was successfully created.                                    => [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]
            // User 'Second Org Member 02' was added to organization 'Second Organization' as member.   => [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]


            Assert.IsTrue(nullSMSClient.SMSs.Any(), "Not a single notification SMS was sent!");

            var maxSMSMessageLength = nullSMSClient.SMSs.Max(sms => sms.Text.Length);
            var allSMSNotifications = nullSMSClient.SMSs.Select(sms => sms.Text.PadRight(maxSMSMessageLength + 2) + " => " + sms.Receivers.OrderBy(_ => _).AggregateWith(", ")).ToArray();
            var smsOverview         = allSMSNotifications.AggregateWith(Environment.NewLine);

            // |-- 160 characters --------------------------------------------------------------------------------------------------------------------------------------------|
            // User 'API Admin 02' was successfully added. https://example.cloud/users/apiAdmin02                           => +49 170 111111
            // User 'API Admin 02' was added to organization 'Admins' as admin.                                             => +49 170 111111
            // User 'API Member 01' was successfully added. https://example.cloud/users/apiMember01                         => +49 170 111111
            // User 'API Member 01' was added to organization 'Admins' as member.                                           => +49 170 111111
            // User 'API Member 02' was successfully added. https://example.cloud/users/apiMember02                         => +49 170 111111, +49 170 222222
            // User 'API Member 02' was added to organization 'Admins' as member.                                           => +49 170 111111, +49 170 222222
            //
            // Organization 'First Organization' was successfully created. https://example.cloud/organizations/firstOrg     => +49 170 111111, +49 170 222222
            // Organization 'First Organization' was linked to organization 'Admins'.                                       => +49 170 111111, +49 170 222222
            // User 'First Org Admin 01' was successfully added. https://example.cloud/users/firstOrgAdmin01                => +49 170 111111, +49 170 222222
            // User 'First Org Admin 01' was added to organization 'First Organization' as admin.                           => +49 170 111111, +49 170 222222
            // User 'First Org Admin 02' was successfully added. https://example.cloud/users/firstOrgAdmin02                => +49 170 111111, +49 170 222222, +49 170 333333
            // User 'First Org Admin 02' was added to organization 'First Organization' as admin.                           => +49 170 111111, +49 170 222222, +49 170 333333
            // User 'First Org Member 01' was successfully added. https://example.cloud/users/firstOrgMember01              => +49 170 111111, +49 170 222222, +49 170 333333
            // User 'First Org Member 01' was added to organization 'First Organization' as member.                         => +49 170 111111, +49 170 222222, +49 170 333333
            // User 'First Org Member 02' was successfully added. https://example.cloud/users/firstOrgMember02              => +49 170 111111, +49 170 222222, +49 170 333333, +49 170 444444
            // User 'First Org Member 02' was added to organization 'First Organization' as member.                         => +49 170 111111, +49 170 222222, +49 170 333333, +49 170 444444
            //
            // Organization 'Second Organization' was successfully created. https://example.cloud/organizations/secondOrg   => +49 170 111111, +49 170 222222, +49 170 333333, +49 170 444444
            // Organization 'Second Organization' was linked to organization 'First Organization'.                          => +49 170 111111, +49 170 222222, +49 170 333333, +49 170 444444
            // User 'Second Org Admin 01' was successfully added. https://example.cloud/users/secondOrgAdmin01              => +49 170 111111, +49 170 222222, +49 170 333333, +49 170 444444
            // User 'Second Org Admin 01' was added to organization 'Second Organization' as admin.                         => +49 170 111111, +49 170 222222, +49 170 333333, +49 170 444444
            // User 'Second Org Admin 02' was successfully added. https://example.cloud/users/secondOrgAdmin02              => +49 170 111111, +49 170 222222, +49 170 333333, +49 170 444444, +49 170 555555
            // User 'Second Org Admin 02' was added to organization 'Second Organization' as admin.                         => +49 170 111111, +49 170 222222, +49 170 333333, +49 170 444444, +49 170 555555
            // User 'Second Org Member 01' was successfully added. https://example.cloud/users/secondOrgMember01            => +49 170 111111, +49 170 222222, +49 170 333333, +49 170 444444, +49 170 555555
            // User 'Second Org Member 01' was added to organization 'Second Organization' as member.                       => +49 170 111111, +49 170 222222, +49 170 333333, +49 170 444444, +49 170 555555
            // User 'Second Org Member 02' was successfully added. https://example.cloud/users/secondOrgMember02            => +49 170 111111, +49 170 222222, +49 170 333333, +49 170 444444, +49 170 555555, +49 170 666666
            // User 'Second Org Member 02' was added to organization 'Second Organization' as member.                       => +49 170 111111, +49 170 222222, +49 170 333333, +49 170 444444, +49 170 555555, +49 170 666666
        }