예제 #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());
        }
예제 #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());
        }
예제 #3
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));
        }
예제 #4
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));
        }
예제 #5
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));
        }