public async Task ProvisionPlan_PlanAndPaymentMethodPresent_InstanceProvisonedWithProperBundleId() { //Arrange var signedInUserId = Guid.NewGuid(); var fakeMediator = Substitute.For <IMediator>(); fakeMediator .Send(Arg.Is <GetPlanByIdQuery>(arg => arg.Id == "some-plan-id")) .Returns(new Plan( "some-bundle-id", 1337, new Bundle(), Array.Empty <PullDogPlan>())); fakeMediator .Send(Arg.Is <GetActivePaymentMethodForUserQuery>(arg => arg.User.Id == signedInUserId)) .Returns(new PaymentMethod()); fakeMediator .Send(Arg.Is <EnsureUserForIdentityCommand>( args => args.IdentityName == "some-identity-name")) .Returns(new User() { Id = signedInUserId }); var fakeMapper = Substitute.For <IMapper>(); var controller = new PlansController( fakeMapper, fakeMediator); controller.FakeAuthentication("some-identity-name"); //Act await controller.ProvisionPlan("some-plan-id"); //Assert await fakeMediator .Received(1) .Send(Arg.Is <ProvisionInstanceForUserCommand>(arg => arg.Plan.Id == "some-bundle-id" && arg.User.Id == signedInUserId)); }
public async Task ProvisionPlan_PlanAndNoPaymentMethodPresent_ReturnsValidationError() { //Arrange var signedInUserId = Guid.NewGuid(); var fakeMediator = Substitute.For <IMediator>(); fakeMediator .Send(Arg.Is <GetPlanByIdQuery>(arg => arg.Id == "some-plan-id")) .Returns(new Plan( "some-bundle-id", 1337, new Bundle(), Array.Empty <PullDogPlan>())); fakeMediator .Send(Arg.Is <EnsureUserForIdentityCommand>( args => args.IdentityName == "some-identity-name")) .Returns(new User() { Id = signedInUserId }); var mapper = AutoMapperFactory.CreateValidMapper(); var controller = new PlansController( mapper, fakeMediator); controller.FakeAuthentication("some-identity-name"); //Act var response = await controller.ProvisionPlan("some-plan-id") as BadRequestObjectResult; //Assert Assert.IsNotNull(response); var value = response.Value as ValidationProblemDetails; Assert.IsNotNull(value); Assert.AreEqual("NO_PAYMENT_METHOD", value.Type); }
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)); }
public async Task ProvisionPlan_PaymentMethodAndNoPlanPresent_ReturnsValidationError() { //Arrange var signedInUserId = Guid.NewGuid(); var fakeMediator = Substitute.For <IMediator>(); fakeMediator .Send(Arg.Is <GetActivePaymentMethodForUserQuery>(arg => arg.User.Id == signedInUserId)) .Returns(new PaymentMethod()); fakeMediator .Send(Arg.Is <EnsureUserForIdentityCommand>( args => args.IdentityName == "some-identity-name")) .Returns(new User() { Id = signedInUserId }); var mapper = AutoMapperFactory.CreateValidMapper(); var controller = new PlansController( mapper, fakeMediator); controller.FakeAuthentication("some-identity-name"); //Act var response = await controller.ProvisionPlan("some-plan-id") as BadRequestObjectResult; //Assert Assert.IsNotNull(response); var value = response.Value as ValidationProblemDetails; Assert.IsNotNull(value); Assert.AreEqual("PLAN_NOT_FOUND", value.Type); }