public async Task HandleShouldReturnOk()
        {
            // Arrange
            var id   = Guid.NewGuid();
            var name = "name";

            var teamReadRepositoryMock = new Mock <ITeamReadRepository>();

            teamReadRepositoryMock.Setup(x => x.GetAsync(id)).Returns(Task.FromResult(new Team(TeamId.With(id), new Name(name))));
            var teamReadRepository     = teamReadRepositoryMock.Object;
            var operatorReadRepository = new Mock <IOperatorReadRepository>().Object;

            var mapperMock = new Mock <IMapper>();

            mapperMock.Setup(x => x.Map <TeamModel>(It.IsAny <object>())).Returns(new TeamModel());
            var mapper = mapperMock.Object;

            var query = new GetTeamQuery(id);

            var handler = new GetTeamQueryHandler(mapper, teamReadRepository, operatorReadRepository);

            // Act
            var result = await handler.Handle(query, CancellationToken.None);

            // Assert
            result.IsFailure.Should().BeFalse();
            result.Should().BeOfType(typeof(Result <TeamModel>));
        }
        public async Task HandleShouldReturnFailWhenNotFound()
        {
            // Arrange
            var id = Guid.NewGuid();

            var teamReadRepositoryMock = new Mock <ITeamReadRepository>();

            teamReadRepositoryMock.Setup(x => x.GetAsync(id)).Throws <EntityNotFoundDbException>();
            var teamReadRepository     = teamReadRepositoryMock.Object;
            var operatorReadRepository = new Mock <IOperatorReadRepository>().Object;

            var mapperMock = new Mock <IMapper>();

            mapperMock.Setup(x => x.Map <TeamModel>(It.IsAny <object>())).Returns(new TeamModel());
            var mapper = mapperMock.Object;

            var query = new GetTeamQuery(id);

            var handler = new GetTeamQueryHandler(mapper, teamReadRepository, operatorReadRepository);

            // Act
            var result = await handler.Handle(query, CancellationToken.None);

            // Assert
            result.IsFailure.Should().BeTrue();
            result.Failures.Should().OnlyContain(x => x.Code == HandlerFaultCode.NotFound.Name &&
                                                 x.Message == HandlerFailures.TeamNotFound &&
                                                 x.Target == "id");
        }
        public async Task HandleShouldReturnFailWhenDatabaseSpecificErrorOccurs()
        {
            // Arrange
            var id = Guid.NewGuid();

            var teamReadRepositoryMock = new Mock <ITeamReadRepository>();

            teamReadRepositoryMock.Setup(x => x.GetAsync(id)).Throws <SomeDatabaseSpecificException>();
            var teamReadRepository     = teamReadRepositoryMock.Object;
            var operatorReadRepository = new Mock <IOperatorReadRepository>().Object;

            var mapperMock = new Mock <IMapper>();

            mapperMock.Setup(x => x.Map <TeamModel>(It.IsAny <object>())).Returns(new TeamModel());
            var mapper = mapperMock.Object;

            var query = new GetTeamQuery(id);

            var handler = new GetTeamQueryHandler(mapper, teamReadRepository, operatorReadRepository);

            // Act
            var result = await handler.Handle(query, CancellationToken.None);

            // Assert
            result.IsFailure.Should().BeTrue();
            result.Failures.Should().OnlyContain(x => x.Message == CustomFailures.GetTeamFailure);
        }
        public async Task GetTeamDetail()
        {
            var sut = new GetTeamQueryHandler(_context, _mapper);

            var result = await sut.Handle(new GetTeamQuery { TeamId = validId }, CancellationToken.None);

            result.ShouldBeOfType <TeamModel>();
            result.Id.ShouldBe(validId);
        }