moved ittybitty to another project, wrote tests for MainPresenter (with JustMock)

This commit is contained in:
mgroves 2011-03-10 21:32:51 -05:00
parent 158cf7916d
commit 0504e27f8c
13 changed files with 264 additions and 12 deletions

View file

@ -0,0 +1,52 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{83658808-E964-4F0F-8C0F-FE33B5F7CE3B}</ProjectGuid>
<ProjectTypeGuids>{EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>IttyBitty</RootNamespace>
<AssemblyName>IttyBitty</AssemblyName>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="mscorlib" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="IttyBittyIoC.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View file

@ -0,0 +1,29 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("IttyBitty")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("IttyBitty")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2011")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View file

@ -0,0 +1,156 @@
using System.Collections.Generic;
using System.Linq;
using MonoStockPortfolio.Activites.Main;
using MonoStockPortfolio.Core.PortfolioRepositories;
using MonoStockPortfolio.Entities;
using Telerik.JustMock;
using Xunit;
namespace MonoStockPortfolio.Tests.Activities
{
public abstract class MainActivityTest
{
protected IMainPresenter _presenter;
protected IPortfolioRepository _mockPortfolioRepository;
protected IMainView _mockView;
protected IList<Portfolio> _portfolioList;
protected Portfolio _portfolio1;
protected Portfolio _portfolio2;
// startup
protected MainActivityTest()
{
_portfolio1 = new Portfolio(555) {Name = "portfolio1"};
_portfolio2 = new Portfolio(777) {Name = "portfolio2"};
_portfolioList = new List<Portfolio>();
_portfolioList.Add(_portfolio1);
_portfolioList.Add(_portfolio2);
_mockPortfolioRepository = Mock.Create<IPortfolioRepository>();
Mock.Arrange(() => _mockPortfolioRepository.GetAllPortfolios()).Returns(_portfolioList);
Mock.Arrange(() => _mockPortfolioRepository.GetPortfolioByName("portfolio1")).Returns(_portfolio1);
_mockView = Mock.Create<IMainView>();
_presenter = new MainPresenter(_mockPortfolioRepository);
_presenter.Initialize(_mockView);
}
}
public class When_initializing_the_Main_Presenter : MainActivityTest
{
[Fact]
public void Initialization_should_get_the_portfolio_list_and_refresh_the_view()
{
Mock.Assert(() => _mockPortfolioRepository.GetAllPortfolios(), Occurs.Exactly(1));
Mock.Assert(() => _mockView.RefreshList(Arg.IsAny<IList<string>>()), Occurs.Exactly(1));
var exp = Arg.Matches<IList<string>>(
stringList => stringList.SequenceEqual(_portfolioList.Select(p => p.Name))
);
Mock.Assert(() => _mockView.RefreshList(exp));
}
}
public class When_the_user_wants_to_add_a_new_portfolio : MainActivityTest
{
public When_the_user_wants_to_add_a_new_portfolio()
{
_presenter.AddNewPortfolio();
}
[Fact]
public void Then_the_Presenter_should_tell_the_view_to_bring_up_the_Add_new_portfolio_screen()
{
Mock.Assert(() => _mockView.StartAddPortfolioActivity(),Occurs.Exactly(1));
}
}
public class When_the_user_wants_to_view_a_portfolio : MainActivityTest
{
public When_the_user_wants_to_view_a_portfolio()
{
_presenter.ViewPortfolio(1);
}
[Fact]
public void Then_the_Presenter_should_tell_the_view_to_bring_up_the_View_Portfolio_screen_with_the_given_position()
{
var id = _portfolioList[1].ID ?? -1;
Mock.Assert(() => _mockView.StartViewPortfolioActivity(id), Occurs.Exactly(1));
}
}
public class When_the_user_wants_to_delete_a_portfolio : MainActivityTest
{
public When_the_user_wants_to_delete_a_portfolio()
{
_presenter.DeletePortfolio(990099);
}
[Fact]
public void Then_the_Presenter_should_use_the_repo_to_delete_the_portfolio_with_the_given_ID()
{
Mock.Assert(() => _mockPortfolioRepository.DeletePortfolioById(990099), Occurs.Exactly(1));
}
}
public class When_the_user_wants_to_edit_a_portfolio : MainActivityTest
{
public When_the_user_wants_to_edit_a_portfolio()
{
_presenter.EditPortfolio(909);
}
[Fact]
public void Then_the_presenter_should_tell_the_view_to_start_up_an_edit_activity_for_the_given_portfolio_id()
{
Mock.Assert(() => _mockView.StartEditPortfolioActivity(909), Occurs.Exactly(1));
}
}
public class When_the_user_wants_to_configure_the_display_fields : MainActivityTest
{
public When_the_user_wants_to_configure_the_display_fields()
{
_presenter.GotoConfig();
}
[Fact]
public void Then_the_presenter_should_tell_the_view_to_start_up_the_config_activity()
{
Mock.Assert(() => _mockView.StartConfigActivity(), Occurs.Exactly(1));
}
}
public class When_the_user_wants_to_exit_the_app : MainActivityTest
{
public When_the_user_wants_to_exit_the_app()
{
_presenter.ExitApplication();
}
[Fact]
public void Then_the_presenter_should_tell_the_view_to_start_up_the_config_activity()
{
Mock.Assert(() => _mockView.ExitApplication(), Occurs.Exactly(1));
}
}
public class When_the_user_wants_to_see_the_context_menu : MainActivityTest
{
private int _id;
public When_the_user_wants_to_see_the_context_menu()
{
_id = _presenter.GetPortfolioIdForContextMenu(_portfolio1.Name);
}
[Fact]
public void Then_the_presenter_should_use_the_given_name_to_lookup_the_ID_and_return_it()
{
Mock.Assert(() => _mockPortfolioRepository.GetPortfolioByName(_portfolio1.Name), Occurs.Exactly(1));
Assert.Equal(_portfolio1.ID, _id);
}
}
}

View file

@ -49,15 +49,23 @@
<Reference Include="System.Xml">
<Private>True</Private>
</Reference>
<Reference Include="Telerik.JustMock.Silverlight">
<HintPath>..\libs\Telerik.JustMock.Silverlight.dll</HintPath>
</Reference>
<Reference Include="xunit">
<HintPath>..\libs\xunit.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Activities\MainActivityTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="YahooStockDataProviderTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\IttyBitty\IttyBitty.csproj">
<Project>{83658808-E964-4F0F-8C0F-FE33B5F7CE3B}</Project>
<Name>IttyBitty</Name>
</ProjectReference>
<ProjectReference Include="..\MonoStockPortfolio.Core\MonoStockPortfolio.Core.csproj">
<Project>{251E7BB4-CFE2-4DE4-9E2A-AAE1AF41C8CB}</Project>
<Name>MonoStockPortfolio.Core</Name>

View file

@ -17,6 +17,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MonoStockPortfolio.Tests",
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}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IttyBitty", "IttyBitty\IttyBitty.csproj", "{83658808-E964-4F0F-8C0F-FE33B5F7CE3B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -42,6 +44,10 @@ Global
{1AAA2739-D853-41B0-866B-B55B373616E1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1AAA2739-D853-41B0-866B-B55B373616E1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1AAA2739-D853-41B0-866B-B55B373616E1}.Release|Any CPU.Build.0 = Release|Any CPU
{83658808-E964-4F0F-8C0F-FE33B5F7CE3B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{83658808-E964-4F0F-8C0F-FE33B5F7CE3B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{83658808-E964-4F0F-8C0F-FE33B5F7CE3B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{83658808-E964-4F0F-8C0F-FE33B5F7CE3B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View file

@ -1,4 +1,4 @@
namespace MonoStockPortfolio.Presenters
namespace MonoStockPortfolio.Activites.Main
{
public interface IMainPresenter
{

View file

@ -1,6 +1,6 @@
using System.Collections.Generic;
namespace MonoStockPortfolio.Presenters
namespace MonoStockPortfolio.Activites.Main
{
public interface IMainView
{

View file

@ -7,10 +7,8 @@ using Android.Util;
using Android.Views;
using Android.Widget;
using MonoStockPortfolio.Framework;
using MonoStockPortfolio.Presenters;
using System.Linq;
namespace MonoStockPortfolio.Activites
namespace MonoStockPortfolio.Activites.Main
{
[Activity(Label = "Stock Portfolio", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity, IMainView

View file

@ -3,7 +3,7 @@ using MonoStockPortfolio.Core.PortfolioRepositories;
using MonoStockPortfolio.Entities;
using System.Linq;
namespace MonoStockPortfolio.Presenters
namespace MonoStockPortfolio.Activites.Main
{
public class MainPresenter : IMainPresenter
{

View file

@ -1,10 +1,10 @@
using System;
using Android.Content;
using MonoStockPortfolio.Activites.Main;
using MonoStockPortfolio.Core.Config;
using MonoStockPortfolio.Core.PortfolioRepositories;
using MonoStockPortfolio.Core.Services;
using MonoStockPortfolio.Core.StockData;
using MonoStockPortfolio.Presenters;
namespace MonoStockPortfolio.Framework
{

View file

@ -52,17 +52,16 @@
<ItemGroup>
<Compile Include="Activites\ConfigActivity.cs" />
<Compile Include="Activites\EditPortfolioActivity.cs" />
<Compile Include="Presenters\IMainPresenter.cs" />
<Compile Include="Presenters\IMainView.cs" />
<Compile Include="Presenters\MainPresenter.cs" />
<Compile Include="Activites\Main\IMainPresenter.cs" />
<Compile Include="Activites\Main\IMainView.cs" />
<Compile Include="Activites\Main\MainPresenter.cs" />
<Compile Include="Framework\ActivityExtensions.cs" />
<Compile Include="Framework\ContextExtensions.cs" />
<Compile Include="Framework\GenericArrayAdapter.cs" />
<Compile Include="Activites\PortfolioActivity.cs" />
<Compile Include="Activites\MainActivity.cs" />
<Compile Include="Activites\Main\MainActivity.cs" />
<Compile Include="Activites\EditPositionActivity.cs" />
<Compile Include="Framework\IoCAttribute.cs" />
<Compile Include="Framework\IttyBittyIoC.cs" />
<Compile Include="Framework\LazyViewAttribute.cs" />
<Compile Include="Framework\ManifestNames.cs" />
<Compile Include="Framework\OnGuiThreadAttribute.cs" />
@ -99,6 +98,10 @@
</AndroidResource>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\IttyBitty\IttyBitty.csproj">
<Project>{83658808-E964-4F0F-8C0F-FE33B5F7CE3B}</Project>
<Name>IttyBitty</Name>
</ProjectReference>
<ProjectReference Include="..\MonoStockPortfolio.Core\MonoStockPortfolio.Core.csproj">
<Project>{251E7BB4-CFE2-4DE4-9E2A-AAE1AF41C8CB}</Project>
<Name>MonoStockPortfolio.Core</Name>

Binary file not shown.