public void ShouldDeleteCustomer()
        {
            ICustomerAdapter adapter = Substitute.For<ICustomerAdapter>();
            adapter.RemoveCustomer(Arg.Any<string>());
            using (CustomersController controller = new CustomersController(adapter))
            using (HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Delete, "~/api/customers"))
            {
                request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration());
                string customerId = Guid.NewGuid().ToString("N");
                HttpResponseMessage message = controller.Delete(request, customerId);

                Assert.AreEqual(HttpStatusCode.OK, message.StatusCode, "The wrong status code was returned.");
                Assert.IsInstanceOfType(message.Content, typeof(ObjectContent), "The content was not the serialized result.");
                ObjectContent content = (ObjectContent)message.Content;
                Assert.AreSame("The customer was deleted.", content.Value, "The wrong object was returned.");

                adapter.Received().RemoveCustomer(customerId);
            }
        }
        public void ShouldGetAllCustomers()
        {
            ICustomerAdapter adapter = Substitute.For<ICustomerAdapter>();
            IEnumerable<CustomerData> data = new List<CustomerData>() { new CustomerData() };
            adapter.GetCustomers().Returns(data);
            using (CustomersController controller = new CustomersController(adapter))
            using (HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "~/api/customers"))
            {
                request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration());
                HttpResponseMessage response = controller.GetAll(request);
                Assert.IsInstanceOfType(response.Content, typeof(ObjectContent<CustomerData[]>), "An array of customer data wasn't returned.");

                ObjectContent<CustomerData[]> content = (ObjectContent<CustomerData[]>)response.Content;
                CustomerData[] results = (CustomerData[])content.Value;
                Assert.AreEqual(1, results.Length, "There should have been one customer.");
                Assert.AreSame(data.First(), results[0], "The wrong customer was returned.");

                adapter.Received().GetCustomers();
            }
        }
        public void ShouldCreateAndReturnCustomer()
        {
            ICustomerAdapter adapter = Substitute.For<ICustomerAdapter>();
            CustomerData added = new CustomerData();
            adapter.AddCustomer(Arg.Any<CustomerData>()).Returns(added);
            using (CustomersController controller = new CustomersController(adapter))
            using (HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "~/api/customers"))
            {
                request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration());
                CustomerData data = new CustomerData();
                HttpResponseMessage message = controller.Post(request, data);

                Assert.AreEqual(HttpStatusCode.Created, message.StatusCode, "The wrong status code was returned.");
                Assert.IsInstanceOfType(message.Content, typeof(ObjectContent), "The content was not the serialized result.");
                ObjectContent content = (ObjectContent)message.Content;
                Assert.AreSame(added, content.Value, "The wrong object was returned.");

                adapter.Received().AddCustomer(data);
            }
        }
        public void ShouldGetCustomerById()
        {
            ICustomerAdapter adapter = Substitute.For<ICustomerAdapter>();
            CustomerData data = new CustomerData();
            adapter.GetCustomer(Arg.Any<string>()).Returns(data);
            using (CustomersController controller = new CustomersController(adapter))
            {
                string customerId = Guid.NewGuid().ToString("N");
                using (HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "~/api/customers/" + customerId))
                {
                    request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration());
                    HttpResponseMessage response = controller.Get(request, customerId);
                    Assert.IsInstanceOfType(response.Content, typeof(ObjectContent<CustomerData>), "Customer data was not returned.");
                    ObjectContent<CustomerData> content = (ObjectContent<CustomerData>)response.Content;
                    CustomerData result = (CustomerData)content.Value;

                    Assert.AreSame(data, result, "The wrong customer was returned.");

                    adapter.Received().GetCustomer(customerId);
                }
            }
        }