public async Task Handle_AuthenticatedAndNoClusterFound_ThrowsClusterNotFoundException()
        {
            //Arrange
            var fakeMediator = Substitute.For <IMediator>();

            fakeMediator
            .Send(Arg.Any <GetClusterForUserQuery>())
            .Returns((Cluster)null);

            var fakeSlackClient = Substitute.For <ISlackClient>();

            var fakeProvisioningService = Substitute.For <IProvisioningService>();

            var handler = new DeployToClusterCommandHandler(
                fakeProvisioningService,
                fakeMediator,
                fakeSlackClient);

            //Assert
            var exception = await Assert.ThrowsExceptionAsync <ClusterNotFoundException>(async() =>
                                                                                         await handler.Handle(new DeployToClusterCommand(Array.Empty <string>())
            {
                UserId = Guid.NewGuid()
            }, default));

            //Assert
            Assert.IsNotNull(exception);
        }
        public async Task Handle_AuthenticatedAndClusterFound_DeploysToDemoCluster()
        {
            //Arrange
            var fakeUserId = Guid.NewGuid();

            var fakeMediator = Substitute.For <IMediator>();

            fakeMediator
            .Send(Arg.Any <GetClusterForUserQuery>())
            .Returns(new Cluster()
            {
                UserId    = fakeUserId,
                Instances = new List <Instance>()
                {
                    new Instance()
                    {
                        Name = "some-instance-name"
                    }
                }
            });

            var fakeSlackClient = Substitute.For <ISlackClient>();

            var fakeProvisioningService = Substitute.For <IProvisioningService>();

            var handler = new DeployToClusterCommandHandler(
                fakeProvisioningService,
                fakeMediator,
                fakeSlackClient);

            //Assert
            await handler.Handle(new DeployToClusterCommand(Array.Empty <string>())
            {
                UserId = fakeUserId
            }, default);

            //Assert
            await fakeProvisioningService
            .Received(1)
            .ScheduleJobAsync(Arg.Is <DeployToClusterStateFlow>(args =>
                                                                args.InstanceName == "some-instance-name"));
        }
        public async Task Handle_AuthenticatedAndDifferentAuthenticatedClusterFound_ThrowsException()
        {
            //Arrange
            var fakeMediator = Substitute.For <IMediator>();

            fakeMediator
            .Send(Arg.Any <GetClusterByIdQuery>())
            .Returns(new Cluster()
            {
                Id        = Guid.NewGuid(),
                Instances = new List <Instance>()
                {
                    new Instance()
                    {
                        Name = "some-instance-name"
                    }
                }
            });

            var fakeSlackClient = Substitute.For <ISlackClient>();

            var fakeProvisioningService = Substitute.For <IProvisioningService>();

            var handler = new DeployToClusterCommandHandler(
                fakeProvisioningService,
                fakeMediator,
                fakeSlackClient);

            //Assert
            var exception = await Assert.ThrowsExceptionAsync <NotAuthorizedToAccessClusterException>(async() =>
                                                                                                      await handler.Handle(new DeployToClusterCommand(Array.Empty <string>())
            {
                UserId    = Guid.NewGuid(),
                ClusterId = Guid.NewGuid()
            }, default));

            //Assert
            Assert.IsNotNull(exception);
        }