public void you_can_get_a_single_product()
        {
            var finder = new FindCommand(Internet, Settings.BaseUrl);
            var result = finder.Find(AnyProduct.Key);

            Assert.IsNotNull(result, "Expected a non-null result");
            Assert.AreEqual(result.Name, AnyProduct.Name, "Unexpected name");
            Assert.AreEqual("42", result.Designs[0].Reference, "Unexpected name");
        }
        public void finding_a_product_that_does_not_exist_returns_null()
        {
            const String AN_ID_THAT_DOES_NOT_EXIST = "Phil Murphy's fanny pack";

            var finder = new FindCommand(Internet, Settings.BaseUrl);
            var result = finder.Find(AN_ID_THAT_DOES_NOT_EXIST);

            Assert.IsNull(result, "Expected finding a product that does not exist to return null.");
        }
        private void then_the_product_does_not_exist_with_key(String id)
        {
            var finder = new FindCommand(Internet, Settings.BaseUrl);
            var result = finder.Find(id);

            Assert.IsNull(result, "Expected that finding the product with key <{0}> would return null.", id);
        }
        public void find_fails_when_internet_returns_401_unauthorized()
        {
            var expectedStatus = HttpStatusCode.Unauthorized;

            var unauthorizedResponse = NewFakeResponse(expectedStatus);

            var internet = MockRepository.GenerateStub<TheInternet>();
            internet.Stub(it => it.Get(Arg<Uri>.Is.Anything)).Return(unauthorizedResponse);

            var finder = new FindCommand(internet, "http://xxx");

            var expectedError = String.Format(
                "Authorization failed. The server returned status {0} ({1}).",
                expectedStatus,
                (Int32)expectedStatus
            );

            var theError = Assert.Throws<Exception>(() => finder.Find("xxx"));

            Assert.AreEqual(expectedError, theError.Message, "The error was raised, but the message does not match.");
        }
        public void find_returns_null_when_internet_returns_404_not_found()
        {
            var notFoundResponse = MockRepository.GenerateStub<Response>();
            notFoundResponse.Stub(it => it.StatusCode).Return(HttpStatusCode.NotFound);

            var internet = MockRepository.GenerateStub<TheInternet>();
            internet.Stub(it => it.Get(Arg<Uri>.Is.Anything)).Return(notFoundResponse);

            var finder = new FindCommand(internet, "http://xxx");

            var result = finder.Find("xxx");

            Assert.IsNull(result);
        }