示例#1
0
        /// <summary>
        /// Save update club details
        /// </summary>
        /// <param name="clubDetailsDto"></param>
        /// <returns></returns>
        public bool SaveClubDetails(ClubDetailsDto clubDetailsDto)
        {
            try
            {
                var club = _clubRepository.FirstOrDefault(c => c.Id == clubDetailsDto.Id);

                if (club != null)
                {
                    club.Name       = clubDetailsDto.Name;
                    club.CountryId  = clubDetailsDto.CountryId;
                    club.Eliminated = clubDetailsDto.Eliminated;

                    var rowCount = _clubRepository.Save();

                    return(rowCount == 1);
                }
            }
            catch
            {
                // log error when impl
                return(false);
            }

            return(false);
        }
示例#2
0
        public void Should_return_false_when_attempting_to_save_non_existent_club()
        {
            // Arrange
            var clubRepository = new Mock <IGenericRepository <Club> >();

            var clubService = new ClubService(_mapper, null, clubRepository.Object);

            clubRepository.Setup(r => r.FirstOrDefault(It.IsAny <Expression <Func <Club, bool> > >())).Returns((Club)null);
            clubRepository.Setup(r => r.Save()).Returns(0);

            var updatedClubDetailsDto = new ClubDetailsDto
            {
                Id         = _testClubEntity.Id,
                Name       = _testClubEntity.Name,
                CountryId  = _testClubEntity.CountryId,
                Eliminated = !_testClubEntity.Eliminated,
            };

            // Act
            var result = clubService.SaveClubDetails(updatedClubDetailsDto);

            // Assert
            Assert.That(result, Is.False);
        }
示例#3
0
        public void Should_successfuly_save_club_details()
        {
            // Arrange
            var clubRepository = new Mock <IGenericRepository <Club> >();

            var clubService = new ClubService(_mapper, null, clubRepository.Object);

            clubRepository.Setup(r => r.FirstOrDefault(It.IsAny <Expression <Func <Club, bool> > >())).Returns(_testClubEntity);
            clubRepository.Setup(r => r.Save()).Returns(1);

            var updatedClubDetailsDto = new ClubDetailsDto
            {
                Id         = _testClubEntity.Id,
                Name       = _testClubEntity.Name,
                CountryId  = _testClubEntity.CountryId,
                Eliminated = !_testClubEntity.Eliminated,
            };

            // Act
            var result = clubService.SaveClubDetails(updatedClubDetailsDto);

            // Assert
            Assert.That(result, Is.True);
        }