Пример #1
0
 public IHttpActionResult Post([FromBody] InvestorDto investor)
 {
     try
     {
         if (investor != null)
         {
             return(Ok(personBLL.CreateNewPerson(investor)));
         }
         else
         {
             return(BadRequest());
         }
     }
     catch (Exception e)
     {
         // LOG ERROR
         return(InternalServerError(e));
     }
 }
        public async Task get_async_returns_mapped_investor_if_it_exists()
        {
            //Given
            var investor = GetDefaultInvestor();

            investor.AddToFavouriteCompanies("AAPL");
            investor.AddToFavouriteCompanies("MSFN");

            var expectedInvestorDto = new InvestorDto()
            {
                UserId             = investor.UserId,
                UpdatedAt          = investor.UpdatedAt,
                FavouriteCompanies = new List <string>(investor.FavouriteCompanies)
            };

            var userRepositoryMock = new Mock <IUserRepository>();

            var investorRepositoryMock = new Mock <IInvestorRepository>();

            investorRepositoryMock.Setup(x => x.GetAsync(investor.UserId))
            .Returns(Task.FromResult(investor));


            var companyRepositoryMock = new Mock <ICompanyRepository>();

            var mapperMock = new Mock <IMapper>();

            mapperMock.Setup(x => x.Map <InvestorDto>(It.IsAny <Investor>()))
            .Returns(expectedInvestorDto);

            var investorService = new InvestorService(userRepositoryMock.Object,
                                                      investorRepositoryMock.Object, companyRepositoryMock.Object,
                                                      mapperMock.Object);

            //When
            var occuredInvestorDto = await investorService.GetAsync(investor.UserId);

            //Then
            occuredInvestorDto.Should().BeEquivalentTo(expectedInvestorDto);
            mapperMock.Verify(x => x.Map <InvestorDto>(It.IsAny <Investor>()), Times.Once);
        }
        public async Task get_async_using_mail_returns_mapping_result()
        {
            //Given
            var user        = GetDefaultUser();
            var investor    = new Investor(user);
            var investorDto = new InvestorDto();

            var userRepositoryMock = new Mock <IUserRepository>();

            userRepositoryMock.Setup(x => x.GetAsync(user.Email))
            .Returns(Task.FromResult(user));

            var investorRepositoryMock = new Mock <IInvestorRepository>();

            investorRepositoryMock.Setup(x => x.GetAsync(user.Id))
            .Returns(Task.FromResult(investor));

            var companyRepositoryMock = new Mock <ICompanyRepository>();

            var mapperMock = new Mock <IMapper>();

            mapperMock.Setup(x => x.Map <InvestorDto>(investor))
            .Returns(investorDto);

            var investorService = new InvestorService(userRepositoryMock.Object,
                                                      investorRepositoryMock.Object, companyRepositoryMock.Object,
                                                      mapperMock.Object);

            //When
            var returnedInvestorDto = await investorService.GetAsync(user.Email);

            //Then
            userRepositoryMock.Verify(x => x.GetAsync(user.Email), Times.Once);
            investorRepositoryMock.Verify(x => x.GetAsync(user.Id), Times.Once);
            mapperMock.Verify(x => x.Map <InvestorDto>(investor), Times.Once);
            returnedInvestorDto.Should().BeSameAs(investorDto);
        }