示例#1
0
        public async Task CreateRepository_ShouldCallCorrectUrlAndMethod()
        {
            var inputRepository = new Repository()
            {
                IsPrivate = true,
                Name      = "Test111"
            };

            var responseJson = Utilities.LoadFile(Paths.GetEnterpriseDataPath("CreateRepositoryResponse.json"));
            var responseData = new NewtonsoftJsonSerializer().Deserialize <EnterpriseRepository>(responseJson);

            var response = MockRepository.GenerateMock <IRestResponse <EnterpriseRepository> >();

            response.Stub(x => x.Data).Return(responseData);

            var result = _restClient
                         .Capture()
                         .Args <IRestRequest, IRestResponse <EnterpriseRepository> >((s, req) => s.ExecuteTaskAsync <EnterpriseRepository>(req), response);

            var repository = await _sut.CreateRepository(inputRepository);

            Assert.AreEqual(1, result.CallCount);

            var args = result.Args[0];

            Assert.Multiple(() =>
            {
                Assert.AreEqual("users/Login/repos", args.Resource);
                Assert.AreEqual(Method.POST, args.Method);

                var body             = args.Parameters.First(x => x.Type == ParameterType.RequestBody);
                var expectedJsonBody = Utilities.LoadFile(Paths.GetEnterpriseDataPath("CreateRepositoryRequest.json"));

                Assert.AreEqual(expectedJsonBody, body.Value.ToString());

                Assert.AreEqual("NEWREPOSITORY", repository.Name);
                Assert.AreEqual(true, repository.IsPrivate);
            });
        }
示例#2
0
        public async Task ApprovePullRequest_ShouldReturnValidParticipant()
        {
            var responseJson = Utilities.LoadFile(Paths.GetEnterpriseDataPath("ApprovePullRequestResponse.json"));
            var responseData = new NewtonsoftJsonSerializer().Deserialize <EnterpriseParticipant>(responseJson);

            var response = MockRepository.GenerateMock <IRestResponse <EnterpriseParticipant> >();

            response.Stub(x => x.Data).Return(responseData);

            var result = _restClient
                         .Capture()
                         .Args <IRestRequest, IRestResponse <EnterpriseParticipant> >((s, req) => s.ExecuteTaskAsync <EnterpriseParticipant>(req), response);

            var participant = await _sut.ApprovePullRequest("repoName", "owner", 1);

            Assert.AreEqual(1, result.CallCount);

            var args = result.Args[0];

            Assert.Multiple(() =>
            {
                Assert.AreEqual("projects/owner/repos/repoName/pull-requests/1/approve", args.Resource);
                Assert.AreEqual(Method.POST, args.Method);

                Assert.AreEqual(true, participant.Approved);
                Assert.AreEqual("REVIEWER", participant.Role);
                Assert.AreEqual("TestUser", participant.User.UserName);
                Assert.AreEqual("TestUser", participant.User.DisplayName);
            });
        }