mirror of
https://github.com/mgroves/MonodroidStockPortfolio.git
synced 2024-12-29 11:17:07 +00:00
refactored tests out of xunit
This commit is contained in:
parent
1098cdd056
commit
8d9e6d4919
11 changed files with 103 additions and 145 deletions
|
@ -1,28 +0,0 @@
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using Machine.Specifications;
|
|
||||||
using MonoStockPortfolio.Activites.EditPortfolioScreen;
|
|
||||||
using MonoStockPortfolio.Framework;
|
|
||||||
|
|
||||||
namespace MonoStockPortfolio.Tests.Framework
|
|
||||||
{
|
|
||||||
public class ValidationTests
|
|
||||||
{
|
|
||||||
static FormValidator _validator;
|
|
||||||
static IEnumerable<string> _errors;
|
|
||||||
|
|
||||||
Establish context = () =>
|
|
||||||
{
|
|
||||||
_validator = new FormValidator();
|
|
||||||
};
|
|
||||||
|
|
||||||
Because of = () =>
|
|
||||||
{
|
|
||||||
_validator.AddRequired(() => "", "This is required");
|
|
||||||
_errors = _validator.Apply();
|
|
||||||
};
|
|
||||||
|
|
||||||
It should_return_1_error_message = () =>
|
|
||||||
_errors.Count().ShouldEqual(1);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Machine.Specifications;
|
||||||
|
using MonoStockPortfolio.Framework;
|
||||||
|
|
||||||
|
namespace MonoStockPortfolio.Tests.Framework
|
||||||
|
{
|
||||||
|
public class When_validating_forms_with_validation_errors
|
||||||
|
{
|
||||||
|
static FormValidator _validator;
|
||||||
|
static IEnumerable<string> _errors;
|
||||||
|
|
||||||
|
Establish context = () =>
|
||||||
|
{
|
||||||
|
_validator = new FormValidator();
|
||||||
|
};
|
||||||
|
|
||||||
|
Because of = () =>
|
||||||
|
{
|
||||||
|
_validator.AddRequired(() => "", "This is required");
|
||||||
|
_validator.AddValidDecimal(() => "not a decimal", "Decimal required");
|
||||||
|
_validator.AddValidPositiveDecimal(() => "-18.9", "Positive decimal required");
|
||||||
|
_validator.AddValidation(() => "arbitrary error!");
|
||||||
|
_errors = _validator.Apply();
|
||||||
|
};
|
||||||
|
|
||||||
|
It should_return_1_error_message = () =>
|
||||||
|
_errors.Count().ShouldEqual(4);
|
||||||
|
It should_have_a_required_message = () =>
|
||||||
|
_errors.Any(e => e == "This is required").ShouldBeTrue();
|
||||||
|
It should_have_a_valid_decimal_message = () =>
|
||||||
|
_errors.Any(e => e == "Decimal required").ShouldBeTrue();
|
||||||
|
It should_have_a_valid_positive_decimal_message = () =>
|
||||||
|
_errors.Any(e => e == "Positive decimal required").ShouldBeTrue();
|
||||||
|
It should_have_an_arbitrary_message = () =>
|
||||||
|
_errors.Any(e => e == "arbitrary error!").ShouldBeTrue();
|
||||||
|
}
|
||||||
|
}
|
|
@ -21,6 +21,7 @@
|
||||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
|
<NoWarn>169</NoWarn>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
<DebugType>pdbonly</DebugType>
|
<DebugType>pdbonly</DebugType>
|
||||||
|
@ -56,19 +57,15 @@
|
||||||
<Reference Include="Telerik.JustMock.Silverlight">
|
<Reference Include="Telerik.JustMock.Silverlight">
|
||||||
<HintPath>..\libs\Telerik.JustMock.Silverlight.dll</HintPath>
|
<HintPath>..\libs\Telerik.JustMock.Silverlight.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="xunit, Version=1.6.1.1521, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
|
|
||||||
<SpecificVersion>False</SpecificVersion>
|
|
||||||
<HintPath>..\libs\xunit.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Framework\ValidationTests.cs" />
|
<Compile Include="Framework\When_validating_forms_with_validation_errors.cs" />
|
||||||
<Compile Include="Presenters\EditPortfolioTests.cs" />
|
<Compile Include="Presenters\EditPortfolioTests.cs" />
|
||||||
<Compile Include="Presenters\EditPositionTests.cs" />
|
<Compile Include="Presenters\EditPositionTests.cs" />
|
||||||
<Compile Include="Presenters\MainPresenterTests.cs" />
|
<Compile Include="Presenters\MainPresenterTests.cs" />
|
||||||
<Compile Include="Presenters\PortfolioPresenterTests.cs" />
|
<Compile Include="Presenters\PortfolioPresenterTests.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="YahooStockDataProviderTests.cs" />
|
<Compile Include="Services\YahooStockDataServiceTests.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\MonoStockPortfolio.Core\MonoStockPortfolio.Core.csproj">
|
<ProjectReference Include="..\MonoStockPortfolio.Core\MonoStockPortfolio.Core.csproj">
|
||||||
|
|
|
@ -5,6 +5,7 @@ using MonoStockPortfolio.Activites.EditPortfolioScreen;
|
||||||
using MonoStockPortfolio.Core.PortfolioRepositories;
|
using MonoStockPortfolio.Core.PortfolioRepositories;
|
||||||
using MonoStockPortfolio.Entities;
|
using MonoStockPortfolio.Entities;
|
||||||
using Telerik.JustMock;
|
using Telerik.JustMock;
|
||||||
|
using Telerik.JustMock.Helpers;
|
||||||
|
|
||||||
namespace MonoStockPortfolio.Tests.Presenters
|
namespace MonoStockPortfolio.Tests.Presenters
|
||||||
{
|
{
|
||||||
|
|
|
@ -8,6 +8,7 @@ using MonoStockPortfolio.Core.PortfolioRepositories;
|
||||||
using MonoStockPortfolio.Core.StockData;
|
using MonoStockPortfolio.Core.StockData;
|
||||||
using MonoStockPortfolio.Entities;
|
using MonoStockPortfolio.Entities;
|
||||||
using Telerik.JustMock;
|
using Telerik.JustMock;
|
||||||
|
using Telerik.JustMock.Helpers;
|
||||||
|
|
||||||
namespace MonoStockPortfolio.Tests.Presenters
|
namespace MonoStockPortfolio.Tests.Presenters
|
||||||
{
|
{
|
||||||
|
|
|
@ -5,7 +5,7 @@ using MonoStockPortfolio.Activites.MainScreen;
|
||||||
using MonoStockPortfolio.Core.PortfolioRepositories;
|
using MonoStockPortfolio.Core.PortfolioRepositories;
|
||||||
using MonoStockPortfolio.Entities;
|
using MonoStockPortfolio.Entities;
|
||||||
using Telerik.JustMock;
|
using Telerik.JustMock;
|
||||||
using Xunit;
|
using Telerik.JustMock.Helpers;
|
||||||
|
|
||||||
namespace MonoStockPortfolio.Tests.Activities
|
namespace MonoStockPortfolio.Tests.Activities
|
||||||
{
|
{
|
||||||
|
|
|
@ -8,6 +8,7 @@ using MonoStockPortfolio.Core.Services;
|
||||||
using MonoStockPortfolio.Entities;
|
using MonoStockPortfolio.Entities;
|
||||||
using MonoStockPortfolio.Framework;
|
using MonoStockPortfolio.Framework;
|
||||||
using Telerik.JustMock;
|
using Telerik.JustMock;
|
||||||
|
using Telerik.JustMock.Helpers;
|
||||||
|
|
||||||
namespace MonoStockPortfolio.Tests.Presenters
|
namespace MonoStockPortfolio.Tests.Presenters
|
||||||
{
|
{
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Machine.Specifications;
|
||||||
|
using Machine.Specifications.Runner.Impl;
|
||||||
|
using MonoStockPortfolio.Core.StockData;
|
||||||
|
using MonoStockPortfolio.Entities;
|
||||||
|
|
||||||
|
namespace MonoStockPortfolio.Tests.Services
|
||||||
|
{
|
||||||
|
public class When_using_the_Yahoo_stock_data_service_to_get_quotes
|
||||||
|
{
|
||||||
|
static YahooStockDataProvider _svc;
|
||||||
|
static IList<StockQuote> _quotes;
|
||||||
|
|
||||||
|
Establish context = () =>
|
||||||
|
{
|
||||||
|
_svc = new YahooStockDataProvider();
|
||||||
|
};
|
||||||
|
|
||||||
|
Because of = () =>
|
||||||
|
{
|
||||||
|
_quotes = _svc.GetStockQuotes(new[] { "GOOG", "AMZN", "AAPL", "MSFT", "NOVL", "S", "VZ", "T" })
|
||||||
|
.ToList();
|
||||||
|
};
|
||||||
|
|
||||||
|
It should_get_volumes_from_the_web = () =>
|
||||||
|
_quotes.ForEach(q => string.IsNullOrEmpty(q.Volume).ShouldBeFalse());
|
||||||
|
It should_get_last_trade_prices_from_the_web = () =>
|
||||||
|
_quotes.ForEach(q => q.LastTradePrice.ShouldNotEqual(0.0M));
|
||||||
|
It should_get_price_change_from_the_web = () =>
|
||||||
|
_quotes.ForEach(q => q.Change.ShouldNotEqual(0.0M));
|
||||||
|
}
|
||||||
|
|
||||||
|
public class When_using_the_Yahoo_stock_data_service_to_validate_tickers
|
||||||
|
{
|
||||||
|
static YahooStockDataProvider _svc;
|
||||||
|
static bool _goodTicker;
|
||||||
|
static bool _badTicker;
|
||||||
|
|
||||||
|
Establish context = () =>
|
||||||
|
{
|
||||||
|
_svc = new YahooStockDataProvider();
|
||||||
|
};
|
||||||
|
|
||||||
|
Because of = () =>
|
||||||
|
{
|
||||||
|
_goodTicker = _svc.IsValidTicker("GOOG");
|
||||||
|
_badTicker = _svc.IsValidTicker("GOOGAMOOGA");
|
||||||
|
};
|
||||||
|
|
||||||
|
It should_validate_the_good_ticker = () =>
|
||||||
|
_goodTicker.ShouldBeTrue();
|
||||||
|
It shouldnt_validate_the_bad_ticker = () =>
|
||||||
|
_badTicker.ShouldBeFalse();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,109 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using MonoStockPortfolio.Core.PortfolioRepositories;
|
|
||||||
using MonoStockPortfolio.Core.Services;
|
|
||||||
using MonoStockPortfolio.Core.StockData;
|
|
||||||
using MonoStockPortfolio.Entities;
|
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace MonoStockPortfolio.Tests
|
|
||||||
{
|
|
||||||
public class YahooStockDataProviderTests
|
|
||||||
{
|
|
||||||
[Fact]
|
|
||||||
public void Can_get_volume_from_web()
|
|
||||||
{
|
|
||||||
var svc = new YahooStockDataProvider();
|
|
||||||
var quotes = svc.GetStockQuotes(new[] {"GOOG", "AMZN", "AAPL", "MSFT", "NOVL", "S", "VZ", "T"});
|
|
||||||
foreach (var stockQuote in quotes)
|
|
||||||
{
|
|
||||||
Assert.True(!string.IsNullOrEmpty(stockQuote.Volume));
|
|
||||||
}
|
|
||||||
Assert.True(quotes.Any());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void Can_get_volume_from_service()
|
|
||||||
{
|
|
||||||
var svc = new PortfolioService(BuildStubPortfolioRepo(), new YahooStockDataProvider());
|
|
||||||
var items = svc.GetDetailedItems(1, new List<StockDataItem> {StockDataItem.Ticker, StockDataItem.Volume});
|
|
||||||
foreach (var positionResultsViewModel in items)
|
|
||||||
{
|
|
||||||
Assert.True(positionResultsViewModel.Items[StockDataItem.Volume] != null);
|
|
||||||
}
|
|
||||||
Assert.True(items.Any());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void Can_tell_if_a_ticker_is_valid()
|
|
||||||
{
|
|
||||||
var svc = new YahooStockDataProvider();
|
|
||||||
Assert.True(svc.IsValidTicker("GOOG"));
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void Can_tell_if_a_ticker_is_invalid()
|
|
||||||
{
|
|
||||||
var svc = new YahooStockDataProvider();
|
|
||||||
Assert.False(svc.IsValidTicker("HARBLHARBLHARBL"));
|
|
||||||
}
|
|
||||||
|
|
||||||
private IPortfolioRepository BuildStubPortfolioRepo()
|
|
||||||
{
|
|
||||||
return new StubPortfolioRepo();
|
|
||||||
}
|
|
||||||
|
|
||||||
public class StubPortfolioRepo : IPortfolioRepository
|
|
||||||
{
|
|
||||||
public IList<Position> GetAllPositions(long portfolioId)
|
|
||||||
{
|
|
||||||
return new List<Position>
|
|
||||||
{
|
|
||||||
new Position(1)
|
|
||||||
{ContainingPortfolioID = 1, PricePerShare = 5, Shares = 100, Ticker = "GOOG"}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public IList<Portfolio> GetAllPortfolios()
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SavePortfolio(Portfolio portfolio)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void DeletePortfolioById(int portfolioId)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Portfolio GetPortfolioById(long portfolioId)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Portfolio GetPortfolioByName(string portfolioName)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SavePosition(Position position)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void DeletePositionById(long positionId)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Position GetPositionById(long positionId)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -6,6 +6,7 @@ EndProject
|
||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "libs", "libs", "{643BA3D4-E3D6-49B7-B347-2B935FD5B9FC}"
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "libs", "libs", "{643BA3D4-E3D6-49B7-B347-2B935FD5B9FC}"
|
||||||
ProjectSection(SolutionItems) = preProject
|
ProjectSection(SolutionItems) = preProject
|
||||||
libs\PostSharp.SL.dll = libs\PostSharp.SL.dll
|
libs\PostSharp.SL.dll = libs\PostSharp.SL.dll
|
||||||
|
libs\Telerik.JustMock.Silverlight.dll = libs\Telerik.JustMock.Silverlight.dll
|
||||||
EndProjectSection
|
EndProjectSection
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MonoStockPortfolio.Core", "MonoStockPortfolio.Core\MonoStockPortfolio.Core.csproj", "{251E7BB4-CFE2-4DE4-9E2A-AAE1AF41C8CB}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MonoStockPortfolio.Core", "MonoStockPortfolio.Core\MonoStockPortfolio.Core.csproj", "{251E7BB4-CFE2-4DE4-9E2A-AAE1AF41C8CB}"
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// <auto-generated>
|
// <auto-generated>
|
||||||
// This code was generated by a tool.
|
// This code was generated by a tool.
|
||||||
// Runtime Version:2.0.50727.4952
|
// Runtime Version:2.0.50727.5420
|
||||||
//
|
//
|
||||||
// Changes to this file may cause incorrect behavior and will be lost if
|
// Changes to this file may cause incorrect behavior and will be lost if
|
||||||
// the code is regenerated.
|
// the code is regenerated.
|
||||||
|
|
Loading…
Reference in a new issue