Пример #1
0
        public async void Should_return_value_from_cache()
        {
            var requestHandler = StubRequestBuilder();
            var httpClient     = StubHttpClient();
            var api            = new FluentApi <Status>(httpClient, requestHandler);

            var cache  = new FakeCache();
            var status = await api.UsingCache(cache).Please();

            Assert.That(cache.TryGetCount, Is.EqualTo(1));
            Assert.That(status, Is.Not.Null);
        }
Пример #2
0
        public async void Should_read_cache()
        {
            var httpClient     = StubHttpClient();
            var requestHandler = StubRequestBuilder();
            var responseParser = StubResponseParser();

            var api = new FluentApi <Status>(httpClient, requestHandler, responseParser);

            var cache = new FakeCache();
            await api.UsingCache(cache).Please();

            Assert.That(cache.TryGetCount, Is.EqualTo(1));
        }
Пример #3
0
        public async void Should_write_to_cache_on_success()
        {
            var requestHandler = StubRequestBuilder();
            var httpClient     = StubHttpClient();
            var api            = new FluentApi <Status>(httpClient, requestHandler);

            var cache = new FakeCache();
            await api.UsingCache(cache).Please();

            Assert.That(cache.SetCount, Is.EqualTo(1));
            Assert.That(cache.CachedResponses.Count, Is.EqualTo(1));
            Assert.That(cache.CachedResponses[0], Is.InstanceOf <Status>());
        }
Пример #4
0
        public async void Should_not_hit_endpoint_when_value_is_found_in_cache()
        {
            var requestHandler = StubRequestBuilder();
            var httpClient     = StubHttpClient();
            var api            = new FluentApi <Status>(httpClient, requestHandler);

            var cache = new FakeCache();

            cache.StubCachedObject = _stubStatus;

            await api.UsingCache(cache).Please();

            A.CallTo(() => httpClient.Send(A <Request> .Ignored)).MustNotHaveHappened();
        }
Пример #5
0
        public void Should_not_write_to_cache_on_failure()
        {
            var requestHandler = StubRequestBuilder();
            var httpClient     = StubHttpClient();
            var api            = new FluentApi <Status>(httpClient, requestHandler);

            var cache = new FakeCache();

            A.CallTo(() => httpClient.Send(A <Request> .Ignored)).Throws <WebException>();

            api.UsingCache(cache);

            Assert.Throws <ApiWebException>(async() => await api.Please());

            Assert.That(cache.SetCount, Is.EqualTo(0));
            Assert.That(cache.CachedResponses.Count, Is.EqualTo(0));
        }
		public void Should_not_write_to_cache_on_failure()
		{
			var requestHandler = StubRequestBuilder();
			var httpClient = StubHttpClient();
			var responseParser = StubResponseParser();

			var api = new FluentApi<Status>(httpClient, requestHandler, responseParser);

			var cache = new FakeCache();

			A.CallTo(() => httpClient.Send(A<Request>.Ignored)).Throws<WebException>();

			api.UsingCache(cache);

			Assert.Throws<ApiWebException>(async () => await api.Please());

			Assert.That(cache.SetCount, Is.EqualTo(0));
			Assert.That(cache.CachedResponses.Count, Is.EqualTo(0));
		}
		public async void Should_not_hit_endpoint_when_value_is_found_in_cache()
		{
			var requestHandler = StubRequestBuilder();
			var httpClient = StubHttpClient();
			var responseParser = StubResponseParser();

			var api = new FluentApi<Status>(httpClient, requestHandler, responseParser);

			var cache = new FakeCache();
			cache.StubCachedObject = _stubStatus;

			await api.UsingCache(cache).Please();
			A.CallTo(() => httpClient.Send(A<Request>.Ignored)).MustNotHaveHappened();
		}
		public async void Should_return_value_from_cache()
		{
			var requestHandler = StubRequestBuilder();
			var httpClient = StubHttpClient();
			var responseParser = StubResponseParser();

			var api = new FluentApi<Status>(httpClient, requestHandler, responseParser);

			var cache = new FakeCache();
			var status = await api.UsingCache(cache).Please();

			Assert.That(cache.TryGetCount, Is.EqualTo(1));
			Assert.That(status, Is.Not.Null);
		}
		public async void Should_write_to_cache_on_success()
		{
			var requestHandler = StubRequestBuilder();
			var httpClient = StubHttpClient();
			var responseParser = StubResponseParser();
			var api = new FluentApi<Status>(httpClient, requestHandler, responseParser);
			
			var cache = new FakeCache();
			await api.UsingCache(cache).Please();

			Assert.That(cache.SetCount, Is.EqualTo(1));
			Assert.That(cache.CachedResponses.Count, Is.EqualTo(1));
			Assert.That(cache.CachedResponses[0], Is.InstanceOf<Status>());
		}
		public void Should_not_write_to_cache_on_failure()
		{
			var requestCoordinator = A.Fake<IRequestCoordinator>();
			var cache = new FakeCache();
			A.CallTo(() => requestCoordinator.HitEndpoint(A<RequestData>.Ignored)).Throws<WebException>();
			A.CallTo(() => requestCoordinator.ConstructEndpoint(A<RequestData>.Ignored)).Returns("http://foo.com/bar");

			var api = new FluentApi<Status>(requestCoordinator).UsingCache(cache);

			Assert.Throws<ApiWebException>(() => api.Please());

			Assert.That(cache.SetCount, Is.EqualTo(0));
			Assert.That(cache.CachedResponses.Count, Is.EqualTo(0));
		}
		public void Should_not_hit_endpoint_when_value_is_found_in_cache()
		{
			var requestCoordinator = A.Fake<IRequestCoordinator>();
			var cache = new FakeCache();
			cache.StubResponse = stubResponse;

			new FluentApi<Status>(requestCoordinator).UsingCache(cache).Please();
			A.CallTo(() => requestCoordinator.HitEndpoint(A<RequestData>.Ignored)).MustNotHaveHappened();
		}
		public void Should_return_value_from_cache()
		{
			var requestCoordinator = A.Fake<IRequestCoordinator>();
			var cache = new FakeCache();
			cache.StubResponse = stubResponse;

			var status =new FluentApi<Status>(requestCoordinator).UsingCache(cache).Please();

			Assert.That(cache.TryGetCount, Is.EqualTo(1));
			Assert.That(status, Is.Not.Null);
		}
		public void Should_write_to_cache_on_success()
		{
			var requestCoordinator = A.Fake<IRequestCoordinator>();
			var cache = new FakeCache();
			A.CallTo(() => requestCoordinator.HitEndpoint(A<RequestData>.Ignored))
				.Returns(stubResponse);

			new FluentApi<Status>(requestCoordinator).UsingCache(cache).Please();

			Assert.That(cache.SetCount, Is.EqualTo(1));
			Assert.That(cache.CachedResponses.Count, Is.EqualTo(1));
			Assert.That(cache.CachedResponses[0], Is.EqualTo(stubResponse));
		}