public void when_try_to_remove_thing_not_stored_in_pocket_it_should_leave_pocket_content_unchanged_and_return_fail_status() { var sut = new ConcurrentPocket(); const string nameOfThing = "name of the thing"; const string thingItself = "the thing itself"; sut.Put(nameOfThing, thingItself); sut.TryRemove("a different name").Should().BeFalse("a thing with such name not stored in the pocket"); sut.GetThings().Count.Should().Be(expected: 1, "number of things should be the same"); sut.GetThings()[nameOfThing].Should().BeSameAs(thingItself, "the pocket content should stay the same"); }
public void when_put_thing_with_same_name_as_already_present_it_should_replace_it() { var sut = new ConcurrentPocket(); const string nameOfThing = "name of the thing"; var secondThing = DateTime.Now; sut.Put(nameOfThing, "first thing") .Put(nameOfThing, secondThing); sut.GetThings().Count.Should().Be(expected: 1, "same name means to replace the stored thing"); sut.GetThings()[nameOfThing].Should().Be(secondThing, "the thing should be replaced"); }
public void when_put_struct_thing_with_accepted_name_it_should_be_found_in_the_pocket() { var sut = new ConcurrentPocket(); const string nameOfThing = "name of the thing"; var thingItself = DateTime.Now; var pocket = sut.Put(nameOfThing, thingItself); pocket.Should().BeSameAs(sut, "returned pocket should stay the same"); sut.GetThings()[nameOfThing].Should().Be(thingItself, "thing should be stored"); }
public void when_try_to_remove_stored_thing_it_should_remove_it_and_return_success_status() { var sut = new ConcurrentPocket(); const string nameOfThing = "name of the thing"; const string thingItself = "the thing itself"; sut.Put(nameOfThing, thingItself); sut.TryRemove(nameOfThing).Should().BeTrue("thing was removed from the pocket"); sut.GetThings().Count.Should().Be(expected: 0, "the pocket is empty"); }
public void when_take_or_put_thing_from_empty_pocket_it_should_make_thing_put_it_into_pocket_and_return_it() { var sut = new ConcurrentPocket(); const string nameOfThing = "name of the thing"; const string thingItself = "the thing itself"; var isFactoryCalled = false; Func <string> thingFactory = () => { isFactoryCalled = true; return(thingItself); }; var thing = sut.TakeOrPut(nameOfThing, thingFactory); sut.GetThings().Count.Should().Be(expected: 1, "the made thing should be stored in the pocket"); isFactoryCalled.Should().BeTrue("it was an empty pocket and the thing should be made from scratch"); thing.Should().BeSameAs(thingItself, "exactly this thing was made"); }
public void when_try_get_things_from_empty_pocket_it_should_return_nothing() { var sut = new ConcurrentPocket(); sut.GetThings().Count.Should().Be(expected: 0, "no any thing in the pocket"); }