Exemplo n.º 1
0
        public void when_take_or_null_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.TakeOrNull <string>(nameOfThing).Should().BeSameAs(thingItself, "the thing lies in the pocket");
        }
Exemplo n.º 2
0
        public void when_take_or_null_missing_thing_in_pocket_it_find_nothing()
        {
            var          sut         = new ConcurrentPocket();
            const string nameOfThing = "name of the thing";
            const string thingItself = "the thing itself";

            sut.Put(nameOfThing, thingItself);

            sut.TakeOrNull <string>("some other name").Should().BeNull("there is no thing with such name in the pocket");
        }
Exemplo n.º 3
0
        public void when_take_or_null_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.TakeOrNull <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_null_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.TakeOrNull <string>(name: null);

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

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

            sut = () => pocket.TakeOrNull <string>(WhiteSpaceString);
            sut.Should().Throw <ArgumentNullException>().Where(
                exception => exception.ParamName == "name",
                "a whitespace is not a valid name");
        }
Exemplo n.º 5
0
        public void when_take_or_null_something_from_empty_pocket_it_should_find_nothing()
        {
            var sut = new ConcurrentPocket();

            sut.TakeOrNull <string>("some name").Should().BeNull("the pocket is empty");
        }