public async Task Provision_PullRequestInferredFromCommitReference_ProvisionsPullDogEnvironment() { //Arrange var fakeMediator = Substitute.For <IMediator>(); fakeMediator .Send(Arg.Is <GetRepositoryByHandleQuery>(args => args.RepositoryHandle == "some-repository-handle")) .Returns(new PullDogRepository() { PullDogSettings = new PullDogSettings() }); fakeMediator .Send(Arg.Is <GetPullRequestHandleFromCommitReferenceQuery>(args => args.CommitReference == "some-commit-reference")) .Returns("some-inferred-pull-request-handle"); var fakeMapper = Substitute.For <IMapper>(); var fakeAesEncryptionHelper = Substitute.For <IAesEncryptionHelper>(); fakeAesEncryptionHelper .DecryptAsync(Arg.Any <byte[]>()) .Returns("dummy"); var controller = new PullDogApiController( fakeMediator, fakeMapper, fakeAesEncryptionHelper); //Act var result = await controller.Provision(new ProvisionRequest() { RepositoryHandle = "some-repository-handle", CommitReference = "some-commit-reference", ApiKey = "dummy" }) as OkResult; //Assert Assert.IsNotNull(result); await fakeMediator .Received(1) .Send(Arg.Is <ProvisionPullDogEnvironmentCommand>(args => args.PullRequestHandle == "some-inferred-pull-request-handle")); }
public async Task Provision_OnlyCommitReferenceSpecifiedAndPullRequestNotInferred_ReturnsNotFound() { //Arrange var fakeMediator = Substitute.For <IMediator>(); fakeMediator .Send(Arg.Is <GetRepositoryByHandleQuery>(args => args.RepositoryHandle == "some-repository-handle")) .Returns(new PullDogRepository() { PullDogSettings = new PullDogSettings() }); fakeMediator .Send(Arg.Is <GetPullRequestHandleFromCommitReferenceQuery>(args => args.CommitReference == "some-commit-reference")) .Returns((string)null); var fakeMapper = Substitute.For <IMapper>(); var fakeAesEncryptionHelper = Substitute.For <IAesEncryptionHelper>(); fakeAesEncryptionHelper .DecryptAsync(Arg.Any <byte[]>()) .Returns("dummy"); var controller = new PullDogApiController( fakeMediator, fakeMapper, fakeAesEncryptionHelper); //Act var result = await controller.Provision(new ProvisionRequest() { RepositoryHandle = "some-repository-handle", CommitReference = "some-commit-reference", ApiKey = "dummy" }) as NotFoundObjectResult; //Assert Assert.IsNotNull(result); }
public async Task Provision_RepositoryNotFound_ReturnsNotFound() { //Arrange var fakeMediator = Substitute.For <IMediator>(); var fakeMapper = Substitute.For <IMapper>(); var fakeAesEncryptionHelper = Substitute.For <IAesEncryptionHelper>(); var controller = new PullDogApiController( fakeMediator, fakeMapper, fakeAesEncryptionHelper); //Act var result = await controller.Provision(new ProvisionRequest() { PullRequestHandle = "dummy" }) as NotFoundObjectResult; //Assert Assert.IsNotNull(result); }
public async Task Provision_PullRequestHandleAndCommitReferenceMissing_ReturnsBadRequest() { //Arrange var fakeMediator = Substitute.For <IMediator>(); var fakeMapper = Substitute.For <IMapper>(); var fakeAesEncryptionHelper = Substitute.For <IAesEncryptionHelper>(); var controller = new PullDogApiController( fakeMediator, fakeMapper, fakeAesEncryptionHelper); //Act var result = await controller.Provision(new ProvisionRequest() { PullRequestHandle = null, CommitReference = null }) as BadRequestObjectResult; //Assert Assert.IsNotNull(result); }
public async Task Provision_EncryptedApiKeyIsWrong_ReturnsUnauthorized() { //Arrange var fakeMediator = Substitute.For <IMediator>(); fakeMediator .Send(Arg.Is <GetRepositoryByHandleQuery>(args => args.RepositoryHandle == "some-repository-handle")) .Returns(new PullDogRepository() { PullDogSettings = new PullDogSettings() }); var fakeMapper = Substitute.For <IMapper>(); var fakeAesEncryptionHelper = Substitute.For <IAesEncryptionHelper>(); fakeAesEncryptionHelper .DecryptAsync(Arg.Any <byte[]>()) .Returns("some-decrypted-value"); var controller = new PullDogApiController( fakeMediator, fakeMapper, fakeAesEncryptionHelper); //Act var result = await controller.Provision(new ProvisionRequest() { RepositoryHandle = "some-repository-handle", PullRequestHandle = "dummy", ApiKey = "wrong-api-key" }) as UnauthorizedObjectResult; //Assert Assert.IsNotNull(result); }