コード例 #1
0
        public override void SetUp()
        {
            base.SetUp();

            var UserStampBuilder = new UserSecurityStampBuilder();
            var UserBuilder      = new UserBuilder();

            UserStampBuilder.AssignToUser(UserBuilder.Build());

            testUser = UserBuilder.BuildAndSave();
            testUserSecurityStamp = UserStampBuilder.BuildAndSave();

            resetSecurityStamp = new ResetSecurityStamp()
            {
                TargetUserNameId = testUser.Id
            };
            handler = new ResetSecurityStampHandler(DataContext);
        }
コード例 #2
0
        public async Task <HttpResponseMessage> Post(ResetSecurityStamp id)
        {
            try
            {
                await mediator.Send(new ResetSecurityStamp()
                {
                    TargetUserNameId = id.TargetUserNameId
                });
            }
            catch (ValidationException ex)
                when(ex.Errors.FirstOrDefault()?.ErrorCode == nameof(UserHasCorrectValidator))
                {
                    return(Request.CreateResponse(HttpStatusCode.Unauthorized, new { Error = ex.Errors.FirstOrDefault()?.ErrorMessage }));
                }
            catch (ValidationException ex)
                when(ex.Errors.FirstOrDefault()?.ErrorCode == nameof(IsValidUserValidator))
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, new { Error = ex.Errors.FirstOrDefault()?.ErrorMessage }));
                }

            return(Request.CreateResponse(HttpStatusCode.OK, new { Result = "Successfully signed out user." }));
        }
コード例 #3
0
        public override void SetUp()
        {
            base.SetUp();

            // unsure if this test fixture should include the internal handlers
            // as the validator has no clue about *how* the property is validated.
            // on the other hand, there isn't much of a better way to test a validator
            // than to do a kind of sort of integration test
            var token = new CancellationToken();

            Task <bool> ReturnCall <TRequest, TRequestHandler>(CallInfo call)
                where TRequest : IRequest <bool>
                where TRequestHandler : IRequestHandler <TRequest, bool>
            {
                if (call.Args().Length > 0 && call.Args()[0] is TRequest sentRequest)
                {
                    var handler = (TRequestHandler)System.Activator.CreateInstance(typeof(TRequestHandler), DataContext);
                    return(handler.Handle(sentRequest, token));
                }
                return(Task.FromResult(false));
            }

            mediatorMock.Send(Arg.Any <UserHasAnyRoleRequest>()).Returns(ReturnCall <UserHasAnyRoleRequest, UserHasRoleRequestHandler>);
            mediatorMock.Send(Arg.Any <IsValidUserRequest>()).Returns(ReturnCall <IsValidUserRequest, IsValidUserRequestHandler>);

            var roleBuilder = new RoleBuilder();
            var userBuidler = new UserBuilder();

            roleBuilder.With(r => r.Name, PvPStatics.Permissions_Admin);
            roleBuilder.AddUser(userBuidler.Build());

            roleBuilder.BuildAndSave();
            adminUser = userBuidler.BuildAndSave();

            normalUser = new UserBuilder().BuildAndSave();

            request = new ResetSecurityStamp();
        }
コード例 #4
0
ファイル: User.cs プロジェクト: transformania/tt-game
 public void ResetSecurityStamp(ResetSecurityStamp cmd)
 {
     SecurityStamp = Guid.NewGuid().ToString();
 }