예제 #1
0
        public async Task GetLoanByIdShouldReturn400WhenNoIdSpecified()
        {
            var resolver = TestSasServices.DefaultServiceCollection()
                           .WithDefaultFunctionHandlers()
                           .BuildServiceProvider();

            var handler = resolver.GetRequiredService <GetLoanByIdHandler>();
            var request = new ApiGatewayProxyRequestBuilder()
                          .Build();

            var response = await handler.HandleAsync(request, new TestLambdaContext());

            response
            .ShouldHaveStatusCode(400)
            .Body.ShouldBeParseableAs <ErrorResponse>()
            .StatusCode.ShouldBe(400);
        }
예제 #2
0
        public async Task GetItemReShouldReturn404WhenNoItemAvailable()
        {
            var testItems = AutoFaker.Generate <Item>(50);
            var resolver  = TestSasServices.DefaultServiceCollection()
                            .WithDefaultFunctionHandlers()
                            .WithTestItems(testItems)
                            .BuildServiceProvider();

            var handler = resolver.GetRequiredService <GetItemByIdHandler>();
            var request = new ApiGatewayProxyRequestBuilder()
                          .WithPathParameter("id", Guid.NewGuid().ToString())
                          .Build();

            var response = await handler.HandleAsync(request, new TestLambdaContext());

            response
            .ShouldHaveStatusCode(404)
            .Body
            .ShouldBeNull();
        }
        public async Task TestGetItemsHandler(IEnumerable <Item> items)
        {
            var resolver = TestSasServices
                           .DefaultServiceCollection()
                           .WithDefaultFunctionHandlers()
                           .WithTestItems(items)
                           .BuildServiceProvider();

            var handler = resolver.GetRequiredService <GetItemsHandler>();

            var request       = new ApiGatewayProxyRequestBuilder().Build();
            var lambdaContext = new TestLambdaContext();
            var response      = await handler.HandleAsync(request, lambdaContext);

            response
            .ShouldHaveStatusCode(200)
            .ShouldHaveHeader("Content-Type", "application/json")
            .Body
            .ShouldBeParseableAs <IList <Item> >()
            .ShouldDeepEqual(items);
        }
        public async Task GetLoanByStatusTest()
        {
            var testLoans = AutoFaker.Generate <Loan>(50);
            const LoanStatus loanStatus = LoanStatus.Approved;
            var expectedLoans           = testLoans.Where(x => x.Status == loanStatus).ToList();

            var resolver = TestSasServices.DefaultServiceCollection()
                           .WithDefaultFunctionHandlers()
                           .WithTestLoans(testLoans)
                           .BuildServiceProvider();

            var handler = resolver.GetRequiredService <GetLoansByStatusHandler>();
            var request = new ApiGatewayProxyRequestBuilder()
                          .WithPathParameter("status", loanStatus.ToString())
                          .Build();

            var response = await handler.HandleAsync(request, new TestLambdaContext());

            response
            .ShouldHaveStatusCode(200)
            .Body
            .ShouldBeParseableAs <List <Loan> >()
            .ShouldDeepEqual(expectedLoans);
        }
예제 #5
0
        public async Task GetItemReShouldReturn200WithFoundItem()
        {
            var items = new AutoFaker <Item>()
                        .RuleFor(x => x.Id, x => x.UniqueIndex.ToString()) //can sometimes get duplicates, so force unique indexes
                        .Generate(50);
            var item = items[new Random().Next(0, items.Count)];

            var resolver = TestSasServices.DefaultServiceCollection()
                           .WithDefaultFunctionHandlers()
                           .WithTestItems(items)
                           .BuildServiceProvider();

            var handler  = resolver.GetRequiredService <GetItemByIdHandler>();
            var request  = new ApiGatewayProxyRequestBuilder().WithPathParameter("id", item.Id).Build();
            var response = await handler.HandleAsync(request, new TestLambdaContext());

            response
            .ShouldHaveStatusCode(200)
            .ShouldHaveHeader("Content-Type", "application/json")
            .ShouldHaveHeader("Access-Control-Allow-Origin", "*")
            .Body
            .ShouldBeParseableAs <Item>()
            .ShouldDeepEqual(item);
        }