public async Task <DomainValidationResult <Clan> > LeaveClanAsync(Clan clan, UserId userId) { var result = new DomainValidationResult <Clan>(); if (!clan.HasMember(userId)) { result.AddFailedPreconditionError($"The user ({userId}) isn't a member of the clan '{clan.Name}'."); } if (result.IsValid) { var member = clan.FindMember(userId); clan.Leave(member); await _clanRepository.UnitOfWork.CommitAsync(); if (clan.Deleted) { await this.DeleteClanAsync(clan); } return(clan); } return(result); }
public async Task <DomainValidationResult <Member> > KickMemberFromClanAsync(Clan clan, UserId userId, MemberId memberId) { var result = new DomainValidationResult <Member>(); if (!clan.MemberIsOwner(userId)) { result.AddFailedPreconditionError($"The user ({userId}) isn't the clan owner."); } if (!clan.HasMember(memberId)) { result.AddFailedPreconditionError($"The memberId ({memberId}) isn't a member of the clan '{clan.Name}'."); } if (result.IsValid) { var member = clan.FindMember(memberId); clan.Kick(member); await _clanRepository.UnitOfWork.CommitAsync(); return(member); } return(result); }
public void HasMember_WithUserId_ShouldBeFalse() { // Arrange var clan = new Clan("TestClan", new UserId()); // Act Assert clan.HasMember(new UserId()).Should().BeFalse(); }
public void HasMember_WithUserId_ShouldBeTrue() { // Arrange var userId = new UserId(); var clan = new Clan("TestClan", userId); // Act Assert clan.HasMember(userId).Should().BeTrue(); }
public void HasMember_WithMemberId_ShouldBeTrue() { // Arrange var clan = new Clan("TestClan", new UserId()); var memberId = clan.Members.SingleOrDefault()?.Id; // Act Assert clan.HasMember(memberId).Should().BeTrue(); }