Example #1
0
        public void user_permission_list_should_not_have_granted_permission_after_UserPermissionGrantedEvent_with_inactive_permission()
        {
            // Assemble
            var agg           = UserAggregateMockAggregate.SetupAdminUser();
            var permissionAgg = UserAggregateMockAggregate.SetupTestPermission();

            permissionAgg.DisablePermission(agg);

            GrantUserPermissionDTO input = new GrantUserPermissionDTO
            {
                ForId = agg.Id,
                ById  = agg.Id,
                PermissionsToGrant = new Dictionary <Guid, PermissionDetails>
                {
                    {
                        permissionAgg.Id, new PermissionDetails
                        {
                            Reason = "test Reason"
                        }
                    }
                }
            };

            // Apply
            agg.GrantPermission(agg, new List <PermissionAggregate> {
                permissionAgg
            }, input);

            // Assert
            var changes = agg.FlushUncommitedChanges();

            Assert.Single(changes);
            Assert.False(agg.PermissionList.Any());
        }
Example #2
0
        public void user_permission_list_should_not_contain_requested_permission_after_UserPermissionRequestedEvent_with_inactive_permission()
        {
            // Assemble
            var agg           = UserAggregateMockAggregate.SetupAdminUser();
            var permissionAgg = UserAggregateMockAggregate.SetupTestPermission();

            permissionAgg.DisablePermission(agg);

            RequestUserPermissionsDTO requestInput = new RequestUserPermissionsDTO
            {
                ForId    = agg.Id,
                ById     = agg.Id,
                Requests = new Dictionary <Guid, PermissionDetails>
                {
                    { permissionAgg.Id, new PermissionDetails
                      {
                          Reason = "TestReason"
                      } }
                },
            };

            // Apply
            agg.UserRequestedPermissions(new List <PermissionAggregate> {
                permissionAgg
            }, requestInput);

            // Assert
            Assert.False(agg.PermissionList.Any());
        }
Example #3
0
        public void given_active_user_should_be_inactive_after_UserDisabledEvent()
        {
            // Assemble
            var agg = UserAggregateMockAggregate.SetupAdminUser();

            // Apply
            agg.DisableSingleUser(agg);

            // Assert
            var changes = agg.FlushUncommitedChanges();

            Assert.Equal(2, changes.Length);
            Assert.Collection(changes,
                              (e) =>
            {
                Assert.IsType <UserCreatedEvent>(e);
            },
                              (e) =>
            {
                Assert.IsType <UserDisabledEvent>(e);
                var @event = (UserDisabledEvent)e;

                Assert.Equal(2, @event.Version);
                Assert.NotEqual(Guid.Empty, @event.Id);

                Assert.False(@event.IsActive);
                Assert.Equal(@event.ByAgg, agg.Id);
            });

            Assert.False(agg.IsActive);
        }
Example #4
0
        public void user_permission_list_should_not_have_revoked_permission_after_UserPermissionRevokedEvent_when_permission_was_not_previously_granted()
        {
            // Assemble
            var agg           = UserAggregateMockAggregate.SetupAdminUser();
            var permissionAgg = UserAggregateMockAggregate.SetupTestPermission();

            RevokeUserPermissionDTO revokeInput = new RevokeUserPermissionDTO()
            {
                ForId = agg.Id,
                ById  = agg.Id,
                PermissionsToRevoke = new Dictionary <Guid, PermissionDetails>
                {
                    {
                        permissionAgg.Id, new PermissionDetails
                        {
                            Reason = "test revoke reason"
                        }
                    }
                }
            };

            RequestUserPermissionsDTO requestInput = new RequestUserPermissionsDTO
            {
                ForId    = agg.Id,
                ById     = agg.Id,
                Requests = new Dictionary <Guid, PermissionDetails>
                {
                    { permissionAgg.Id, new PermissionDetails
                      {
                          Reason = "TestReason"
                      } }
                },
            };

            agg.UserRequestedPermissions(new List <PermissionAggregate> {
                permissionAgg
            }, requestInput);

            // Apply
            agg.RevokePermission(agg, revokeInput);

            // Assert
            var changes = agg.FlushUncommitedChanges();

            Assert.Equal(2, changes.Length);
            Assert.Collection(changes,
                              (e) =>
            {
                Assert.IsType <UserCreatedEvent>(e);
            },
                              (e) =>
            {
                Assert.IsType <UserPermissionsRequestedEvent>(e);
            }
                              );

            Assert.True(agg.PermissionList.ContainsKey(permissionAgg.Id));
            Assert.Equal(agg.PermissionList[permissionAgg.Id].EventType, JsonConvert.SerializeObject(typeof(UserPermissionsRequestedEvent).FullName));
        }
Example #5
0
        public void user_permission_list_should_contain_requested_permission_after_UserPermissionRequestedEvent()
        {
            // Assemble
            var agg           = UserAggregateMockAggregate.SetupAdminUser();
            var permissionAgg = UserAggregateMockAggregate.SetupTestPermission();

            RequestUserPermissionsDTO requestInput = new RequestUserPermissionsDTO
            {
                ForId    = agg.Id,
                ById     = agg.Id,
                Requests = new Dictionary <Guid, PermissionDetails>
                {
                    { permissionAgg.Id, new PermissionDetails
                      {
                          Reason = "TestReason"
                      } }
                },
            };

            // Apply
            agg.UserRequestedPermissions(new List <PermissionAggregate> {
                permissionAgg
            }, requestInput);

            // Assert
            var changes = agg.FlushUncommitedChanges();

            Assert.Equal(2, changes.Length);
            Assert.Collection(changes,
                              (e) =>
            {
                Assert.IsType <UserCreatedEvent>(e);
            },
                              (e) =>
            {
                Assert.IsType <UserPermissionsRequestedEvent>(e);
                var @event = (UserPermissionsRequestedEvent)e;

                Assert.NotEqual(Guid.Empty, @event.Id);
                Assert.Equal(2, @event.Version);
                Assert.NotEqual(new DateTime(), @event.TimeStamp);

                Assert.True(@event.Requests.Any());
                Assert.True(@event.Requests.ContainsKey(permissionAgg.Id));
                Assert.Equal(@event.Requests[permissionAgg.Id].EventType, JsonConvert.SerializeObject(typeof(UserPermissionsRequestedEvent).FullName));
                Assert.Equal(@event.Requests[permissionAgg.Id].Reason, requestInput.Requests[permissionAgg.Id].Reason);
                Assert.True(@event.Requests[permissionAgg.Id].IsPending);
                //Assert.NotEqual(@event.Requests[permissionAgg.Id].RequestDate, new DateTime());
                Assert.Equal(@event.Requests[permissionAgg.Id].RequestedBy, agg.Id);
                Assert.Equal(@event.Requests[permissionAgg.Id].RequestedFor, agg.Id);
            });

            Assert.True(agg.PermissionList.ContainsKey(permissionAgg.Id));
            Assert.Equal(agg.PermissionList[permissionAgg.Id].EventType, JsonConvert.SerializeObject(typeof(UserPermissionsRequestedEvent).FullName));
        }
Example #6
0
        public void user_permission_list_should_have_granted_permission_after_UserPermissionGrantedEvent()
        {
            // Assemble
            var agg           = UserAggregateMockAggregate.SetupAdminUser();
            var permissionAgg = UserAggregateMockAggregate.SetupTestPermission();

            GrantUserPermissionDTO input = new GrantUserPermissionDTO
            {
                ForId = agg.Id,
                ById  = agg.Id,
                PermissionsToGrant = new Dictionary <Guid, PermissionDetails>
                {
                    {
                        permissionAgg.Id, new PermissionDetails
                        {
                            Reason = "test Reason"
                        }
                    }
                }
            };

            // Apply
            agg.GrantPermission(agg, new List <PermissionAggregate> {
                permissionAgg
            }, input);

            // Assert
            var changes = agg.FlushUncommitedChanges();

            Assert.Equal(2, changes.Length);
            Assert.Collection(changes,
                              (e) =>
            {
                Assert.IsType <UserCreatedEvent>(e);
            },
                              (e) =>
            {
                Assert.IsType <UserPermissionGrantedEvent>(e);
                var @event = (UserPermissionGrantedEvent)e;
                Assert.NotEqual(Guid.Empty, @event.Id);
                Assert.Equal(2, @event.Version);

                Assert.Equal(agg.Id, @event.ForId);
                Assert.Equal(agg.Id, @event.ById);
                Assert.True(@event.PermissionsToGrant.ContainsKey(permissionAgg.Id));
                Assert.Equal(@event.PermissionsToGrant[permissionAgg.Id].EventType, JsonConvert.SerializeObject(typeof(UserPermissionGrantedEvent).FullName));
            }
                              );

            Assert.True(agg.PermissionList.ContainsKey(permissionAgg.Id));
            Assert.Equal(agg.PermissionList[permissionAgg.Id].EventType, JsonConvert.SerializeObject(typeof(UserPermissionGrantedEvent).FullName));
        }
Example #7
0
        public void given_new_user_should_have_correct_values_after_UserUpdatedEvent()
        {
            // Assemble
            var agg = UserAggregateMockAggregate.SetupAdminUser();
            UpdateUserInformationDTO input = new UpdateUserInformationDTO
            {
                ForID      = agg.Id,
                FirstName  = "ChangedFName",
                LastName   = "ChangedLName",
                Email      = "ChangedEmail",
                Position   = "ChangedPosition",
                Department = "ChangedDepartment",
                IsAdmin    = false
            };


            // Apply
            agg.UpdateUserInfo(input);

            // Assert
            var changes = agg.FlushUncommitedChanges();

            Assert.Equal(2, changes.Length);
            Assert.Collection(changes,
                              (e) =>
            {
                Assert.IsType <UserCreatedEvent>(e);
            },
                              (e) =>
            {
                Assert.IsType <UserUpdatedEvent>(e);
                var @event = (UserUpdatedEvent)e;
                Assert.Equal(2, @event.Version);
                Assert.NotEqual(Guid.Empty, @event.Id);

                Assert.Equal(@event.FirstName, agg.FirstName);
                Assert.Equal(@event.LastName, agg.LastName);
                Assert.Equal(@event.Email, agg.Email);
                Assert.Equal(@event.Position, agg.Position);
                Assert.Equal(@event.Department, agg.Department);
                Assert.Equal(@event.IsAdmin, agg.IsAdmin);
            });

            Assert.Equal(2, agg.Version);
            Assert.Equal(input.FirstName, agg.FirstName);
            Assert.Equal(input.LastName, agg.LastName);
            Assert.Equal(input.Email, agg.Email);
            Assert.Equal(input.Position, agg.Position);
            Assert.Equal(input.Department, agg.Department);
            Assert.Equal(input.IsAdmin, agg.IsAdmin);
        }