mirror of
https://github.com/mgroves/MonodroidStockPortfolio.git
synced 2024-12-26 03:00:17 +00:00
users can now add different lots of same ticker to same portfolio
This commit is contained in:
parent
be37ce7087
commit
a85aa217a9
4 changed files with 1 additions and 46 deletions
|
@ -35,7 +35,7 @@ namespace MonoStockPortfolio.Core.Services
|
|||
var positions = _portRepo.GetAllPositions(portfolioID);
|
||||
if (!positions.Any()) return new List<PositionResultsViewModel>();
|
||||
|
||||
var tickers = positions.Select(p => p.Ticker);
|
||||
var tickers = positions.Select(p => p.Ticker).Distinct();
|
||||
var stockData = _stockRepo.GetStockQuotes(tickers);
|
||||
|
||||
foreach (var position in positions)
|
||||
|
|
|
@ -66,7 +66,6 @@
|
|||
<Compile Include="Presenters\Config\Given_an_initialized_Config_Presenter.cs" />
|
||||
<Compile Include="Presenters\EditPortfolio\EditPortfolioTests.cs" />
|
||||
<Compile Include="Presenters\EditPosition\EditPositionTests.cs" />
|
||||
<Compile Include="Presenters\EditPosition\When_the_user_tries_to_save_a_position_for_a_ticker_thats_already_being_tracked.cs" />
|
||||
<Compile Include="Presenters\Main\MainPresenterTests.cs" />
|
||||
<Compile Include="Presenters\Main\When_the_user_wants_to_see_About_info.cs" />
|
||||
<Compile Include="Presenters\Portfolio\PortfolioPresenterTests.cs" />
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Machine.Specifications;
|
||||
using MonoStockPortfolio.Activites.EditPositionScreen;
|
||||
using MonoStockPortfolio.Entities;
|
||||
using Telerik.JustMock;
|
||||
|
||||
namespace MonoStockPortfolio.Tests.Presenters.EditPosition
|
||||
{
|
||||
[Tags("UnitTest")]
|
||||
public class When_the_user_tries_to_save_a_position_for_a_ticker_thats_already_being_tracked : EditPositionTests
|
||||
{
|
||||
Establish context = () =>
|
||||
{
|
||||
_presenter.Initialize(_mockView, 1);
|
||||
|
||||
Mock.Arrange(() => _mockStockService.IsValidTicker(Arg.AnyString)).Returns(true);
|
||||
Mock.Arrange(() => _mockPortfolioRepository.IsTickerAlreadyBeingTracked(Arg.AnyString, Arg.AnyLong)).Returns(true);
|
||||
};
|
||||
|
||||
Because of = () =>
|
||||
{
|
||||
var fakeInputModel = new PositionInputModel { PriceText = "5", SharesText = "5", TickerText = "ABC" };
|
||||
_presenter.Save(fakeInputModel);
|
||||
};
|
||||
|
||||
It should_not_try_to_save_the_portfolio = () =>
|
||||
Mock.Assert(() => _mockPortfolioRepository.SavePosition(Arg.IsAny<Position>()), Occurs.Never());
|
||||
It should_send_the_validation_errors_to_the_view = () =>
|
||||
Mock.Assert(() => _mockView.ShowErrorMessages(Arg.IsAny<IList<string>>()), Occurs.Exactly(1));
|
||||
It should_send_a_duplicate_ticker_error_to_the_view = () =>
|
||||
MockPositionMatches(x => x.Any(p => p == "You are already tracking that ticker in this portfolio"));
|
||||
}
|
||||
}
|
|
@ -49,7 +49,6 @@ namespace MonoStockPortfolio.Activites.EditPositionScreen
|
|||
validator.AddValidPositiveDecimal(() => positionInputModel.SharesText, "Please enter a valid, positive number of shares");
|
||||
validator.AddValidPositiveDecimal(() => positionInputModel.PriceText, "Please enter a valid, positive price per share");
|
||||
validator.AddValidation(() => ValidateTicker(positionInputModel.TickerText));
|
||||
validator.AddValidation(() => ValidateNotRepeatTicker(positionInputModel.TickerText));
|
||||
|
||||
var errorMessages = validator.Apply();
|
||||
if (!errorMessages.Any())
|
||||
|
@ -97,14 +96,5 @@ namespace MonoStockPortfolio.Activites.EditPositionScreen
|
|||
return "Unable to load stock information from the web";
|
||||
}
|
||||
}
|
||||
|
||||
private string ValidateNotRepeatTicker(string ticker)
|
||||
{
|
||||
if(_portfolioRepository.IsTickerAlreadyBeingTracked(ticker, _portfolioId))
|
||||
{
|
||||
return "You are already tracking that ticker in this portfolio";
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue