Skip to content
This repository has been archived by the owner on Oct 16, 2019. It is now read-only.

Commit

Permalink
Merge branch 'release/0.8'
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSylence committed Oct 17, 2016
2 parents 0b1fac3 + 5541cfb commit 3b8bd9a
Show file tree
Hide file tree
Showing 83 changed files with 997 additions and 408 deletions.
1 change: 1 addition & 0 deletions Twice.Tests/Models/Cache/SqliteCacheTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public async Task CachingEmptyHashtagListDoesNothing()
using( var cache = new SqliteCache( con ) )
{
// Act
// ReSharper disable once AccessToDisposedClosure
var ex = await ExceptionAssert.CatchAsync<Exception>( () => cache.AddHashtags( new List<string>() ) );

// Assert
Expand Down
13 changes: 7 additions & 6 deletions Twice.Tests/Models/Proxy/MediaProxyServerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public async Task DataIsCorrectlyWrittenToResponse()
responseMsg.Content.Headers.ContentLength = 4;

var client = new Mock<IHttpClient>();
client.Setup( c => c.GetAsync( new Uri( "https://example.com" ) ) ).Returns( Task.FromResult( responseMsg ) );
client.Setup( c => c.GetAsync( new Uri( "https://example.com" ), null ) ).Returns( Task.FromResult( responseMsg ) );
var proxy = new MediaProxyServer( client.Object );

var request = new Mock<IHttpRequest>();
Expand Down Expand Up @@ -84,7 +84,7 @@ public async Task MissingQueryParameterIsIgnored()
{
// Arrange
var client = new Mock<IHttpClient>();
client.Setup( c => c.GetAsync( It.IsAny<Uri>() ) ).Verifiable();
client.Setup( c => c.GetAsync( It.IsAny<Uri>(), null ) ).Verifiable();
var proxy = new MediaProxyServer( client.Object );

var request = new Mock<IHttpRequest>();
Expand All @@ -97,7 +97,7 @@ public async Task MissingQueryParameterIsIgnored()
await proxy.HandleRequest( request.Object, response.Object );

// Assert
client.Verify( c => c.GetAsync( It.IsAny<Uri>() ), Times.Never() );
client.Verify( c => c.GetAsync( It.IsAny<Uri>(), null ), Times.Never() );
}

[TestMethod, TestCategory( "Models.Proxy" )]
Expand All @@ -106,12 +106,13 @@ public async Task NotFoundIsPropagatedCorrectly()
// Arrange
var responseMsg = new HttpResponseMessage( HttpStatusCode.NotFound );
var client = new Mock<IHttpClient>();
client.Setup( c => c.GetAsync( new Uri( "https://example.com" ) ) ).Returns( Task.FromResult( responseMsg ) );
client.Setup( c => c.GetAsync( new Uri( "https://example.com" ), null ) ).Returns( Task.FromResult( responseMsg ) );

var proxy = new MediaProxyServer( client.Object );

var request = new Mock<IHttpRequest>();
request.Setup( c => c.GetQueryParameter( "stream" ) ).Returns( "https://example.com" );
request.Setup( c => c.GetQueryParameter( "user" ) ).Returns( string.Empty );

var response = new Mock<IHttpResponse>();
response.Setup( c => c.SetStatus( 404, It.IsAny<string>() ) ).Verifiable();
Expand All @@ -135,7 +136,7 @@ public void StartingAddsPrefix()
// Act
try
{
proxy.Start();
proxy.Start( null );
}
finally
{
Expand All @@ -157,7 +158,7 @@ public void StartingStartsListener()
// Act
try
{
proxy.Start();
proxy.Start( null );
}
finally
{
Expand Down
11 changes: 7 additions & 4 deletions Twice.Tests/Models/Scheduling/SchedulerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ public void JobIsExecutedInThread()
var scheduler = new Scheduler( "SchedulerTests.JobIsExecutedInThread.json", contextList.Object, config.Object,
proc.Object, 20 );
scheduler.Start();
bool set;

try
{
var job = new SchedulerJob
Expand All @@ -110,16 +112,17 @@ public void JobIsExecutedInThread()
scheduler.AddJob( job );

// Act
bool set = waitHandle.Wait( 2000 );
set = waitHandle.Wait( 2000 );

// Assert
Assert.IsTrue( set );
proc.Verify( p => p.Process( It.IsAny<SchedulerJob>() ), Times.Once() );
}
finally
{
scheduler.Stop();
}

// Assert
Assert.IsTrue( set );
proc.Verify( p => p.Process( It.IsAny<SchedulerJob>() ), Times.Once() );
}

[TestMethod, TestCategory( "Models.Scheduling" )]
Expand Down
112 changes: 31 additions & 81 deletions Twice.Tests/Models/Twitter/Streaming/StreamParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,7 @@ public async Task KeepAliveMessageIsIgnored()
{
// Arrange
const string strContent = "";
var execute = new Mock<ITwitterExecute>();
StreamContent content = new StreamContent( execute.Object, strContent );

var stream = new Mock<IStreamingConnection>();
stream.Setup( s => s.Start( It.IsAny<Func<IStreamContent, Task>>() ) )
.Callback<Func<StreamContent, Task>>( func => func( content ) )
.Returns( Task.FromResult( new List<IStreaming>() ) );

var parser = StreamParser.Create( stream.Object, null );
var parser = SetupParser( strContent );

// Act
parser.StartStreaming();
Expand All @@ -70,17 +62,10 @@ public void ReceivingFavoriteRaisesEvent()
// Arrange
const string strContent =
"{ \"event\":\"favorite\", \"created_at\": \"Sat Sep 04 16:10:54 +0000 2010\", \"target\": { \"id\": 123 }, \"source\": { \"id\": 456 }, \"target_object\": { \"created_at\": \"Wed Jun 06 20:07:10 +0000 2012\", \"id_str\": \"210462857140252672\" } }";
var execute = new Mock<ITwitterExecute>();
StreamContent content = new StreamContent( execute.Object, strContent );

var stream = new Mock<IStreamingConnection>();
stream.Setup( s => s.Start( It.IsAny<Func<IStreamContent, Task>>() ) )
.Callback<Func<StreamContent, Task>>( func => func( content ) )
.Returns( Task.FromResult( new List<IStreaming>() ) );

var parser = StreamParser.Create( stream.Object, null );
EventStreamEventArgs receivedData = null;
ManualResetEventSlim waitHandle = new ManualResetEventSlim( false );
var parser = SetupParser( strContent );
EventStreamEventArgs receivedData = null;

parser.FavoriteEventReceived += ( s, e ) =>
{
Expand All @@ -104,17 +89,10 @@ public void ReceivingFriendlistRaisesEvent()
{
// Arrange
const string strContent = "{\"friends\":[123,456,789]}";
var execute = new Mock<ITwitterExecute>();
StreamContent content = new StreamContent( execute.Object, strContent );

var stream = new Mock<IStreamingConnection>();
stream.Setup( s => s.Start( It.IsAny<Func<IStreamContent, Task>>() ) )
.Callback<Func<StreamContent, Task>>( func => func( content ) )
.Returns( Task.FromResult( new List<IStreaming>() ) );

var parser = StreamParser.Create( stream.Object, null );
FriendsStreamEventArgs receivedData = null;
ManualResetEventSlim waitHandle = new ManualResetEventSlim( false );
var parser = SetupParser( strContent );
FriendsStreamEventArgs receivedData = null;

parser.FriendsReceived += ( s, e ) =>
{
Expand All @@ -137,17 +115,10 @@ public void ReceivingMessageDeleteRaisesEvent()
// Arrange
const string strContent =
"{\"delete\":{\"direct_message\":{\"id\":1234,\"id_str\":\"1234\",\"user_id\":3,\"user_id_str\":\"3\"}}}";
var execute = new Mock<ITwitterExecute>();
StreamContent content = new StreamContent( execute.Object, strContent );

var stream = new Mock<IStreamingConnection>();
stream.Setup( s => s.Start( It.IsAny<Func<IStreamContent, Task>>() ) )
.Callback<Func<StreamContent, Task>>( func => func( content ) )
.Returns( Task.FromResult( new List<IStreaming>() ) );

var parser = StreamParser.Create( stream.Object, null );
DeleteStreamEventArgs receivedDelete = null;
ManualResetEventSlim waitHandle = new ManualResetEventSlim( false );
var parser = SetupParser( strContent );
DeleteStreamEventArgs receivedDelete = null;

parser.DirectMessageDeleted += ( s, e ) =>
{
Expand All @@ -170,17 +141,10 @@ public void ReceivingMessageRaisesEvent()
{
// Arrange
var strContent = File.ReadAllText( "Data/message.json" );
var execute = new Mock<ITwitterExecute>();
StreamContent content = new StreamContent( execute.Object, strContent );

var stream = new Mock<IStreamingConnection>();
stream.Setup( s => s.Start( It.IsAny<Func<IStreamContent, Task>>() ) )
.Callback<Func<StreamContent, Task>>( func => func( content ) )
.Returns( Task.FromResult( new List<IStreaming>() ) );

var parser = StreamParser.Create( stream.Object, null );
DirectMessageStreamEventArgs receivedData = null;
ManualResetEventSlim waitHandle = new ManualResetEventSlim( false );
var parser = SetupParser( strContent );
DirectMessageStreamEventArgs receivedData = null;

parser.DirectMessageReceived += ( s, e ) =>
{
Expand All @@ -202,17 +166,10 @@ public void ReceivingStatusDeleteRaisesEvent()
{
// Arrange
const string strContent = "{\"delete\":{\"status\":{\"id\":1234,\"id_str\":\"1234\",\"user_id\":3,\"user_id_str\":\"3\"}}}";
var execute = new Mock<ITwitterExecute>();
StreamContent content = new StreamContent( execute.Object, strContent );

var stream = new Mock<IStreamingConnection>();
stream.Setup( s => s.Start( It.IsAny<Func<IStreamContent, Task>>() ) )
.Callback<Func<StreamContent, Task>>( func => func( content ) )
.Returns( Task.FromResult( new List<IStreaming>() ) );

var parser = StreamParser.Create( stream.Object, null );
DeleteStreamEventArgs receivedDelete = null;
ManualResetEventSlim waitHandle = new ManualResetEventSlim( false );
var parser = SetupParser( strContent );
DeleteStreamEventArgs receivedDelete = null;

parser.StatusDeleted += ( s, e ) =>
{
Expand All @@ -235,17 +192,10 @@ public void ReceivingStatusRaisesEvent()
{
// Arrange
var strContent = File.ReadAllText( "Data/tweet.json" );
var execute = new Mock<ITwitterExecute>();
StreamContent content = new StreamContent( execute.Object, strContent );

var stream = new Mock<IStreamingConnection>();
stream.Setup( s => s.Start( It.IsAny<Func<IStreamContent, Task>>() ) )
.Callback<Func<StreamContent, Task>>( func => func( content ) )
.Returns( Task.FromResult( new List<IStreaming>() ) );

var parser = StreamParser.Create( stream.Object, null );
StatusStreamEventArgs receivedData = null;
ManualResetEventSlim waitHandle = new ManualResetEventSlim( false );
var parser = SetupParser( strContent );
StatusStreamEventArgs receivedData = null;

parser.StatusReceived += ( s, e ) =>
{
Expand All @@ -267,17 +217,10 @@ public void ReceivingUnknownDataRaisesEvent()
{
// Arrange
const string strContent = "{\"test\":[1,2,3]}";
var execute = new Mock<ITwitterExecute>();
StreamContent content = new StreamContent( execute.Object, strContent );

var stream = new Mock<IStreamingConnection>();
stream.Setup( s => s.Start( It.IsAny<Func<IStreamContent, Task>>() ) )
.Callback<Func<StreamContent, Task>>( func => func( content ) )
.Returns( Task.FromResult( new List<IStreaming>() ) );

var parser = StreamParser.Create( stream.Object, null );
StreamEventArgs receivedData = null;
ManualResetEventSlim waitHandle = new ManualResetEventSlim( false );
var parser = SetupParser( strContent );
StreamEventArgs receivedData = null;

parser.UnknownDataReceived += ( s, e ) =>
{
Expand All @@ -300,17 +243,10 @@ public void ReceivingUnkownDataRaisesEvent()
// Arrange
const string strContent =
"{ \"event\":\"unknown\", \"created_at\": \"Sat Sep 04 16:10:54 +0000 2010\", \"target\": { \"id\": 123 }, \"source\": { \"id\": 456 }, \"target_object\": { \"created_at\": \"Wed Jun 06 20:07:10 +0000 2012\", \"id_str\": \"210462857140252672\" } }";
var execute = new Mock<ITwitterExecute>();
StreamContent content = new StreamContent( execute.Object, strContent );

var stream = new Mock<IStreamingConnection>();
stream.Setup( s => s.Start( It.IsAny<Func<IStreamContent, Task>>() ) )
.Callback<Func<StreamContent, Task>>( func => func( content ) )
.Returns( Task.FromResult( new List<IStreaming>() ) );

var parser = StreamParser.Create( stream.Object, null );
EventStreamEventArgs receivedData = null;
ManualResetEventSlim waitHandle = new ManualResetEventSlim( false );
var parser = SetupParser( strContent );
EventStreamEventArgs receivedData = null;

parser.UnknownEventReceived += ( s, e ) =>
{
Expand Down Expand Up @@ -356,5 +292,19 @@ public void StreamParserCanBeCreated()
// Assert
Assert.IsNotNull( parser );
}

private static StreamParser SetupParser( string strContent )
{
var execute = new Mock<ITwitterExecute>();
StreamContent content = new StreamContent( execute.Object, strContent );

var stream = new Mock<IStreamingConnection>();
stream.Setup( s => s.Start( It.IsAny<Func<IStreamContent, Task>>() ) )
.Callback<Func<StreamContent, Task>>( func => func( content ) )
.Returns( Task.FromResult( new List<IStreaming>() ) );

var parser = StreamParser.Create( stream.Object, null );
return parser;
}
}
}
2 changes: 1 addition & 1 deletion Twice.Tests/Models/Twitter/TweetHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Twice.Tests.Models.Twitter
{
[TestClass]
internal class TweetHelperTests
public class TweetHelperTests
{
}
}
14 changes: 7 additions & 7 deletions Twice.Tests/Twice.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<Private>True</Private>
</Reference>
<Reference Include="GongSolutions.Wpf.DragDrop, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\gong-wpf-dragdrop.1.0.0-ALPHA017\lib\net40\GongSolutions.Wpf.DragDrop.dll</HintPath>
<HintPath>..\packages\gong-wpf-dragdrop.1.0.0\lib\net46\GongSolutions.Wpf.DragDrop.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="ICSharpCode.SharpZipLib, Version=0.86.0.518, Culture=neutral, processorArchitecture=MSIL">
Expand Down Expand Up @@ -110,8 +110,8 @@
<HintPath>..\packages\Mono.Cecil.0.9.6.4\lib\net45\Mono.Cecil.Rocks.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Moq, Version=4.5.21.0, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<HintPath>..\packages\Moq.4.5.21\lib\net45\Moq.dll</HintPath>
<Reference Include="Moq, Version=4.5.23.0, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<HintPath>..\packages\Moq.4.5.23\lib\net45\Moq.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
Expand All @@ -138,8 +138,8 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Data.SQLite, Version=1.0.102.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
<HintPath>..\packages\System.Data.SQLite.Core.1.0.102.0\lib\net46\System.Data.SQLite.dll</HintPath>
<Reference Include="System.Data.SQLite, Version=1.0.103.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
<HintPath>..\packages\System.Data.SQLite.Core.1.0.103\lib\net46\System.Data.SQLite.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Net.Http" />
Expand Down Expand Up @@ -372,12 +372,12 @@
</Choose>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\System.Data.SQLite.Core.1.0.102.0\build\net46\System.Data.SQLite.Core.targets" Condition="Exists('..\packages\System.Data.SQLite.Core.1.0.102.0\build\net46\System.Data.SQLite.Core.targets')" />
<Import Project="..\packages\System.Data.SQLite.Core.1.0.103\build\net46\System.Data.SQLite.Core.targets" Condition="Exists('..\packages\System.Data.SQLite.Core.1.0.103\build\net46\System.Data.SQLite.Core.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\System.Data.SQLite.Core.1.0.102.0\build\net46\System.Data.SQLite.Core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\System.Data.SQLite.Core.1.0.102.0\build\net46\System.Data.SQLite.Core.targets'))" />
<Error Condition="!Exists('..\packages\System.Data.SQLite.Core.1.0.103\build\net46\System.Data.SQLite.Core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\System.Data.SQLite.Core.1.0.103\build\net46\System.Data.SQLite.Core.targets'))" />
</Target>
<!-- 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void CorrectAccountsAreListed()
var contextList = new Mock<ITwitterContextList>();
contextList.SetupGet( c => c.Contexts ).Returns( contexts );

var vm = new SourceAccountSelectorPage( wizard.Object, contextList.Object );
var vm = new SourceAccountSelectorPage( wizard.Object, contextList.Object, false );

// Act
var userIds = vm.Accounts.Select( c => c.Context.UserId ).ToArray();
Expand Down
Loading

0 comments on commit 3b8bd9a

Please sign in to comment.