Exemplo n.º 1
0
        public async Task ProvisionDemo_DemoPlanPresentGiven_DemoInstanceProvisonedWithProperBundleId()
        {
            //Arrange
            var fakeMediator = Substitute.For <IMediator>();

            fakeMediator
            .Send(Arg.Any <GetDemoPlanQuery>())
            .Returns(new Plan(
                         "some-bundle-id",
                         1337,
                         new Bundle(),
                         Array.Empty <PullDogPlan>()));

            var fakeMapper = Substitute.For <IMapper>();

            var controller = new PlansController(
                fakeMapper,
                fakeMediator);

            //Act
            await controller.ProvisionDemo();

            //Assert
            await fakeMediator
            .Received(1)
            .Send(Arg.Any <ProvisionDemoInstanceCommand>());
        }
Exemplo n.º 2
0
        public async Task ProvisionDemo_DemoAlreadyProvisioned_ReturnsValidationError()
        {
            //Arrange
            var fakeMediator = Substitute.For <IMediator>();

            fakeMediator
            .Send(Arg.Any <GetDemoPlanQuery>())
            .Returns(new Plan(
                         "some-bundle-id",
                         1337,
                         new Bundle(),
                         Array.Empty <PullDogPlan>()));

            fakeMediator
            .Send(Arg.Any <ProvisionDemoInstanceCommand>())
            .Throws(new DemoInstanceAlreadyProvisionedException());

            var mapper = AutoMapperFactory.CreateValidMapper();

            var controller = new PlansController(
                mapper,
                fakeMediator);

            //Act
            var result = await controller.ProvisionDemo();

            //Assert
            var validationProblem = result.GetValidationProblemDetails();

            Assert.AreEqual("ALREADY_PROVISIONED", validationProblem.Type);
        }
Exemplo n.º 3
0
        public async Task ProvisionDemo_AuthenticatedUser_PassesAuthenticatedUserIdToProvisionDemoInstanceCommand()
        {
            //Arrange
            var fakeMediator = Substitute.For <IMediator>();

            fakeMediator
            .Send(Arg.Any <GetDemoPlanQuery>())
            .Returns(new Plan(
                         "some-bundle-id",
                         1337,
                         new Bundle(),
                         Array.Empty <PullDogPlan>()));

            var fakeAuthenticatedUserId = Guid.NewGuid();

            fakeMediator
            .Send(Arg.Is <EnsureUserForIdentityCommand>(
                      args => args.IdentityName == "some-identity-name"))
            .Returns(new User()
            {
                Id = fakeAuthenticatedUserId
            });

            var fakeMapper = Substitute.For <IMapper>();

            var controller = new PlansController(
                fakeMapper,
                fakeMediator);

            controller.FakeAuthentication("some-identity-name");

            //Act
            var result = await controller.ProvisionDemo();

            //Assert
            result.AssertSuccessfulStatusCode();

            await fakeMediator
            .Received(1)
            .Send(Arg.Is <ProvisionDemoInstanceCommand>(arg =>
                                                        arg.AuthenticatedUserId == fakeAuthenticatedUserId));
        }