mirror of
https://github.com/mgroves/MonodroidStockPortfolio.git
synced 2024-11-14 19:29:26 +00:00
hammered out race conditions in Portfolio Presenter tests finally, also renamed the CSV folder to reflect the new CSV library I'm using
This commit is contained in:
parent
fef665cdee
commit
872df67ffd
24 changed files with 59 additions and 13 deletions
|
@ -60,7 +60,7 @@
|
|||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\MonoDroid.FileHelpers\MonoDroid.LumenWorks.Framework.IO.Csv.csproj">
|
||||
<ProjectReference Include="..\MonoDroid.LumenWorks.Framework.IO.Csv\MonoDroid.LumenWorks.Framework.IO.Csv.csproj">
|
||||
<Project>{1AAA2739-D853-41B0-866B-B55B373616E1}</Project>
|
||||
<Name>MonoDroid.LumenWorks.Framework.IO.Csv</Name>
|
||||
</ProjectReference>
|
||||
|
|
|
@ -40,6 +40,10 @@
|
|||
<Reference Include="mscorlib">
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="PostSharp.SL, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b13fd38b8f9c99d7, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\libs\PostSharp.SL.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System">
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
|
@ -49,9 +53,6 @@
|
|||
<Reference Include="System.Xml.Linq">
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml">
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Telerik.JustMock.Silverlight">
|
||||
<HintPath>..\libs\Telerik.JustMock.Silverlight.dll</HintPath>
|
||||
</Reference>
|
||||
|
|
|
@ -1,18 +1,19 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using Machine.Specifications;
|
||||
using MonoStockPortfolio.Activites.PortfolioScreen;
|
||||
using MonoStockPortfolio.Core.Config;
|
||||
using MonoStockPortfolio.Core.PortfolioRepositories;
|
||||
using MonoStockPortfolio.Core.Services;
|
||||
using MonoStockPortfolio.Entities;
|
||||
using MonoStockPortfolio.Framework;
|
||||
using Telerik.JustMock;
|
||||
|
||||
namespace MonoStockPortfolio.Tests.Presenters
|
||||
{
|
||||
public class Given_an_initialized_Portfolio_Presenter
|
||||
{
|
||||
protected static PortfolioPresenter _presenter;
|
||||
protected static IPortfolioPresenter _presenter;
|
||||
protected static IPortfolioRepository _mockPortfolioRepository;
|
||||
protected static IPortfolioService _mockPortfolioService;
|
||||
protected static IConfigRepository _mockConfigRepository;
|
||||
|
@ -20,6 +21,8 @@ namespace MonoStockPortfolio.Tests.Presenters
|
|||
|
||||
Establish context = () =>
|
||||
{
|
||||
OnWorkerThreadAttribute.ThreadingService = new DoNotThreadService();
|
||||
|
||||
_mockPortfolioRepository = Mock.Create<IPortfolioRepository>();
|
||||
Mock.Arrange(() => _mockPortfolioRepository.GetPortfolioById(999)).Returns(new Portfolio(123) { Name = "Test Portfolio" });
|
||||
|
||||
|
@ -29,22 +32,32 @@ namespace MonoStockPortfolio.Tests.Presenters
|
|||
|
||||
_mockConfigRepository = Mock.Create<IConfigRepository>();
|
||||
_mockView = Mock.Create<IPortfolioView>();
|
||||
Mock.Arrange(() => _mockView.StartEditPosition(Arg.AnyInt, Arg.AnyLong)).DoNothing(); // i don't know why this has to be here to pass the "edit" context option test
|
||||
|
||||
_presenter = new PortfolioPresenter(_mockPortfolioRepository, _mockPortfolioService, _mockConfigRepository);
|
||||
|
||||
_presenter.Initialize(_mockView, 999);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
internal class DoNotThreadService : IThreadingService
|
||||
{
|
||||
public void QueueUserWorkItem(WaitCallback func)
|
||||
{
|
||||
func.Invoke(null);
|
||||
}
|
||||
}
|
||||
|
||||
public class When_done_initializing_a_Portfolio_Presenter : Given_an_initialized_Portfolio_Presenter
|
||||
{
|
||||
It should_get_the_positions_list_and_refresh_the_view = () =>
|
||||
It should_show_the_progress_bar_with_a_nice_message = () =>
|
||||
Mock.Assert(() => _mockView.ShowProgressDialog("Loading...Please wait..."), Occurs.Exactly(1));
|
||||
It should_use_the_service_to_get_the_positions = () =>
|
||||
Mock.Assert(() => _mockPortfolioService.GetDetailedItems(999, Arg.IsAny<IEnumerable<StockDataItem>>()), Occurs.Exactly(1));
|
||||
|
||||
It should_hide_the_progress_bar_message = () =>
|
||||
Mock.Assert(() => _mockView.HideProgressDialog(), Occurs.Exactly(1));
|
||||
It should_refresh_the_view = () =>
|
||||
Mock.Assert(() => _mockView.RefreshList(Arg.IsAny<IEnumerable<PositionResultsViewModel>>(), Arg.IsAny<IEnumerable<StockDataItem>>()), Occurs.Exactly(1));
|
||||
|
||||
It should_get_the_portfolio_name_from_the_repository_and_set_the_title_with_that = () =>
|
||||
Mock.Assert(() => _mockView.SetTitle("Portfolio: Test Portfolio"), Occurs.Exactly(1));
|
||||
}
|
||||
|
@ -75,4 +88,19 @@ namespace MonoStockPortfolio.Tests.Presenters
|
|||
It should_use_the_repo_to_delete_the_position = () =>
|
||||
Mock.Assert(() => _mockPortfolioRepository.DeletePositionById(123), Occurs.Exactly(1));
|
||||
}
|
||||
|
||||
public class When_the_user_wants_to_refresh_the_positions : Given_an_initialized_Portfolio_Presenter
|
||||
{
|
||||
Because of = () =>
|
||||
_presenter.RefreshPositions();
|
||||
|
||||
It should_show_the_progress_bar_with_a_nice_message_again = () =>
|
||||
Mock.Assert(() => _mockView.ShowProgressDialog("Loading...Please wait..."), Occurs.Exactly(2));
|
||||
It should_use_the_service_to_get_the_positions_again = () =>
|
||||
Mock.Assert(() => _mockPortfolioService.GetDetailedItems(999, Arg.IsAny<IEnumerable<StockDataItem>>()), Occurs.Exactly(2));
|
||||
It should_hide_the_progress_bar_message_again = () =>
|
||||
Mock.Assert(() => _mockView.HideProgressDialog(), Occurs.Exactly(2));
|
||||
It should_refresh_the_view_again = () =>
|
||||
Mock.Assert(() => _mockView.RefreshList(Arg.IsAny<IEnumerable<PositionResultsViewModel>>(), Arg.IsAny<IEnumerable<StockDataItem>>()), Occurs.Exactly(2));
|
||||
}
|
||||
}
|
|
@ -14,7 +14,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MonoStockPortfolio.Entities
|
|||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MonoStockPortfolio.Tests", "MonoStockPortfolio.Tests\MonoStockPortfolio.Tests.csproj", "{C2797FAB-AFAB-49F6-9131-FC9BF03CAB9D}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MonoDroid.LumenWorks.Framework.IO.Csv", "MonoDroid.FileHelpers\MonoDroid.LumenWorks.Framework.IO.Csv.csproj", "{1AAA2739-D853-41B0-866B-B55B373616E1}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MonoDroid.LumenWorks.Framework.IO.Csv", "MonoDroid.LumenWorks.Framework.IO.Csv\MonoDroid.LumenWorks.Framework.IO.Csv.csproj", "{1AAA2739-D853-41B0-866B-B55B373616E1}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Android.Runtime;
|
||||
using MonoStockPortfolio.Core.Config;
|
||||
using MonoStockPortfolio.Core.PortfolioRepositories;
|
||||
using MonoStockPortfolio.Core.Services;
|
||||
|
|
|
@ -5,9 +5,27 @@ namespace MonoStockPortfolio.Framework
|
|||
{
|
||||
public class OnWorkerThreadAttribute : MethodInterceptionAspect
|
||||
{
|
||||
public static IThreadingService ThreadingService;
|
||||
|
||||
public override void OnInvoke(MethodInterceptionArgs args)
|
||||
{
|
||||
ThreadPool.QueueUserWorkItem(d => args.Proceed());
|
||||
if(ThreadingService == null) ThreadingService = new ThreadingService();
|
||||
ThreadingService.QueueUserWorkItem(d => args.Invoke(args.Arguments));
|
||||
}
|
||||
}
|
||||
|
||||
// this is kinda fail, but it helps with testing to inject in a "non threaded" service
|
||||
// and I suppose it might make refactoring easier maybe...? just go with it
|
||||
public interface IThreadingService
|
||||
{
|
||||
void QueueUserWorkItem(WaitCallback func);
|
||||
}
|
||||
|
||||
public class ThreadingService : IThreadingService
|
||||
{
|
||||
public void QueueUserWorkItem(WaitCallback waitCallback)
|
||||
{
|
||||
ThreadPool.QueueUserWorkItem(waitCallback);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue