Beispiel #1
0
        public async Task And_Exception_Then_Returns_Bad_Request(
            string searchTerm,
            [Frozen] Mock <IMediator> mockMediator,
            [Greedy] LocationsController controller)
        {
            mockMediator
            .Setup(mediator => mediator.Send(
                       It.IsAny <GetLocationsQuery>(),
                       It.IsAny <CancellationToken>()))
            .Throws <InvalidOperationException>();

            var controllerResult = await controller.GetByQuery(searchTerm) as StatusCodeResult;

            controllerResult.StatusCode.Should().Be((int)HttpStatusCode.BadRequest);
        }
Beispiel #2
0
        public async Task Then_Passes_Query_To_Mediator_And_Returns_Locations(
            string searchTerm,
            GetLocationsQueryResponse queryResponse,
            [Frozen] Mock <IMediator> mockMediator,
            [Greedy] LocationsController controller)
        {
            //Arrange
            queryResponse.Locations = queryResponse.Locations.Select(c => { c.Postcode = null; return(c); }).ToList();

            mockMediator
            .Setup(mediator => mediator.Send(It.Is <GetLocationsQuery>(c => c.SearchTerm.Equals(searchTerm)), It.IsAny <CancellationToken>()))
            .ReturnsAsync(queryResponse);

            var actual = await controller.GetByQuery(searchTerm) as ObjectResult;

            actual.StatusCode.Should().Be((int)HttpStatusCode.OK);
            var model = actual.Value as GetLocationSearchResponse;

            model.Locations.Should().BeEquivalentTo(queryResponse.Locations, options => options.ExcludingMissingMembers());
        }