public void can_retrieve_correlated_aggregate() { var command1 = CorrelatedMessage.NewRoot(); var id = Guid.NewGuid(); var agg = new CorrelatedAggregate(id, command1); agg.RaiseCorrelatedEvent(); agg.RaiseCorrelatedEvent(); _repo.Save(agg); var command2 = CorrelatedMessage.NewRoot(); var recovered = _repo.GetById <CorrelatedAggregate>(id, command2); Assert.NotNull(recovered); Assert.Equal(2, recovered.Version);//zero based, includes created recovered.RaiseCorrelatedEvent(); recovered.RaiseCorrelatedEvent(); _repo.Save(recovered); var command3 = CorrelatedMessage.NewRoot(); var recovered2 = _repo.GetById <CorrelatedAggregate>(id, command3); Assert.NotNull(recovered2); Assert.Equal(4, recovered2.Version); }
//Add events to the Subject for tracking the authentication status results public void UserAuthenticated(UserPrincipal retrievedUser, string domain, string authProvider, string hostIpAddress, string clientId) { if (_usersRm.HasUser(retrievedUser.Sid.Value, domain, out Guid userId) && _subjectsRm.TryGetSubjectIdForUser(userId, authProvider, domain, out var subId)) { var subject = _repo.GetById <Subject>(subId, new CorrelatedRoot()); subject.Authenticated(hostIpAddress, clientId); _repo.Save(subject); } }
/// <summary> /// Given the create role command, creates a role created event. /// </summary> public CommandResponse Handle(ApplicationMsgs.CreateRole cmd) { var application = _repo.GetById <SecuredApplication>(cmd.AppId, cmd); var pol = application.Policies.First(p => p.Id == cmd.PolicyId); pol.AddRole(cmd.RoleId ?? Guid.NewGuid(), cmd.Name); _repo.Save(application); return(cmd.Succeed()); }