private Guid AddNewSubject(Guid?specifiedUserId = null, string provider = null, string domain = null) { var subjectId = Guid.NewGuid(); var userId = specifiedUserId ?? Guid.NewGuid(); if (!_subjects.TryGetValue($"{provider ?? authProvider}-{domain ?? authDomain}", out var subjects)) { subjects = new Dictionary <Guid, Guid>(); _subjects.Add($"{provider ?? authProvider}-{domain ?? authDomain}", subjects); } subjects.Add(userId, subjectId); var evt = MessageBuilder.New( () => new SubjectMsgs.SubjectCreated(subjectId, userId, userId.ToString(), provider ?? authProvider, domain ?? authDomain)); var stream = _fixture.StreamNameBuilder.GenerateForAggregate(typeof(Subject), subjectId); _fixture.StreamStoreConnection.AppendToStream( stream, ExpectedVersion.Any, null, new[] { _fixture.EventSerializer.Serialize(evt) }); _fixture.RepositoryEvents.WaitFor <SubjectMsgs.SubjectCreated>(TimeSpan.FromMilliseconds(200)); _fixture.ClearQueues(); return(subjectId); }
private void AddUsers() { var evt1 = MessageBuilder.New( () => new UserMsgs.UserCreated( _id1)); var evt2 = MessageBuilder.New( () => new UserMsgs.UserDetailsUpdated( _id1, FullName, GivenName, Surname, Email)); var evt3 = MessageBuilder.New( () => new UserMsgs.AuthDomainMapped( _id1, SubjectId, AuthProvider, AuthDomain, UserName)); var evt4 = MessageBuilder.New( () => new UserMsgs.UserCreated( _id2)); var evt5 = MessageBuilder.New( () => new UserMsgs.UserDetailsUpdated( _id2, FullName, GivenName, Surname, Email)); var evt6 = MessageBuilder.New( () => new UserMsgs.AuthDomainMapped( _id2, SubjectId2, AuthProvider, AuthDomain, UserName2)); var stream1 = _fixture.StreamNameBuilder.GenerateForAggregate(typeof(User), _id1); var stream2 = _fixture.StreamNameBuilder.GenerateForAggregate(typeof(User), _id2); _fixture.StreamStoreConnection.AppendToStream( stream1, ExpectedVersion.Any, null, new[] { _fixture.EventSerializer.Serialize(evt1), _fixture.EventSerializer.Serialize(evt2), _fixture.EventSerializer.Serialize(evt3) }); _fixture.RepositoryEvents.WaitForMsgId(evt3.MsgId, TimeSpan.FromMilliseconds(100)); _fixture.StreamStoreConnection.AppendToStream( stream2, ExpectedVersion.Any, null, new[] { _fixture.EventSerializer.Serialize(evt4), _fixture.EventSerializer.Serialize(evt5), _fixture.EventSerializer.Serialize(evt6) }); _fixture.RepositoryEvents.WaitForMsgId(evt6.MsgId, TimeSpan.FromMilliseconds(100)); _fixture.ClearQueues(); }
private void CreateUser() { var evt = MessageBuilder.New( () => new UserMsgs.UserCreated( _userId, _userSidFromAuthProvider, AuthProvider, AuthDomain, UserName, FullName, GivenName, Surname, Email)); var stream = _streamNamer.GenerateForAggregate(typeof(User), _userId); _fixture.StreamStoreConnection.AppendToStream( stream, ExpectedVersion.Any, null, _fixture.EventSerializer.Serialize(evt)); _fixture.RepositoryEvents.WaitForMsgId(evt.MsgId, TimeSpan.FromMilliseconds(100)); _fixture.ClearQueues(); }
public void can_remove_client_scope_from_user() { //given AddUser(); var givenEvt = _fixture.EventSerializer.Serialize(MessageBuilder.New( () => new UserMsgs.ClientScopeAdded( _userId, ClientScope))); var stream = _fixture.StreamNameBuilder.GenerateForAggregate(typeof(User), _userId); _fixture.StreamStoreConnection.AppendToStream( stream, ExpectedVersion.Any, null, new[] { givenEvt }); _fixture.RepositoryEvents.WaitFor <UserMsgs.ClientScopeAdded>(TimeSpan.FromMilliseconds(100)); _fixture.ClearQueues(); //when var cmd = MessageBuilder.New( () => new UserMsgs.RemoveClientScope(_userId, ClientScope)); _fixture.Dispatcher.Send(cmd); //then _fixture.RepositoryEvents.WaitFor <UserMsgs.ClientScopeRemoved>(TimeSpan.FromMilliseconds(100)); _fixture .TestQueue .AssertNext <UserMsgs.RemoveClientScope>(cmd.CorrelationId) .AssertEmpty(); _fixture .RepositoryEvents .AssertNext <UserMsgs.ClientScopeRemoved>(cmd.CorrelationId, out UserMsgs.ClientScopeRemoved evt) .AssertEmpty(); Assert.Equal(ClientScope, evt.ClientScope); }
private void AddRole() { var evt = MessageBuilder.New( () => new RoleMsgs.RoleCreated( _roleId, RoleName, Application)); var stream = _fixture.StreamNameBuilder.GenerateForAggregate(typeof(Role), _roleId); _fixture.StreamStoreConnection.AppendToStream( stream, ExpectedVersion.Any, null, _fixture.EventSerializer.Serialize(evt)); _fixture.RepositoryEvents.WaitFor <RoleMsgs.RoleCreated>(TimeSpan.FromMilliseconds(100)); _fixture.ClearQueues(); }
private void AddApplication() { var evt = MessageBuilder.New( () => new ApplicationMsgs.ApplicationRegistered(_id, Application, OneRolePerUser, _roles, SecAdminRole, DefaultUser, DefaultDomain, _defaultUserRoles)); var stream = _fixture.StreamNameBuilder.GenerateForAggregate(typeof(ApplicationRoot), _id); _fixture.StreamStoreConnection.AppendToStream( stream, ExpectedVersion.Any, null, _fixture.EventSerializer.Serialize(evt)); _fixture.RepositoryEvents.WaitFor <ApplicationMsgs.ApplicationRegistered>(TimeSpan.FromMilliseconds(100)); _fixture.ClearQueues(); }