public async Task WhenRegisteringWithNonUniqueUsername_ItShouldThrowAnException()
        {
            await this.DatabaseTestAsync(async testDatabase =>
            {
                this.target = new RegisterUserDbStatement(this.userManager.Object, testDatabase, this.requestSnapshot);

                var hashedPassword = RegistrationData.Password + "1";
                this.passwordHasher.Setup(v => v.HashPassword(RegistrationData.Password.Value)).Returns(hashedPassword);

                await this.CreateUserAsync(testDatabase, RegistrationData.Username.Value, RegistrationData.Email + "1");

                await testDatabase.TakeSnapshotAsync();

                var exception = await ExpectedException.GetExceptionAsync <RecoverableException>(() =>
                {
                    return(this.target.ExecuteAsync(
                               UserId,
                               RegistrationData.Username,
                               RegistrationData.Email,
                               RegistrationData.ExampleWork,
                               RegistrationData.Password,
                               TimeStamp));
                });

                Assert.IsNotNull(exception);
                Assert.IsTrue(exception.Message.Contains("username"));

                return(ExpectedSideEffects.TransactionAborted);
            });
        }
Пример #2
0
        public async Task WhenGettingLandingPage_AndLandingPageDoesNotExist_ItShouldThrowHttpResponseExceptionWith404()
        {
            this.getLandingPage.Setup(v => v.HandleAsync(new GetLandingPageQuery(Username)))
            .Returns(Task.FromResult <GetLandingPageResult>(null)).Verifiable();

            var exception = await ExpectedException.GetExceptionAsync <HttpResponseException>(() => this.target.GetLandingPage(Username.Value));

            Assert.AreEqual(HttpStatusCode.NotFound, exception.Response.StatusCode);
            this.getLandingPage.Verify();
        }
Пример #3
0
        public async Task WhenGettingPost_AndPostIsNotFound_ItShouldThrowNotFoundException()
        {
            var timestamp = DateTime.UtcNow;

            this.timestampCreator.Setup(v => v.Now()).Returns(timestamp);
            this.requesterContext.Setup(_ => _.GetRequesterAsync()).ReturnsAsync(Requester);

            this.getPost.Setup(v => v.HandleAsync(new GetPostQuery(Requester, PostId, false, timestamp)))
            .ReturnsAsync(null)
            .Verifiable();

            var exception = await ExpectedException.GetExceptionAsync <HttpResponseException>(() => this.target.GetPost(PostId.Value.EncodeGuid()));

            Assert.AreEqual(HttpStatusCode.NotFound, exception.Response.StatusCode);
            this.getPost.Verify();
        }
Пример #4
0
        public async Task WhenCommitToTaxamoThrowsAnException_ItShouldStillCommitToDatabase_AndThrowWrappedException()
        {
            var tasks = new List <Func <Task> >();

            this.retryOnTransientFailure.Setup(v => v.HandleAsync(It.IsAny <Func <Task <InitializeCreditRequestResult> > >()))
            .Callback <Func <Task> >(tasks.Add)
            .ReturnsAsync(InitializeResult);

            this.retryOnTransientFailure.Setup(v => v.HandleAsync(It.IsAny <Func <Task <StripeTransactionResult> > >()))
            .Callback <Func <Task> >(tasks.Add)
            .ReturnsAsync(StripeTransactionResult);

            int callCount = 0;

            this.retryOnTransientFailure.Setup(v => v.HandleAsync(It.IsAny <Func <Task> >()))
            .Callback <Func <Task> >(tasks.Add)
            .Returns(() =>
            {
                if (callCount++ == 1)
                {
                    var tcs = new TaskCompletionSource <int>();
                    tcs.SetException(new DivideByZeroException());
                    return(tcs.Task);
                }

                return(Task.FromResult(0));
            });

            var exception = await ExpectedException.GetExceptionAsync <FailedToApplyCreditException>(
                () => this.target.ExecuteAsync(UserId, Now, TransactionReference, Amount, ExpectedTotalAmount, UserType.StandardUser));

            Assert.AreEqual(4, tasks.Count);

            Assert.IsNotNull(exception);
            Assert.IsTrue(
                exception.Message.Contains(StripeTransactionResult.StripeChargeId) &&
                exception.Message.Contains(StripeTransactionResult.TransactionReference.Value.ToString()) &&
                exception.Message.Contains(InitializeResult.TaxamoTransaction.Key) &&
                exception.Message.Contains(UserId.Value.ToString()));
        }