public async Task EnsuresNonNullArguments() { var client = new WatchedClient(Substitute.For <IApiConnection>()); await Assert.ThrowsAsync <ArgumentNullException>(() => client.CheckWatched(null, "name")); await Assert.ThrowsAsync <ArgumentNullException>(() => client.CheckWatched("owner", null)); await Assert.ThrowsAsync <ArgumentException>(() => client.CheckWatched("", "name")); await Assert.ThrowsAsync <ArgumentException>(() => client.CheckWatched("owner", "")); }
public async Task ReturnsTrueOnValidResult() { var endpoint = new Uri("repos/fight/club/subscription", UriKind.Relative); var connection = Substitute.For<IApiConnection>(); connection.Get<Subscription>(endpoint).Returns(Task.FromResult(new Subscription())); var client = new WatchedClient(connection); var watched = await client.CheckWatched("fight", "club"); Assert.True(watched); }
public async Task ReturnsFalseOnNotFoundException() { var endpoint = new Uri("repos/fight/club/subscription", UriKind.Relative); var connection = Substitute.For<IApiConnection>(); var response = new ApiResponse<Subscription> { StatusCode = HttpStatusCode.NotFound }; connection.Get<Subscription>(endpoint).Returns(x => { throw new NotFoundException(response); }); var client = new WatchedClient(connection); var watched = await client.CheckWatched("fight", "club"); Assert.False(watched); }
public async Task ReturnsTrueOnValidResultWithRepositoryId() { var endpoint = new Uri("repositories/1/subscription", UriKind.Relative); var connection = Substitute.For <IApiConnection>(); connection.Get <Subscription>(endpoint).Returns(Task.FromResult(new Subscription(false, false, null, default(DateTimeOffset), null, null))); var client = new WatchedClient(connection); var watched = await client.CheckWatched(1); Assert.True(watched); }
public async Task ReturnsFalseOnNotFoundExceptionWithRepositoryId() { var endpoint = new Uri("repositories/1/subscription", UriKind.Relative); var connection = Substitute.For <IApiConnection>(); var response = CreateResponse(HttpStatusCode.NotFound); connection.Get <Subscription>(endpoint).Returns <Task <Subscription> >(x => { throw new NotFoundException(response); }); var client = new WatchedClient(connection); var watched = await client.CheckWatched(1); Assert.False(watched); }
public async Task ReturnsFalseOnNotFoundException() { var endpoint = new Uri("repos/fight/club/subscription", UriKind.Relative); var connection = Substitute.For <IApiConnection>(); var response = new Response(HttpStatusCode.NotFound, null, new Dictionary <string, string>(), "application/json"); connection.Get <Subscription>(endpoint).Returns <Task <Subscription> >(x => { throw new NotFoundException(response); }); var client = new WatchedClient(connection); var watched = await client.CheckWatched("fight", "club"); Assert.False(watched); }
public async Task ReturnsFalseOnNotFoundException() { var endpoint = new Uri("repos/fight/club/subscription", UriKind.Relative); var connection = Substitute.For<IApiConnection>(); var response = new Response(HttpStatusCode.NotFound, null, new Dictionary<string, string>(), "application/json"); connection.Get<Subscription>(endpoint).Returns<Task<Subscription>>(x => { throw new NotFoundException(response); }); var client = new WatchedClient(connection); var watched = await client.CheckWatched("fight", "club"); Assert.False(watched); }