Esempio n. 1
0
        public async Task ShouldIdentifyWithNewPassword(
            TestableContext context,
            Handler handler
            )
        {
            context.UoW.Plan <User>(context.Id())
            .HasEvent <Events.Registered>(x =>
            {
                x.UserName  = context.Id();
                x.GivenName = "test";
                x.Password  = PasswordStorage.CreateHash("test");
            })
            .HasEvent <Events.PasswordChanged>(x =>
            {
                x.UserName = context.Id();
                x.Password = PasswordStorage.CreateHash("test2");
            });

            var command = new Commands.Identify
            {
                UserName = context.Id(),
                Password = "******"
            };
            await handler.Handle(command, context).ConfigureAwait(false);

            context.UoW.Check <User>(context.Id()).Raised <Events.Identified>();
        }
Esempio n. 2
0
        public async Task ShouldNotIdentifyUserWithOldPassword(
            TestableContext context,
            Handler handler
            )
        {
            context.UoW.Plan <User>(context.Id())
            .HasEvent <Events.Registered>(x =>
            {
                x.UserName  = context.Id();
                x.GivenName = "test";
                x.Password  = PasswordStorage.CreateHash("test");
            })
            .HasEvent <Events.PasswordChanged>(x =>
            {
                x.UserName = context.Id();
                x.Password = PasswordStorage.CreateHash("test2");
            });

            var command = new Commands.Identify
            {
                UserName = context.Id(),
                Password = "******"
            };
            await Assert.ThrowsAsync <BusinessException>(() => handler.Handle(command, context)).ConfigureAwait(false);
        }
Esempio n. 3
0
        public async Task Handle(Commands.Identify command, IMessageHandlerContext ctx)
        {
            var user = await ctx.For <User>().Get(command.UserName).ConfigureAwait(false);

            user.Identify(command.Password);
        }