public async Task Given_Registered_OrganisationId_Or_TeamName_When_Call_GetByTeamNameAsync_ShouldReturns_Team_Instance(string organisationId, string teamName) { var moqRepository = new Mock <ITeamRepository>(); moqRepository .Setup(t => t.GetByAsync(It.IsAny <Expression <Func <Domain.Entities.Team, bool> > >())) .ReturnsAsync(() => new Domain.Entities.Team { Name = teamName, OrganisationId = organisationId }) .Verifiable(); var moqOrgRepository = new Mock <IOrganisationRepository>(); moqOrgRepository .Setup(t => t.ExistsByAsync(It.IsAny <Expression <Func <Domain.Entities.Organisation, bool> > >())) .ReturnsAsync(true) .Verifiable(); var service = new Application.TeamService(moqRepository.Object, moqOrgRepository.Object, null); var teamResult = await service.GetByTeamNameAsync(organisationId, teamName); moqRepository.Verify(); Assert.NotNull(teamResult); Assert.Equal(teamName, teamResult.Name); }
public async Task Given_Not_Exists_Team_When_Call_AddAsync_ShouldReturns_A_New_Instance_Of_Team(string organisationId, string teamName) { var moqRepository = new Mock <ITeamRepository>(); moqRepository .Setup(t => t.ExistsByAsync(It.IsAny <Expression <Func <Team, bool> > >())) .ReturnsAsync(false) .Verifiable(); moqRepository .Setup(t => t.AddAsync(It.IsAny <Team>())) .ReturnsAsync(new Team { Name = teamName, OrganisationId = organisationId }) .Verifiable(); var moqOrgRepository = new Mock <IOrganisationRepository>(); moqOrgRepository .Setup(t => t.ExistsByAsync(It.IsAny <Expression <Func <Organisation, bool> > >())) .ReturnsAsync(true) .Verifiable(); var service = new Application.TeamService(moqRepository.Object, moqOrgRepository.Object, null); var teamResult = await service.AddAsync("organisationId", new DataContracts.Team { Name = teamName }); moqRepository.VerifyAll(); moqOrgRepository.VerifyAll(); Assert.NotNull(teamResult); Assert.Equal(teamName, teamResult.Name); }
public async Task Given_Exists_Team_When_Call_AddAsync_ShouldReturns_NameAlreadyUseException() { var moqRepository = new Mock <ITeamRepository>(); moqRepository .Setup(t => t.ExistsByAsync(It.IsAny <Expression <Func <Team, bool> > >())) .ReturnsAsync(true) .Verifiable(); var moqOrgRepository = new Mock <IOrganisationRepository>(); moqOrgRepository .Setup(t => t.ExistsByAsync(It.IsAny <Expression <Func <Organisation, bool> > >())) .ReturnsAsync(true) .Verifiable(); var service = new Application.TeamService(moqRepository.Object, moqOrgRepository.Object, null); await Assert.ThrowsAsync <NameAlreadyUsedException>(() => service.AddAsync("", new DataContracts.Team { Name = "development" })); moqRepository.Verify(t => t.AddAsync(It.IsAny <Team>()), Times.Never); moqRepository.Verify(); moqOrgRepository.Verify(); }
public async Task Given_Not_Exists_Team_When_Call_UpdateAsync_ShouldReturns_Null_Reference() { var moqRepository = new Mock <ITeamRepository>(); moqRepository .Setup(t => t.GetByAsync(It.IsAny <Expression <Func <Team, bool> > >())) .ReturnsAsync(() => null) .Verifiable(); var moqOrgRepository = new Mock <IOrganisationRepository>(); moqOrgRepository .Setup(t => t.ExistsByAsync(It.IsAny <Expression <Func <Domain.Entities.Organisation, bool> > >())) .ReturnsAsync(true) .Verifiable(); var service = new Application.TeamService(moqRepository.Object, moqOrgRepository.Object, null); var teamResult = await service.UpdateAsync("", new DataContracts.Team { Name = "development" }); moqRepository.Verify(t => t.UpdateAsync(It.IsAny <Team>()), Times.Never); moqRepository.Verify(); Assert.Null(teamResult); }
public async Task Given_Team_Registered_When_Call_DeleteAsync_ShouldReturns_TaskCompleted(string organisationName, string teamName) { var moqRepository = new Mock <ITeamRepository>(); moqRepository .Setup(t => t.DeleteAsync(It.IsAny <Expression <Func <Domain.Entities.Team, bool> > >())) .ReturnsAsync(true) .Verifiable(); var moqOrgRepository = new Mock <IOrganisationRepository>(); moqOrgRepository .Setup(t => t.ExistsByAsync(It.IsAny <Expression <Func <Organisation, bool> > >())) .ReturnsAsync(true) .Verifiable(); var service = new Application.TeamService(moqRepository.Object, moqOrgRepository.Object, null); await service.DeleteAsync(organisationName, teamName); moqRepository.VerifyAll(); }