Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Test.TwitterFriendsSearcher.Shared/ControlCenter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Test.TwitterFriendsSearcher.Shared
{
public class ControlCenter
{
public int X { get; set; }
public int Y { get; set; }
}
}
36 changes: 36 additions & 0 deletions Test.TwitterFriendsSearcher.Shared/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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("Test.TwitterFriendsSearcher.Shared")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("Test.TwitterFriendsSearcher.Shared")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2011")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("905010fd-6c58-423b-bdba-701607839963")]

// 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")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?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>{D0AAAA20-2694-4AFD-A53D-1A701C5D6544}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Test.TwitterFriendsSearcher.Shared</RootNamespace>
<AssemblyName>Test.TwitterFriendsSearcher.Shared</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<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="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ControlCenter.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.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>
25 changes: 25 additions & 0 deletions Test.TwitterFriendsSearcher/Bootstrapping/BootstrapperTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using StructureMap;
using TwitterFriendsSearcher.Bootstrapping;
using TwitterFriendsSearcher.FollowAlgorithm;

namespace Test.TwitterFriendsSearcher.Bootstrapping
{
[TestClass]
public class BootstrapperTest
{

[TestMethod]
public void should_wire_IncreaseFollowersServices_dependencies()
{
new ApplicationBootstrapper().Bootstrap();

var increaseFollowersService = ObjectFactory.GetInstance<IncreaseFollowersService>();

var searchExecutor = ObjectFactory.GetInstance<ISearchExecutor>();

Assert.IsNotNull(increaseFollowersService);
}

}
}
76 changes: 58 additions & 18 deletions Test.TwitterFriendsSearcher/EndToEnd/ApplicationRunner.cs
Original file line number Diff line number Diff line change
@@ -1,47 +1,87 @@
using System;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Windows;
using Test.TwitterFriendsSearcher.TwitterFriendsSearcherUiProvider;
using TwitterFriendsSearcher;
using TwitterFriendsSearcher.Twitter;
using White.Core;
using White.Core.InputDevices;
using White.Core.UIItems;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using White.Core.UIItems.WindowItems;

namespace Test.TwitterFriendsSearcher.EndToEnd
{
public class ApplicationRunner
{

private Application application;
private Keyboard keyboard;
private Mouse mouse;
private Process twitterFriendsSearcherProccess;

public void Tweet(ITwitterWrapper twitterWrapper, string tweet)
public void Launch()
{
new Thread(() =>
{
Program.TwitterWrapper = twitterWrapper;
Program.Main(tweet);
}).Start();
keyboard = Keyboard.Instance;
mouse = Mouse.Instance;

Thread.Sleep(1000);
LaunchTwitterFriendsSearcherAndHostTheService();

var currentProcess = Process.GetCurrentProcess();
application = Application.Attach(currentProcess.Id);
twitterFriendsSearcherProccess = Process.GetProcessesByName("TwitterFriendsSearcher.Runner")[0];

application = Application.Attach(twitterFriendsSearcherProccess.Id);
}

private void LaunchTwitterFriendsSearcherAndHostTheService()
{
Process.Start(@"..\..\..\..\..\TwitterFriendsSearcher.Runner\bin\Debug\TwitterFriendsSearcher.Runner.exe");

// give it a chance to run and host a service
Thread.Sleep(10000);
}

public void EnterKeywords(string keywords)
{
using (var serviceClient = new TwitterFriendsSearcherUiInfoProviderClient())
{
var center = serviceClient.GetTextBoxCenterByName("tbKeywords");
mouse.Click(new Point(center.X, center.Y));
}

keyboard.Enter(keywords);
}

public void ClickButton(string buttonName)
{
using(var serviceClient = new TwitterFriendsSearcherUiInfoProviderClient())
{
var center = serviceClient.GetButtonCenterByName(buttonName);
mouse.Location = new Point(center.X, center.Y);
mouse.Click();
}
}

public void ReadAndDisplayRecentTweet()
public bool DisplaysAtLeastOneFollowedUser()
{
if (Program.MainForm.InvokeRequired)
Program.MainForm.Invoke(new Action(() => Program.MainForm.ReadLatestTweet()));
else
Program.MainForm.ReadLatestTweet();
using(var serviceClient = new TwitterFriendsSearcherUiInfoProviderClient())
{
return serviceClient.GetListBoxInfo("lbUsersFollowedAtTheMoment").Items.Length > 0;
}
}

public void ShowsTweet(string tweet)
public void StopApplication()
{
var mainWindow = application.GetWindow("TwitterFriendsSearcher");
var label = mainWindow.Get<Label>("lblLastTweet");
application.Kill();
try
{
twitterFriendsSearcherProccess.Kill();
}
catch
{
}

Assert.AreEqual(tweet, label.Text);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,37 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Rhino.Mocks;
using StructureMap;
using Test.TwitterFriendsSearcher.TestHelpers;
using TwitterFriendsSearcher.Twitter;

namespace Test.TwitterFriendsSearcher.EndToEnd
{

[TestClass]
public class TwitterFriendsSearcherEndToEndTests
{

private ApplicationRunner applicationRunner = new ApplicationRunner();
private FakeTwitterWrapper twitterWrapper = new FakeTwitterWrapper();

[TestMethod]
public void should_tweet_then_fetch_and_display_the_tweet()
[TestInitialize]
public void SetUp()
{
const string testTweet = "Test tweet";
applicationRunner.Launch();
}

applicationRunner.Tweet(twitterWrapper, testTweet);
twitterWrapper.HasReceivedTweet(testTweet);
[TestCleanup]
public void TearDown()
{
applicationRunner.StopApplication();
}

applicationRunner.ReadAndDisplayRecentTweet();
twitterWrapper.HasBeenAskedForTheLastTweet();
[TestMethod]
public void should_display_the_user_returned_from_Twitter_when_entered_keywords_and_clicked_search()
{
applicationRunner.EnterKeywords("tdd course");
applicationRunner.ClickButton("btnStart");

applicationRunner.ShowsTweet(testTweet);
DelayedAssert.AreEqual(true, () => applicationRunner.DisplaysAtLeastOneFollowedUser());
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,45 @@ public class IncreaseFollowersServiceTest
public void should_grab_users_by_name_and_start_making_friends_process()
{
const string keywords = "TDD course";
var usersForKeywords = new List<int> {1, 2, 3};
var usersForKeywords = new List<int> { 1, 2, 3 };

var increaseFollowersService = new IncreaseFollowersService(makingFriendsService, usersSearcher);

usersSearcher.Stub(x => x.Find(keywords)).Return(usersForKeywords);

increaseFollowersService.IncreaseByKeywords(keywords);

makingFriendsService.AssertWasCalled(x => x.MakeFriendsWith(usersForKeywords));
}

[TestMethod]
public void should_raise_UserFollowed_when_user_is_followed()
{
const int userId = 3;

var increaseFollowersService = new IncreaseFollowersService(makingFriendsService, usersSearcher);

var isUserFollowedRaised = false;
increaseFollowersService.UserFollowed += (sender, args) => { isUserFollowedRaised = true; };

makingFriendsService.Raise(x => x.UserFollowed += null, this, new UserEventArgs(userId));

Assert.IsTrue(isUserFollowedRaised);
}

[TestMethod]
public void should_raise_UserUnfollowed_when_user_is_unfollowed()
{
const int userId = 3;

var increaseFollowersService = new IncreaseFollowersService(makingFriendsService, usersSearcher);

var isUserUnfollowedRaised = false;
increaseFollowersService.UserUnfollowed += (sender, args) => { isUserUnfollowedRaised = true; };

makingFriendsService.Raise(x => x.UserUnfollowed += null, this, new UserEventArgs(userId));

Assert.IsTrue(isUserUnfollowedRaised);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void should_follow_each_user_and_unfollow_them_when_making_friends()

var makingFriendsService = new MakingFriendsService(twitterWrapper);

makingFriendsService.StartMakingFriends(users);
makingFriendsService.MakeFriendsWith(users);

twitterWrapper.AssertWasCalled(x => x.Follow(1));
twitterWrapper.AssertWasCalled(x => x.Follow(2));
Expand All @@ -28,5 +28,37 @@ public void should_follow_each_user_and_unfollow_them_when_making_friends()
twitterWrapper.AssertWasCalled(x => x.Unfollow(2));
}

[TestMethod]
public void should_raise_UserFollowed_when_the_user_is_followed()
{
var users = new List<int> { 1 };

var makingFriendsService = new MakingFriendsService(twitterWrapper);

var isUserFollowedRaised = false;

makingFriendsService.UserFollowed += (sender, e) => { isUserFollowedRaised = true; };

makingFriendsService.MakeFriendsWith(users);

Assert.IsTrue(isUserFollowedRaised);
}

[TestMethod]
public void should_raise_UserUnfollowed_when_the_user_is_unfollowed()
{
var users = new List<int> { 1 };

var makingFriendsService = new MakingFriendsService(twitterWrapper);

var isUserUnfollowedRaised = false;

makingFriendsService.UserUnfollowed += (sender, e) => { isUserUnfollowedRaised = true; };

makingFriendsService.MakeFriendsWith(users);

Assert.IsTrue(isUserUnfollowedRaised);
}

}
}
Loading