public ServiceResult <PortfolioPropertiesResponse> GetProperties() { if (_Portfolio == null) { return(ServiceResult <PortfolioPropertiesResponse> .NotFound()); } var response = new PortfolioPropertiesResponse(); response.Id = _Portfolio.Id; response.Name = _Portfolio.Name; response.StartDate = _Portfolio.StartDate; response.EndDate = _Portfolio.EndDate; foreach (var holding in _Portfolio.Holdings.All()) { var holdingProperty = new RestApi.Portfolios.HoldingProperties() { Stock = holding.Stock.ToSummaryResponse(Date.Today), StartDate = holding.EffectivePeriod.FromDate, EndDate = holding.EffectivePeriod.ToDate, ParticipatingInDrp = holding.Settings.ParticipateInDrp }; response.Holdings.Add(holdingProperty); } return(ServiceResult <PortfolioPropertiesResponse> .Ok(response)); }
public async Task GetProperties() { var mockRepository = new MockRepository(MockBehavior.Strict); var portfolioId = Guid.NewGuid(); var response = new PortfolioPropertiesResponse() { Id = portfolioId }; var messageHandler = mockRepository.Create <IRestClientMessageHandler>(); messageHandler.SetupProperty(x => x.Portfolio, portfolioId); messageHandler.Setup(x => x.GetAsync <PortfolioPropertiesResponse>(It.Is <string>(x => x == "portfolio/" + portfolioId + "/properties"))) .Returns(Task <PortfolioPropertiesResponse> .FromResult(response)) .Verifiable(); var resource = new PortfolioResource(messageHandler.Object); var result = await resource.GetProperties(); result.Should().Be(response); mockRepository.Verify(); }
public void GetProperties() { var mockRepository = new MockRepository(MockBehavior.Strict); var response = new PortfolioPropertiesResponse(); var service = mockRepository.Create <IPortfolioPropertiesService>(); service.Setup(x => x.GetProperties()).Returns(ServiceResult <PortfolioPropertiesResponse> .Ok(response)).Verifiable(); var controller = new PortfolioController(); var result = controller.GetProperties(service.Object); result.Result.Should().BeOkObjectResult().Value.Should().Be(response); mockRepository.VerifyAll(); }