public async Task Should_Register_Device() { const string path = "/api/users/registerDeviceToken"; var request = new RegisterDeviceTokenRequest { Email = "*****@*****.**", UserId = "*****@*****.**" }; MockRestClient.Setup(m => m.PostAsync <RegisterDeviceTokenResponse>(It.Is <string>(a => a == path), It.IsAny <RegisterDeviceTokenRequest>())).ReturnsAsync(new ApiResponse <RegisterDeviceTokenResponse> { UrlPath = path, HttpStatusCode = HttpStatusCode.OK, Model = new RegisterDeviceTokenResponse { Code = "Success" } }); ApiResponse <RegisterDeviceTokenResponse> response = await _userClient.RegisterDeviceTokenAsync(request).ConfigureAwait(false); Assert.NotNull(response); Assert.NotNull(response.Model); Assert.Equal("Success", response.Model.Code); Assert.Equal(HttpStatusCode.OK, response.HttpStatusCode); Assert.Equal(path, response.UrlPath); MockRestClient.Verify(m => m.PostAsync <RegisterDeviceTokenResponse>(It.Is <string>(a => a == path), It.IsAny <RegisterDeviceTokenRequest>()), Times.Once); }
public async Task Should_Retrieve_User() { const string userId = "*****@*****.**"; string path = $"/api/users/byUserId/{userId}"; MockRestClient.Setup(m => m.GetAsync <RetrieveUserResponse>(It.Is <string>(a => a == path))).ReturnsAsync(new ApiResponse <RetrieveUserResponse> { UrlPath = path, HttpStatusCode = HttpStatusCode.OK, Model = new RetrieveUserResponse { User = new UserModel { Email = userId, UserId = userId } } }); ApiResponse <RetrieveUserResponse> response = await _userClient.GetByUserIdAsync(userId).ConfigureAwait(false); Assert.NotNull(response); Assert.NotNull(response.Model); Assert.NotNull(response.Model.User); Assert.Equal(userId, response.Model.User.Email); Assert.Equal(userId, response.Model.User.UserId); Assert.Equal(HttpStatusCode.OK, response.HttpStatusCode); Assert.Equal(path, response.UrlPath); MockRestClient.Verify(m => m.GetAsync <RetrieveUserResponse>(It.Is <string>(a => a == path)), Times.Once); }
public async Task Should_Retrieve_Users() { const int listId = 14; const string users = "[email protected]\[email protected]"; string path = $"/api/lists/getUsers?listId={listId}"; MockRestClient.Setup(m => m.GetContentAsync(It.Is <string>(a => a == path))).ReturnsAsync(new ApiResponse { UrlPath = path, HttpStatusCode = HttpStatusCode.OK, Content = users }); ApiResponse <GetUsersResponse> response = await _listClient.GetUsersAsync(listId).ConfigureAwait(false); Assert.NotNull(response); Assert.NotNull(response.Model); Assert.NotNull(response.Model.UserIds); Assert.True(response.Model.UserIds.Any()); Assert.Equal(2, response.Model.UserIds.Count()); Assert.Equal(HttpStatusCode.OK, response.HttpStatusCode); Assert.Equal(path, response.UrlPath); MockRestClient.Verify(m => m.GetContentAsync(It.Is <string>(a => a == path)), Times.Once); }
public async Task Should_Update_Email() { string path = "/api/users/updateEmail"; var request = new UpdateEmailRequest { CurrentEmail = "*****@*****.**", NewEmail = "*****@*****.**" }; MockRestClient.Setup(m => m.PostAsync <UpdateUserResponse>(It.Is <string>(a => a == path), It.IsAny <UpdateEmailRequest>())).ReturnsAsync(new ApiResponse <UpdateUserResponse> { UrlPath = path, HttpStatusCode = HttpStatusCode.OK, Model = new UpdateUserResponse { Code = "Success" } }); ApiResponse <UpdateUserResponse> response = await _userClient.UpdateEmailAsync(request).ConfigureAwait(false); Assert.NotNull(response); Assert.NotNull(response.Model); Assert.Equal("Success", response.Model.Code); Assert.Equal(HttpStatusCode.OK, response.HttpStatusCode); Assert.Equal(path, response.UrlPath); MockRestClient.Verify(m => m.PostAsync <UpdateUserResponse>(It.Is <string>(a => a == path), It.IsAny <UpdateEmailRequest>()), Times.Once); }
public async Task Should_Delete_User() { const string email = "*****@*****.**"; string path = $"/api/users/{email}"; MockRestClient.Setup(m => m.DeleteAsync <DeleteUserResponse>(It.Is <string>(a => a == path))).ReturnsAsync(new ApiResponse <DeleteUserResponse> { UrlPath = path, HttpStatusCode = HttpStatusCode.OK, Model = new DeleteUserResponse { Code = "Success" } }); ApiResponse <DeleteUserResponse> response = await _userClient.DeleteByEmailAsync(email).ConfigureAwait(false); Assert.NotNull(response); Assert.NotNull(response.Model); Assert.Equal("Success", response.Model.Code); Assert.Equal(HttpStatusCode.OK, response.HttpStatusCode); Assert.Equal(path, response.UrlPath); MockRestClient.Verify(m => m.DeleteAsync <DeleteUserResponse>(It.Is <string>(a => a == path)), Times.Once); }
public void ShouldReturnHealthStatus() { var expected = new HealthStatus() { IsElasticsearchServerAvailable = true, IsMailServerAvailable = true, IsMessageQueueServerAvailable = true, }; var content = JsonConvert.SerializeObject(expected); var restResponse = new RestResponse() { Content = content }; MockRestClient.Setup(x => x.Execute(It.Is <RestRequest>(y => y.Resource == HealthStatusName))) .Returns(restResponse); MockJsonConvert.Setup(x => x.DeserializeObject <HealthStatus>(content)) .Returns(expected); var actual = Subject.GetHealthStatus(); Assert.That(actual, Is.EqualTo(expected)); MockRestClient.Verify(x => x.Execute(It.Is <RestRequest>(y => y.Resource == HealthStatusName)), Times.Once); MockJsonConvert.Verify(x => x.DeserializeObject <HealthStatus>(content), Times.Once); }
public async Task Should_Delete() { const int listId = 14; string path = $"/api/lists/{listId}"; MockRestClient.Setup(m => m.DeleteAsync <DeleteListResponse>(It.Is <string>(a => a == path))).ReturnsAsync(new ApiResponse <DeleteListResponse> { UrlPath = path, HttpStatusCode = HttpStatusCode.OK, Model = new DeleteListResponse { Code = "Success" } }); ApiResponse <DeleteListResponse> response = await _listClient.DeleteAsync(listId).ConfigureAwait(false); Assert.NotNull(response); Assert.NotNull(response.Model); Assert.Equal("Success", response.Model.Code); Assert.Equal(HttpStatusCode.OK, response.HttpStatusCode); Assert.Equal(path, response.UrlPath); MockRestClient.Verify(m => m.DeleteAsync <DeleteListResponse>(It.Is <string>(a => a == path)), Times.Once); }
public async Task Should_Create_List() { const string path = "/api/lists"; const string name = "test_list"; const int listId = 14; MockRestClient.Setup(m => m.PostAsync <CreateListResponse>(It.Is <string>(a => a == path), It.Is <string>(a => a == name))).ReturnsAsync(new ApiResponse <CreateListResponse> { UrlPath = path, HttpStatusCode = HttpStatusCode.OK, Model = new CreateListResponse { ListId = listId } }); ApiResponse <CreateListResponse> response = await _listClient.CreateAsync(name).ConfigureAwait(false); Assert.NotNull(response); Assert.NotNull(response.Model); Assert.Equal(listId, response.Model.ListId); Assert.Equal(HttpStatusCode.OK, response.HttpStatusCode); Assert.Equal(path, response.UrlPath); MockRestClient.Verify(m => m.PostAsync <CreateListResponse>(It.Is <string>(a => a == path), It.Is <string>(a => a == name)), Times.Once); }
public Client Build() { var payload = new ExpandoObject() as IDictionary <string, object>; foreach (var data in Data) { payload.Add(data.Key, data.Value); } MockRestResponse.SetupGet(m => m.Content) .Returns(JsonConvert.SerializeObject(payload)); MockRestResponse.SetupGet(m => m.StatusCode) .Returns(Status); MockRestClient.Setup(m => m.ExecuteAsync(It.Is <IRestRequest>(request => request.Resource.Equals(Resource) && request.Method.Equals(Method) && Parameters.All(x => ContainsParameter(request, x.Key, x.Value))) , It.IsAny <CancellationToken>())) .ReturnsAsync(MockRestResponse.Object) .Verifiable(); return(new Client(ApiToken, Username, MockRestClient.Object)); }
protected override void OnArrange() { base.OnArrange(); MockLeanKitApi.Setup(x => x.GetBoard(It.IsAny <long>())).Returns(_testBoard); var serializer = new JsonSerializer <Unfuddle.Person>(); var user1 = new Unfuddle.Person() { Email = "*****@*****.**", First_Name = "Johnny", Id = 1, Last_Name = "Cash", Username = "******" }; var user2 = new Unfuddle.Person() { Email = "*****@*****.**", First_Name = "Willy", Id = 2, Last_Name = "Cash", Username = "******" }; var user3 = new Unfuddle.Person() { Email = "", First_Name = "", Id = 3, Last_Name = "", Username = "" }; var restResponse1 = new RestResponse() { Content = serializer.SerializeToString(user1), StatusCode = HttpStatusCode.OK }; var restResponse2 = new RestResponse() { Content = serializer.SerializeToString(user2), StatusCode = HttpStatusCode.OK }; var restResponse3 = new RestResponse() { Content = serializer.SerializeToString(user3), StatusCode = HttpStatusCode.OK }; MockRestClient.Setup(x => x.Execute(It.Is <RestRequest>(y => y.Resource.Contains("people/1")))).Returns(restResponse1); MockRestClient.Setup(x => x.Execute(It.Is <RestRequest>(y => y.Resource.Contains("people/2")))).Returns(restResponse2); MockRestClient.Setup(x => x.Execute(It.Is <RestRequest>(y => y.Resource.Contains("people/3")))).Returns(restResponse3); }
public void ShouldQueryTheHealthStatusEndpointAndReturnStatusCodeWhenPinging() { var restResponse = new RestResponse() { StatusCode = HttpStatusCode.OK }; MockRestClient.Setup(x => x.Execute(It.Is <RestRequest>(y => y.Resource == HealthStatusName))).Returns(restResponse); var actual = Subject.Ping(); MockRestClient.Verify(x => x.Execute(It.Is <RestRequest>(y => y.Resource == HealthStatusName)), Times.Once); Assert.That(actual, Is.TypeOf(typeof(HttpStatusCode))); }
protected override void OnArrange() { base.OnArrange(); MockLeanKitApi.Setup(x => x.GetBoard(It.IsAny <long>())).Returns(_testBoard); var serializer = new JsonSerializer <GitHubIssues.Issue>(); var issue1 = new GitHubIssues.Issue() { Id = 1, Number = 1, State = "Open" }; var restResponse1 = new RestResponse() { Content = serializer.SerializeToString(issue1), StatusCode = HttpStatusCode.OK }; MockRestClient.Setup(x => x.Execute(It.Is <RestRequest>(y => y.Resource.Contains("issues/1") && y.Method == Method.GET))).Returns(restResponse1); MockRestClient.Setup(x => x.Execute(It.Is <RestRequest>(y => y.Resource.Contains("issues/1") && y.Method == Method.PATCH))).Returns(restResponse1); var issue2 = new GitHubIssues.Issue() { Id = 2, Number = 2, State = "Closed" }; var restResponse2 = new RestResponse() { Content = serializer.SerializeToString(issue2), StatusCode = HttpStatusCode.OK }; MockRestClient.Setup(x => x.Execute(It.Is <RestRequest>(y => y.Resource.Contains("issues/2") && y.Method == Method.GET))).Returns(restResponse2); MockRestClient.Setup(x => x.Execute(It.Is <RestRequest>(y => y.Resource.Contains("issues/2") && y.Method == Method.PATCH))).Returns(restResponse2); var errorSerializer = new JsonSerializer <GitHubIssues.ErrorMessage>(); var errorResponse = new RestResponse() { Content = errorSerializer.SerializeToString(new GitHubIssues.ErrorMessage() { Message = "Error" }), StatusCode = HttpStatusCode.NotFound }; MockRestClient.Setup(x => x.Execute(It.Is <RestRequest>(y => y.Resource.Contains("issues/3") && y.Method == Method.GET))).Returns(errorResponse); MockRestClient.Setup(x => x.Execute(It.Is <RestRequest>(y => y.Resource.Contains("issues/3") && y.Method == Method.PATCH))).Returns(errorResponse); }
public async Task Should_Not_Return_Size_When_Content_Is_Null_Or_Empty() { const int listId = 14; string path = $"/api/lists/{listId}/size"; MockRestClient.Setup(m => m.GetContentAsync(It.Is <string>(a => a == path))).ReturnsAsync(new ApiResponse { UrlPath = path, HttpStatusCode = HttpStatusCode.OK }); ApiResponse <GetSizeResponse> response = await _listClient.GetSizeAsync(listId).ConfigureAwait(false); Assert.NotNull(response); Assert.Null(response.Model); Assert.Equal(HttpStatusCode.OK, response.HttpStatusCode); Assert.Equal(path, response.UrlPath); MockRestClient.Verify(m => m.GetContentAsync(It.Is <string>(a => a == path)), Times.Once); }
public void ShouldGetCollectionOfResourceStubs() { var expected = new List <ResourceStub>(); var content = JsonConvert.SerializeObject(expected); var restResponse = new RestResponse() { Content = content }; MockRestClient.Setup(x => x.Execute(It.Is <RestRequest>(y => y.Resource == ResourceStubName))) .Returns(restResponse); MockJsonConvert.Setup(x => x.DeserializeObject <IList <ResourceStub> >(content)) .Returns(expected); var actual = Subject.GetCollection <ResourceStub>(); Assert.That(actual.ToList(), Is.EquivalentTo(expected)); MockRestClient.Verify(x => x.Execute(It.Is <RestRequest>(y => y.Resource == ResourceStubName)), Times.Once); MockJsonConvert.Verify(x => x.DeserializeObject <IList <ResourceStub> >(content), Times.Once); }
public void ShouldCreateAndReturnResourceStub() { var expected = new ResourceStub(); var content = JsonConvert.SerializeObject(expected); var restResponse = new RestResponse() { Content = content }; MockRestClient.Setup(x => x.Execute(It.Is <RestRequest>(y => y.Resource == ResourceStubName))) .Returns(restResponse); MockJsonConvert.Setup(x => x.DeserializeObject <ResourceStub>(content)) .Returns(expected); var actual = Subject.Create(expected); Assert.That(actual, Is.EqualTo(expected)); MockRestClient.Verify(x => x.Execute(It.Is <RestRequest>(y => y.Resource == ResourceStubName)), Times.Once); MockJsonConvert.Verify(x => x.DeserializeObject <ResourceStub>(content), Times.Once); }
public async Task Should_Not_Return_Users_When_HttpStatusCode_Is_Unauthorized() { const int listId = 14; string path = $"/api/lists/getUsers?listId={listId}"; MockRestClient.Setup(m => m.GetContentAsync(It.Is <string>(a => a == path))).ReturnsAsync(new ApiResponse { UrlPath = path, HttpStatusCode = HttpStatusCode.Unauthorized }); ApiResponse <GetUsersResponse> response = await _listClient.GetUsersAsync(listId).ConfigureAwait(false); Assert.NotNull(response); Assert.Null(response.Model); Assert.Equal(HttpStatusCode.Unauthorized, response.HttpStatusCode); Assert.Equal(path, response.UrlPath); MockRestClient.Verify(m => m.GetContentAsync(It.Is <string>(a => a == path)), Times.Once); }
public async Task Should_Retrieve_All_Lists() { const string path = "/api/lists"; const int listId = 14; const string listName = "test list"; DateTime date = DateTime.Now.AddDays(-10); MockRestClient.Setup(m => m.GetAsync <GetAllListResponse>(It.Is <string>(a => a == path))).ReturnsAsync(new ApiResponse <GetAllListResponse> { UrlPath = path, HttpStatusCode = HttpStatusCode.OK, Model = new GetAllListResponse { Lists = new List <GetAllListModel> { new GetAllListModel { Id = listId, CreatedAt = date.ToString(), Name = listName } } } }); ApiResponse <GetAllListResponse> response = await _listClient.GetAllListsAsync().ConfigureAwait(false); Assert.NotNull(response); Assert.NotNull(response.Model); Assert.NotNull(response.Model.Lists); Assert.NotNull(response.Model.Lists.First()); Assert.Equal(listName, response.Model.Lists.First().Name); Assert.Equal(listId, response.Model.Lists.First().Id); Assert.Equal(date.ToString(), response.Model.Lists.First().CreatedAt); Assert.Equal(HttpStatusCode.OK, response.HttpStatusCode); Assert.Equal(path, response.UrlPath); MockRestClient.Verify(m => m.GetAsync <GetAllListResponse>(It.Is <string>(a => a == path)), Times.Once); }
public async Task Should_Retrieve_Size() { const int listId = 14; const int size = 309; string path = $"/api/lists/{listId}/size"; MockRestClient.Setup(m => m.GetContentAsync(It.Is <string>(a => a == path))).ReturnsAsync(new ApiResponse { UrlPath = path, HttpStatusCode = HttpStatusCode.OK, Content = size.ToString() }); ApiResponse <GetSizeResponse> response = await _listClient.GetSizeAsync(listId).ConfigureAwait(false); Assert.NotNull(response); Assert.NotNull(response.Model); Assert.Equal(size, response.Model.Size); Assert.Equal(HttpStatusCode.OK, response.HttpStatusCode); Assert.Equal(path, response.UrlPath); MockRestClient.Verify(m => m.GetContentAsync(It.Is <string>(a => a == path)), Times.Once); }
public async Task Should_Subscribe() { const string path = "/api/lists/subscribe"; const int successCount = 14; var request = new SubscribeRequest { ListId = 14, Subscribers = new UserModel[1] { new UserModel { Email = "*****@*****.**", UserId = "*****@*****.**" } } }; MockRestClient.Setup(m => m.PostAsync <SubscribeResponse>(It.Is <string>(a => a == path), It.IsAny <SubscribeRequest>())).ReturnsAsync(new ApiResponse <SubscribeResponse> { UrlPath = path, HttpStatusCode = HttpStatusCode.OK, Model = new SubscribeResponse { SuccessCount = successCount } }); ApiResponse <SubscribeResponse> response = await _listClient.SubscribeAsync(request).ConfigureAwait(false); Assert.NotNull(response); Assert.NotNull(response.Model); Assert.Equal(successCount, response.Model.SuccessCount); Assert.Equal(HttpStatusCode.OK, response.HttpStatusCode); Assert.Equal(path, response.UrlPath); MockRestClient.Verify(m => m.PostAsync <SubscribeResponse>(It.Is <string>(a => a == path), It.IsAny <SubscribeRequest>()), Times.Once); }
public async Task Should_Purchase_With_Valid_Value() { string path = "/api/commerce/trackPurchase"; var request = new TrackPurchaseRequest() { Id = "1234", Items = new List <CommerceItem>(), User = new UpdateUserRequest() { Email = "*****@*****.**", UserId = "*****@*****.**", DataFields = new ExpandoObject() } }; MockRestClient.Setup(m => m.PostAsync <TrackPurchaseResponse>(It.Is <string>(a => a == path), It.IsAny <TrackPurchaseRequest>())).ReturnsAsync(new ApiResponse <TrackPurchaseResponse> { UrlPath = path, HttpStatusCode = HttpStatusCode.OK, Model = new TrackPurchaseResponse { Code = "Success" } }); ApiResponse <TrackPurchaseResponse> response = await _commerceClient.TrackPurchaseAsync(request).ConfigureAwait(false); Assert.NotNull(response); Assert.NotNull(response.Model); Assert.Equal("Success", response.Model.Code); Assert.Equal(HttpStatusCode.OK, response.HttpStatusCode); Assert.Equal(path, response.UrlPath); MockRestClient.Verify(m => m.PostAsync <TrackPurchaseResponse>(It.Is <string>(a => a == path), It.IsAny <TrackPurchaseRequest>()), Times.Once); }
public async Task Should_Update_User() { string path = "/api/users/bulkUpdate"; var request = new BulkUpadateUserRequest { Users = new UserModel[1] { new UserModel { Email = "*****@*****.**", UserId = "*****@*****.**" } } }; MockRestClient.Setup(m => m.PostAsync <BulkUpdateUserResponse>(It.Is <string>(a => a == path), It.IsAny <UserModel[]>())).ReturnsAsync(new ApiResponse <BulkUpdateUserResponse> { UrlPath = path, HttpStatusCode = HttpStatusCode.OK, Model = new BulkUpdateUserResponse { SuccessCount = 5 } }); ApiResponse <BulkUpdateUserResponse> response = await _userClient.BulkUpdateAsync(request).ConfigureAwait(false); Assert.NotNull(response); Assert.NotNull(response.Model); Assert.Equal(5, response.Model.SuccessCount); Assert.Equal(HttpStatusCode.OK, response.HttpStatusCode); Assert.Equal(path, response.UrlPath); MockRestClient.Verify(m => m.PostAsync <BulkUpdateUserResponse>(It.Is <string>(a => a == path), It.IsAny <UserModel[]>()), Times.Once); }
protected override void OnArrange() { base.OnArrange(); MockLeanKitApi.Setup(x => x.GetBoard(It.IsAny <long>())).Returns(_testBoard); var serializer = new JsonSerializer <List <GitHubPulls.Pull> >(); var pull1 = new GitHubPulls.Pull() { Id = 1, Number = 1, State = "Open", Body = "New Pull 1", Title = "New Pull 1" }; var pull2 = new GitHubPulls.Pull() { Id = 2, Number = 2, State = "Open", Body = "New Pull 2", Title = "New Pull 2" }; var pull3 = new GitHubPulls.Pull() { Id = 3, Number = 3, State = "Open", Body = "New Pull 3", Title = "New Pull 3" }; var restResponse1 = new RestResponse() { Content = serializer.SerializeToString(new List <GitHubPulls.Pull>() { pull1 }), StatusCode = HttpStatusCode.OK }; MockRestClient.Setup( x => x.Execute(It.Is <RestRequest>(y => y.Resource.Contains("/1/pulls") && y.Method == Method.GET))) .Returns(restResponse1); MockLeanKitApi.Setup(x => x.GetCardByExternalId(1, It.IsAny <string>())).Returns((Card)null); MockLeanKitApi.Setup(x => x.AddCard(1, It.IsAny <Card>(), It.IsAny <string>())).Returns(_testCardAddResult1); MockRestClient.Setup( x => x.Execute(It.Is <RestRequest>(y => y.Resource.Contains("/2/pulls") && y.Method == Method.GET))) .Returns(restResponse1); MockLeanKitApi.Setup(x => x.GetCardByExternalId(2, It.IsAny <string>())).Returns((Card)null); MockLeanKitApi.Setup(x => x.AddCard(2, It.IsAny <Card>(), It.IsAny <string>())).Returns(_testCardAddResult1); var restResponse3 = new RestResponse() { Content = serializer.SerializeToString(new List <GitHubPulls.Pull>() { pull1, pull2, pull3 }), StatusCode = HttpStatusCode.OK }; MockRestClient.Setup( x => x.Execute(It.Is <RestRequest>(y => y.Resource.Contains("/3/pulls") && y.Method == Method.GET))) .Returns(restResponse3); MockLeanKitApi.Setup(x => x.GetCardByExternalId(3, It.IsAny <string>())).Returns((Card)null); MockLeanKitApi.Setup(x => x.AddCard(3, It.IsAny <Card>(), It.IsAny <string>())).Returns(_testCardAddResult1); MockRestClient.Setup( x => x.Execute(It.Is <RestRequest>(y => y.Resource.Contains("/4/pulls") && y.Method == Method.GET))) .Returns(restResponse1); MockLeanKitApi.Setup(x => x.GetCardByExternalId(4, It.IsAny <string>())) .Returns(new Card() { Id = 4, ExternalSystemName = "GitHub" }); MockLeanKitApi.Setup(x => x.AddCard(4, It.IsAny <Card>(), It.IsAny <string>())).Returns(_testCardAddResult1); MockRestClient.Setup( x => x.Execute(It.Is <RestRequest>(y => y.Resource.Contains("/5/pulls") && y.Method == Method.GET))) .Returns(restResponse1); MockLeanKitApi.Setup(x => x.GetCardByExternalId(5, It.IsAny <string>())) .Returns(new Card() { Id = 5, ExternalSystemName = "GitHubber" }); MockLeanKitApi.Setup(x => x.AddCard(5, It.IsAny <Card>(), It.IsAny <string>())).Returns(_testCardAddResult1); }
protected override void OnArrange() { base.OnArrange(); MockLeanKitApi.Setup(x => x.GetBoard(It.IsAny <long>())).Returns(_testBoard); var serializer = new JsonSerializer <GitHubIssues.Issue>(); var issue1 = new GitHubIssues.Issue() { Id = 1, Number = 1, Title = "Issue 1", Body = "Issue 1", State = "Open" }; var restResponse1 = new RestResponse() { Content = serializer.SerializeToString(issue1), StatusCode = HttpStatusCode.OK }; MockRestClient.Setup(x => x.Execute(It.Is <RestRequest>(y => y.Resource.Contains("issues/1") && y.Method == Method.GET))).Returns(restResponse1); MockRestClient.Setup(x => x.Execute(It.Is <RestRequest>(y => y.Resource.Contains("issues/1") && y.Method == Method.PATCH))).Returns(restResponse1); var issue2 = new GitHubIssues.Issue() { Id = 2, Number = 2, Title = "Issue 2", Body = "Issue 2", State = "Open" }; var restResponse2 = new RestResponse() { Content = serializer.SerializeToString(issue2), StatusCode = HttpStatusCode.OK }; MockRestClient.Setup(x => x.Execute(It.Is <RestRequest>(y => y.Resource.Contains("issues/2") && y.Method == Method.GET))).Returns(restResponse2); MockRestClient.Setup(x => x.Execute(It.Is <RestRequest>(y => y.Resource.Contains("issues/2") && y.Method == Method.PATCH))).Returns(restResponse2); var issue3 = new GitHubIssues.Issue() { Id = 3, Number = 3, Title = "Issue 3", Body = "Issue 3", State = "Open" }; var restResponse3 = new RestResponse() { Content = serializer.SerializeToString(issue3), StatusCode = HttpStatusCode.OK }; MockRestClient.Setup(x => x.Execute(It.Is <RestRequest>(y => y.Resource.Contains("issues/3") && y.Method == Method.GET))).Returns(restResponse3); MockRestClient.Setup(x => x.Execute(It.Is <RestRequest>(y => y.Resource.Contains("issues/3") && y.Method == Method.PATCH))).Returns(restResponse3); var issue4 = new GitHubIssues.Issue() { Id = 4, Number = 4, Title = "Issue 4", Body = "Issue 4", State = "Open" }; var restResponse4 = new RestResponse() { Content = serializer.SerializeToString(issue4), StatusCode = HttpStatusCode.OK }; MockRestClient.Setup(x => x.Execute(It.Is <RestRequest>(y => y.Resource.Contains("issues/4") && y.Method == Method.GET))).Returns(restResponse4); MockRestClient.Setup(x => x.Execute(It.Is <RestRequest>(y => y.Resource.Contains("issues/4") && y.Method == Method.PATCH))).Returns(restResponse4); }
protected override void OnArrange() { base.OnArrange(); MockLeanKitApi.Setup(x => x.GetBoard(It.IsAny <long>())).Returns(_testBoard); var serializer = new JsonSerializer <List <GitHubIssues.Issue> >(); var issue1 = new GitHubIssues.Issue() { Id = 1, Number = 1, State = "Open", Body = "New Issue 1", Title = "New Issue 1" }; var issue2 = new GitHubIssues.Issue() { Id = 2, Number = 2, State = "Open", Body = "New Issue 2", Title = "New Issue 2" }; var issue3 = new GitHubIssues.Issue() { Id = 3, Number = 3, State = "Open", Body = "New Issue 3", Title = "New Issue 3" }; var restResponse1 = new RestResponse() { Content = serializer.SerializeToString(new List <GitHubIssues.Issue>() { issue1 }), StatusCode = HttpStatusCode.OK }; var noRestResponse = new RestResponse() { StatusCode = HttpStatusCode.OK, Content = "" }; MockRestClient.Setup(x => x.Execute(It.Is <RestRequest>(y => y.Resource.Contains("/1/issues") && y.Method == Method.GET && y.Parameters[0].Value.ToString() == "Open"))).Returns(restResponse1); MockRestClient.Setup(x => x.Execute(It.Is <RestRequest>(y => y.Resource.Contains("/1/issues") && y.Method == Method.GET && y.Parameters[0].Value.ToString() != "Open"))).Returns(noRestResponse); MockLeanKitApi.Setup(x => x.GetCardByExternalId(1, It.IsAny <string>())).Returns((Card)null); MockLeanKitApi.Setup(x => x.AddCard(1, It.IsAny <Card>(), It.IsAny <string>())).Returns(_testCardAddResult1); MockRestClient.Setup(x => x.Execute(It.Is <RestRequest>(y => y.Resource.Contains("/2/issues") && y.Method == Method.GET && y.Parameters[0].Value.ToString() == "Open"))).Returns(restResponse1); MockRestClient.Setup(x => x.Execute(It.Is <RestRequest>(y => y.Resource.Contains("/2/issues") && y.Method == Method.GET && y.Parameters[0].Value.ToString() != "Open"))).Returns(noRestResponse); MockLeanKitApi.Setup(x => x.GetCardByExternalId(2, It.IsAny <string>())).Returns((Card)null); MockLeanKitApi.Setup(x => x.AddCard(2, It.IsAny <Card>(), It.IsAny <string>())).Returns(_testCardAddResult1); var restResponse3 = new RestResponse() { Content = serializer.SerializeToString(new List <GitHubIssues.Issue>() { issue1, issue2, issue3 }), StatusCode = HttpStatusCode.OK }; MockRestClient.Setup(x => x.Execute(It.Is <RestRequest>(y => y.Resource.Contains("/3/issues") && y.Method == Method.GET && y.Parameters[0].Value.ToString() == "Open"))).Returns(restResponse3); MockRestClient.Setup(x => x.Execute(It.Is <RestRequest>(y => y.Resource.Contains("/3/issues") && y.Method == Method.GET && y.Parameters[0].Value.ToString() != "Open"))).Returns(noRestResponse); MockLeanKitApi.Setup(x => x.GetCardByExternalId(3, It.IsAny <string>())).Returns((Card)null); MockLeanKitApi.Setup(x => x.AddCard(3, It.IsAny <Card>(), It.IsAny <string>())).Returns(_testCardAddResult1); MockRestClient.Setup(x => x.Execute(It.Is <RestRequest>(y => y.Resource.Contains("/4/issues") && y.Method == Method.GET && y.Parameters[0].Value.ToString() == "Open"))).Returns(restResponse1); MockRestClient.Setup(x => x.Execute(It.Is <RestRequest>(y => y.Resource.Contains("/4/issues") && y.Method == Method.GET && y.Parameters[0].Value.ToString() != "Open"))).Returns(noRestResponse); MockLeanKitApi.Setup(x => x.GetCardByExternalId(4, It.IsAny <string>())).Returns(new Card() { Id = 4, ExternalSystemName = "GitHub" }); MockLeanKitApi.Setup(x => x.AddCard(4, It.IsAny <Card>(), It.IsAny <string>())).Returns(_testCardAddResult1); MockRestClient.Setup(x => x.Execute(It.Is <RestRequest>(y => y.Resource.Contains("/5/issues") && y.Method == Method.GET && y.Parameters[0].Value.ToString() == "Open"))).Returns(restResponse1); MockRestClient.Setup(x => x.Execute(It.Is <RestRequest>(y => y.Resource.Contains("/5/issues") && y.Method == Method.GET && y.Parameters[0].Value.ToString() != "Open"))).Returns(noRestResponse); MockLeanKitApi.Setup(x => x.GetCardByExternalId(5, It.IsAny <string>())).Returns(new Card() { Id = 4, ExternalSystemName = "GitHubby" }); MockLeanKitApi.Setup(x => x.AddCard(5, It.IsAny <Card>(), It.IsAny <string>())).Returns(_testCardAddResult1); }
protected override void OnArrange() { base.OnArrange(); MockLeanKitApi.Setup(x => x.GetBoard(It.IsAny <long>())).Returns(_testBoard); var serializer = new JsonSerializer <Unfuddle.Ticket>(); var ticket1 = new Unfuddle.Ticket() { Id = 1, Status = "Open" }; var restResponse1 = new RestResponse() { Content = serializer.SerializeToString(ticket1), StatusCode = HttpStatusCode.OK }; MockRestClient.Setup(x => x.Execute(It.Is <RestRequest>(y => y.Resource.Contains("tickets/1") && y.Method == Method.GET))).Returns(restResponse1); MockRestClient.Setup(x => x.Execute(It.Is <RestRequest>(y => y.Resource.Contains("tickets/1") && y.Method == Method.PUT))).Returns(restResponse1); var ticket2 = new Unfuddle.Ticket() { Id = 2, Status = "Accepted" }; var restResponse2 = new RestResponse() { Content = serializer.SerializeToString(ticket2), StatusCode = HttpStatusCode.OK }; MockRestClient.Setup(x => x.Execute(It.Is <RestRequest>(y => y.Resource.Contains("tickets/2") && y.Method == Method.GET))).Returns(restResponse2); MockRestClient.Setup(x => x.Execute(It.Is <RestRequest>(y => y.Resource.Contains("tickets/2") && y.Method == Method.PUT))).Returns(restResponse2); var ticket3 = new Unfuddle.Ticket() { Id = 3, Status = "Open" }; var restResponse3 = new RestResponse() { Content = serializer.SerializeToString(ticket3), StatusCode = HttpStatusCode.OK }; MockRestClient.Setup(x => x.Execute(It.Is <RestRequest>(y => y.Resource.Contains("tickets/3") && y.Method == Method.GET))).Returns(restResponse3); MockRestClient.Setup(x => x.Execute(It.Is <RestRequest>(y => y.Resource.Contains("tickets/3") && y.Method == Method.PUT))).Returns(restResponse3); var ticket4 = new Unfuddle.Ticket() { Id = 4, Status = "Resolved" }; var restResponse4 = new RestResponse() { Content = serializer.SerializeToString(ticket4), StatusCode = HttpStatusCode.OK }; MockRestClient.Setup(x => x.Execute(It.Is <RestRequest>(y => y.Resource.Contains("tickets/4") && y.Method == Method.GET))).Returns(restResponse4); MockRestClient.Setup(x => x.Execute(It.Is <RestRequest>(y => y.Resource.Contains("tickets/4") && y.Method == Method.PUT))).Returns(restResponse4); }
protected override void OnArrange() { base.OnArrange(); MockLeanKitApi.Setup(x => x.GetBoard(It.IsAny <long>())).Returns(_testBoard); var serializer = new JsonSerializer <Unfuddle.TicketsResponse>(); var ticket1 = new Unfuddle.Ticket() { Id = 1, Status = "Open", Description = "Ticket 1", Summary = "Ticket 1" }; var ticket2 = new Unfuddle.Ticket() { Id = 2, Status = "Open", Description = "Ticket 2", Summary = "Ticket 2" }; var ticket3 = new Unfuddle.Ticket() { Id = 3, Status = "Open", Description = "Ticket 3", Summary = "Ticket 3" }; var group1 = new Unfuddle.Group() { Tickets = new List <Unfuddle.Ticket>() { ticket1 } }; var unfuddleResponse1 = new Unfuddle.TicketsResponse() { Count = 1, Groups = new List <Unfuddle.Group>() { group1 } }; var restResponse1 = new RestResponse() { Content = serializer.SerializeToString(unfuddleResponse1), StatusCode = HttpStatusCode.OK }; MockRestClient.Setup(x => x.Execute(It.Is <RestRequest>(y => y.Resource.Contains("projects/1/ticket_reports") && y.Method == Method.GET))).Returns(restResponse1); MockLeanKitApi.Setup(x => x.GetCardByExternalId(1, It.IsAny <string>())).Returns((Card)null); MockLeanKitApi.Setup(x => x.AddCard(1, It.IsAny <Card>(), It.IsAny <string>())).Returns(_testCardAddResult1); MockRestClient.Setup(x => x.Execute(It.Is <RestRequest>(y => y.Resource.Contains("projects/2/ticket_reports") && y.Method == Method.GET))).Returns(restResponse1); MockLeanKitApi.Setup(x => x.GetCardByExternalId(2, It.IsAny <string>())).Returns((Card)null); MockLeanKitApi.Setup(x => x.AddCard(2, It.IsAny <Card>(), It.IsAny <string>())).Returns(_testCardAddResult1); var group3 = new Unfuddle.Group() { Tickets = new List <Unfuddle.Ticket>() { ticket1, ticket2, ticket3 } }; var unfuddleResponse3 = new Unfuddle.TicketsResponse() { Count = 1, Groups = new List <Unfuddle.Group>() { group3 } }; var restResponse3 = new RestResponse() { Content = serializer.SerializeToString(unfuddleResponse3), StatusCode = HttpStatusCode.OK }; MockRestClient.Setup(x => x.Execute(It.Is <RestRequest>(y => y.Resource.Contains("projects/3/ticket_reports") && y.Method == Method.GET))).Returns(restResponse3); MockLeanKitApi.Setup(x => x.GetCardByExternalId(3, It.IsAny <string>())).Returns((Card)null); MockLeanKitApi.Setup(x => x.AddCard(3, It.IsAny <Card>(), It.IsAny <string>())).Returns(_testCardAddResult1); MockRestClient.Setup(x => x.Execute(It.Is <RestRequest>(y => y.Resource.Contains("projects/4/ticket_reports") && y.Method == Method.GET))).Returns(restResponse1); MockLeanKitApi.Setup(x => x.GetCardByExternalId(4, It.IsAny <string>())).Returns(new Card() { Id = 4, ExternalSystemName = "Unfuddle" }); MockLeanKitApi.Setup(x => x.AddCard(4, It.IsAny <Card>(), It.IsAny <string>())).Returns(_testCardAddResult1); MockRestClient.Setup(x => x.Execute(It.Is <RestRequest>(y => y.Resource.Contains("projects/5/ticket_reports") && y.Method == Method.GET))).Returns(restResponse1); MockLeanKitApi.Setup(x => x.GetCardByExternalId(5, It.IsAny <string>())).Returns(new Card() { Id = 4, ExternalSystemName = "Unfuddlest" }); MockLeanKitApi.Setup(x => x.AddCard(5, It.IsAny <Card>(), It.IsAny <string>())).Returns(_testCardAddResult1); }