Exemplo n.º 1
0
        public void when_take_or_throw_something_from_empty_pocket_it_should_throw()
        {
            var    pocket = new ConcurrentPocket();
            Action sut    = () => pocket.TakeOrThrow <string>("some name");

            sut.Should().Throw <KeyNotFoundException>("the pocket is empty");
        }
Exemplo n.º 2
0
        public void when_take_or_throw_stored_thing_it_should_be_found()
        {
            var          sut         = new ConcurrentPocket();
            const string nameOfThing = "name of the thing";
            const string thingItself = "the thing itself";

            sut.Put(nameOfThing, thingItself);

            sut.TakeOrThrow <string>(nameOfThing).Should().BeSameAs(thingItself, "the thing lies in the pocket");
        }
Exemplo n.º 3
0
        public void when_take_or_throw_stored_thing_with_unexpected_type_it_should_throw()
        {
            var          pocket      = new ConcurrentPocket();
            const string nameOfThing = "name of the thing";
            const string thingItself = "the thing itself";

            pocket.Put(nameOfThing, thingItself);

            Action sut = () => pocket.TakeOrThrow <given_pocket_extensions>(nameOfThing);

            sut.Should().Throw <InvalidCastException>("impossible to cast a string to the different type");
        }
Exemplo n.º 4
0
        public void when_take_or_throw_missing_thing_in_pocket_it_should_throw()
        {
            var          pocket      = new ConcurrentPocket();
            const string nameOfThing = "name of the thing";
            const string thingItself = "the thing itself";

            pocket.Put(nameOfThing, thingItself);

            Action sut = () => pocket.TakeOrThrow <string>("some other name");

            sut.Should().Throw <KeyNotFoundException>("there is no thing with such name in the pocket");
        }
Exemplo n.º 5
0
        public void when_take_or_throw_thing_with_invalid_name_given_it_should_throw()
        {
            var          pocket      = new ConcurrentPocket();
            const string nameOfThing = "name of the thing";
            const string thingItself = "the thing itself";

            pocket.Put(nameOfThing, thingItself);

            Action sut = () => pocket.TakeOrThrow <string>(name: null);

            sut.Should().Throw <ArgumentNullException>().Where(
                exception => exception.ParamName == "name",
                "null is not a valid name");

            sut = () => pocket.TakeOrThrow <string>(string.Empty);
            sut.Should().Throw <ArgumentNullException>().Where(
                exception => exception.ParamName == "name",
                "an empty string is not a valid name");

            sut = () => pocket.TakeOrThrow <string>(WhiteSpaceString);
            sut.Should().Throw <ArgumentNullException>().Where(
                exception => exception.ParamName == "name",
                "a whitespace is not a valid name");
        }