public async Task Should_ThrowException_When_PassTeamIdForDifferentCompany() { // Arrange var team = new Team() { TeamName = "Test Team", CompanyId = 2, IsDefault = true, CreatedAt = DateTime.UtcNow, CreatedBy = -1 }; team.TeamMembers.Add(new TeamMember() { IsApprover = true, IsMember = true, UserId = 1 }); _fixture.Context.Teams.Attach(team); await _fixture.Context.SaveChangesAsync(); IUnitOfWork unitOfWork = new UnitOfWork(_fixture.Context); IRepository <Team> repository = new Repository <Team>(_fixture.Context); IRepository <TeamMember> teamMemberRepository = new Repository <TeamMember>(_fixture.Context); var handler = new DeleteTeamHandler(unitOfWork, repository, _logger, _mapper); var request = new DeleteTeamCommand(companyId: 1, teamId: 1); // Act var tcs = new CancellationToken(); var exception = await Assert.ThrowsAsync <VacationTrackingException>(async() => { var result = await handler.Handle(request, tcs); }); // Assert Assert.Equal(ExceptionMessages.ItemNotFound, exception.Message); Assert.Equal(404, exception.Code); }
public async Task Should_ThrowException_When_PassInvalidTeamId() { // Arrange IUnitOfWork unitOfWork = new UnitOfWork(_fixture.Context); IRepository <Team> repository = new Repository <Team>(_fixture.Context); IRepository <TeamMember> teamMemberRepository = new Repository <TeamMember>(_fixture.Context); var handler = new DeleteTeamHandler(unitOfWork, repository, _logger, _mapper); var request = new DeleteTeamCommand(companyId: 1, teamId: -1); // Act var tcs = new CancellationToken(); var exception = await Assert.ThrowsAsync <VacationTrackingException>(async() => { var result = await handler.Handle(request, tcs); }); // Assert Assert.Equal(ExceptionMessages.ItemNotFound, exception.Message); Assert.Equal(404, exception.Code); }
public async Task ShouldDeleteTeamCorrectly() { //Arrange var testUser = new User("test", "test", "test", "test"); var testTeam = new Team(testUser, "test", "test"); var dateDeleted = new DateTime(); var teamsRepository = new Mock <ITeamsRepository>(); teamsRepository.Setup(x => x.Get(It.IsAny <Guid>())).Returns(testTeam); teamsRepository.Setup(x => x.UpdateAsync(It.IsAny <Team>())).Callback <Team>(x => { testTeam = x; dateDeleted = testTeam.ChangedAt; }).Returns(Task.CompletedTask); var deleteTeamHandler = new DeleteTeamHandler(teamsRepository.Object); var command = new DeleteTeamCommand(testTeam.Id); //Act await deleteTeamHandler.HandleAsync(command); //Assert teamsRepository.Verify(x => x.Get(It.IsAny <Guid>()), Times.Once); teamsRepository.Verify(x => x.UpdateAsync(It.IsAny <Team>()), Times.Once); Assert.That(testTeam.Deleted); Assert.That(testTeam.ChangedAt, Is.EqualTo(dateDeleted)); }
public async Task Should_DeleteTeamWithMember_When_PassTeamId() { // Arrange var team = new Team() { TeamName = "Test Team", CompanyId = 1, CreatedAt = DateTime.UtcNow, CreatedBy = -1 }; team.TeamMembers.Add(new TeamMember() { IsApprover = true, IsMember = true, UserId = 1 }); _fixture.Context.Teams.Attach(team); await _fixture.Context.SaveChangesAsync(); IUnitOfWork unitOfWork = new UnitOfWork(_fixture.Context); IRepository <Team> repository = new Repository <Team>(_fixture.Context); IRepository <TeamMember> teamMemberRepository = new Repository <TeamMember>(_fixture.Context); var handler = new DeleteTeamHandler(unitOfWork, repository, _logger, _mapper); var request = new DeleteTeamCommand(companyId: 1, teamId: 1); // Act var tcs = new CancellationToken(); var result = await handler.Handle(request, tcs); // Assert Assert.True(result); Assert.False(teamMemberRepository.Queryable().Any(x => x.TeamId == 1)); }