public void you_can_get_a_list_of_products()
        {
            var finder = new FindCommand(Internet, Settings.BaseUrl);
            var result = finder.FindAll();

            Assert.That(result.Length, Is.GreaterThan(0), "Expected at least one product returned");
        }
        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.");
        }
        public void you_can_check_existence_of_a_product()
        {
            var finder = new FindCommand(Internet, Settings.BaseUrl);

            var result = finder.Exists(AnyProduct.Key);
            Assert.IsTrue(result, "Expected the result to be true because the Product does exist.");

            const String AN_ID_THAT_DOES_NOT_EXIST = "Phil Murphy's fanny pack";
            result = finder.Exists(AN_ID_THAT_DOES_NOT_EXIST);

            Assert.IsFalse(result, "Expected the result to be false because the Product does not exist.");
        }
        public void after_a_product_is_created_it_can_be_fetched_ie_it_has_been_persisted()
        {
            var aNewProduct = CreateCommand.Create(ProductSeed.WithName("A new product"), NewDesign());

            var theProductFetchedById = new FindCommand(Internet, Settings.BaseUrl).Find(aNewProduct.Key);

            Assert.AreEqual(theProductFetchedById.Key, aNewProduct.Key,
                "The product was fetched successfully, but it has an unexpected key."
            );
            Assert.AreEqual(theProductFetchedById.Name, aNewProduct.Name,
                "The product was fetched successfully, but it has an unexpected name."
            );
        }
Exemplo n.º 6
0
        public void exists_returns_a_value_that_depends_on_response_status()
        {
            var okResponse = NewFakeResponse(HttpStatusCode.OK);
            var internet = MockRepository.GenerateStub<TheInternet>();
            var finder = new FindCommand(internet, "http://xxx");

            internet.Stub(it => it.Get(Arg<Uri>.Is.Anything)).Return(okResponse);
            Assert.IsTrue(finder.Exists("xxx"), "Expected true because the internet returned OK.");

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

            finder = new FindCommand(internet, "http://xxx");
            Assert.IsFalse(finder.Exists("xxx"), "Expected false because the internet returned NotFound.");
        }
        public void you_cannot_delete_the_last_design()
        {
            var command = new DesignRepository(Internet, Settings.BaseUrl);

            Assert.AreEqual(1, ExampleProduct.Designs.Count,
                "Invalid test data. " +
                "Test expects there to be exactly one design in order to prove that it cannot be deleted."
            );

            var theError = Assert.Throws<Exception>(() =>
                command.Delete(ExampleProduct.Key, ExampleProduct.Designs[0].Key
            ));

            Assert.That(theError.Message, Is.StringEnding("\"Bad Request. Error deleting design.Product must have at least one design\""));

            var theRefreshedProduct = new FindCommand(Internet, Settings.BaseUrl).Find(ExampleProduct.Key);

            Assert.AreEqual(1, theRefreshedProduct.Designs.Count, "Expected the product to still have its last design");
        }
Exemplo n.º 8
0
        public void find_all_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.FindAll());

            Assert.AreEqual(expectedError, theError.Message, "The error was raised, but the message does not match.");
        }
        public void you_can_delete_them_all()
        {
            var finder = new FindCommand(Internet, Settings.BaseUrl);
            var delete = new DeleteCommand(Internet, Settings.BaseUrl);
            var result = finder.FindAll();

            var count = 0;

            Console.WriteLine("Deleting {0} products", result.Length);

            foreach (var product in result) {
                delete.Delete(product.Key);
                count++;
            }

            Console.WriteLine("Deleted {0} products", count);

            Assert.AreEqual(0, finder.FindAll().Length, "Expected them all to have been deleted");
        }
        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);
        }
Exemplo n.º 11
0
        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);
        }