Skip to content

Instantly share code, notes, and snippets.

@robashton
Created July 7, 2011 12:40
Show Gist options
  • Select an option

  • Save robashton/1069421 to your computer and use it in GitHub Desktop.

Select an option

Save robashton/1069421 to your computer and use it in GitHub Desktop.
An example for @grumpydev
[TestFixture]
public class When_the_selection_manager_has_its_search_results_updated
{
private FakeSearchService searchService;
private SelectionManager selectionManager;
[TestFixtureSetUp]
public void ArrangeAndAct()
{
searchService = new FakeSearchService()
{
SelectableItemsResult = new[]
{
new SelectableItem()
{Id = "One", Selected = false},
new SelectableItem()
{Id = "Two", Selected = false},
new SelectableItem()
{Id = "Three", Selected = false}
};
};
selectionManager = new SelectionManager(searchService)
{
SelectableItems = new[]
{
new SelectableItem() {Id = "One", Selected = true},
new SelectableItem() {Id = "Four", Selected = true},
new SelectableItem() {Id = "Five", Selected = false}
};
};
selectionManager.PerformAdditionalSearch("searchTerm");
}
[Test]
public void Items_which_are_selected_in_both_lists_are_selected_in_the_merged_output()
{
var item = selectionManager.SelectableItems
.Where(x => x.Id == "One")
.Single();
Assert.That(item.Selected);
}
[Test]
public void Items_only_present_in_the_search_results_appear_unselected_in_the_merged_output()
{
var item = selectionManager.SelectableItems
.Where(x => x.Id == "Two")
.Single();
Assert.That(item.Selected, Is.False);
}
[Test]
public void Items_which_are_selected_in_the_current_list_without_being_present_in_the_returned_list_are_kept_selected_in_the_current_list()
{
var item = selectionManager.SelectableItems
.Where(x => x.Id == "Four")
.Single();
Assert.That(item.Selected);
}
[Test]
public void Items_which_are_not_selected_in_the_current_list_without_being_present_in_the_returned_list_are_removed_from_the_current_list()
{
var item = selectionManager.SelectableItems
.Where(x => x.Id == "Five")
.FirstOrDefault();
Assert.That(item, Is.Null);
}
}
[TestFixture]
public class When_the_selection_manager_has_its_search_results_updated2
{
private FakeSearchService searchService;
private SelectionManager selectionManager;
private const string ItemPresentInBothLists = "One";
private const string ItemOnlyPresentInSearchResults = "Two";
private const string AlreadySelectedItem = "Four";
private const string UnselectedItem = "Five";
[TestFixtureSetUp]
public void ArrangeAndAct()
{
searchService = new FakeSearchServiceBuilder()
.WithUnselectedItem(ItemPresentInBothLists)
.WithUnselectedItem(ItemOnlyPresentInSearchResults)
.Get();
selectionManager = new SelectionManagerBuilder()
.UsingSearchService(searchService)
.WithSelectedItem(ItemPresentInBothLists)
.WithSelectedItem(AlreadySelectedItem)
.WithUnselectedItem(UnselectedItem)
.Get();
selectionManager.PerformAdditionalSearch("searchTerm");
}
[Test]
public void Items_which_are_selected_in_both_lists_are_selected_in_the_merged_output()
{
Assert.That(selectionManager.HasSelectedItemWithId(ItemPresentInBothLists));
}
[Test]
public void Items_only_present_in_the_search_results_appear_unselected_in_the_merged_output()
{
Assert.That(selectionManager.HasUnselectedItemWithId(ItemOnlyPresentInSearchResults));
}
[Test]
public void Items_which_are_selected_in_the_current_list_without_being_present_in_the_returned_list_are_kept_selected_in_the_current_list()
{
Assert.That(selectionManager.HasSelectedItemWithId(AlreadySelectedItem));
}
[Test]
public void Items_which_are_not_selected_in_the_current_list_without_being_present_in_the_returned_list_are_removed_from_the_current_list()
{
Assert.That(selectionManager.DoesNotHaveItemWithId(UnselectedItem));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment