Exemplo n.º 1
0
        public async Task Then_The_Mediator_Query_Is_Handled_And_Data_Returned(
            string postCode,
            string route,
            uint distance,
            GetAdvertsQueryResult queryResult,
            [Frozen] Mock <IMediator> mediator,
            [Greedy] AdvertsController controller)
        {
            //Arrange
            mediator.Setup(x => x.Send(It.Is <GetAdvertsQuery>(c =>
                                                               c.Distance.Equals(distance) &&
                                                               c.Postcode.Equals(postCode) &&
                                                               c.Route.Equals(route)
                                                               ), CancellationToken.None))
            .ReturnsAsync(queryResult);

            //Act
            var controllerResult = await controller.GetAdverts(postCode, route, distance) as ObjectResult;

            //Assert
            Assert.IsNotNull(controllerResult);
            controllerResult.StatusCode.Should().Be((int)HttpStatusCode.OK);
            var model = controllerResult.Value as GetAdvertsResponse;

            Assert.IsNotNull(model);
            model.Should().BeEquivalentTo((GetAdvertsResponse)queryResult);
        }
        public void Then_If_The_Employer_Is_Anonymous_Then_Anon_Employer_Name_Used(GetAdvertsQueryResult source, string anonEmployerName)
        {
            //Arrange
            foreach (var vacancy in source.Vacancies)
            {
                vacancy.IsEmployerAnonymous   = true;
                vacancy.AnonymousEmployerName = anonEmployerName;
            }

            //Act
            var actual = (GetAdvertsResponse)source;

            //Assert
            actual.Vacancies.ToList().TrueForAll(c =>
                                                 c.EmployerName.Equals(anonEmployerName)
                                                 ).Should().BeTrue();
        }
        public void Then_If_No_Location_Response_Returned_Then_Mapped(List <GetRoutesListItem> routes)
        {
            //Arrange
            var source = new GetAdvertsQueryResult
            {
                Location   = null,
                Routes     = routes,
                Vacancies  = new List <GetVacanciesListItem>(),
                TotalFound = 0
            };

            //Act
            var actual = (GetAdvertsResponse)source;

            //Assert
            actual.TotalFound.Should().Be(0);
            actual.Routes.Should().BeEquivalentTo(routes.Select(c => new { Route = c.Name }).ToList());
            actual.Vacancies.Should().BeEmpty();
            actual.Location.Should().BeNull();
        }
        public void Then_The_Fields_Are_Mapped_For_Non_Anon_Employer(GetAdvertsQueryResult source)
        {
            //Arrange
            foreach (var vacancy in source.Vacancies)
            {
                vacancy.IsEmployerAnonymous = false;
            }

            //Act
            var actual = (GetAdvertsResponse)source;

            //Assert
            actual.Routes.Should().BeEquivalentTo(source.Routes.Select(c => new { Route = c.Name }).ToList());
            actual.TotalFound.Should().Be(source.TotalFound);
            actual.Location.Should().BeEquivalentTo(source.Location);
            actual.Vacancies.Should()
            .BeEquivalentTo(source.Vacancies, options => options
                            .Excluding(c => c.AnonymousEmployerName)
                            .Excluding(c => c.IsEmployerAnonymous)
                            .Excluding(c => c.StandardLarsCode)
                            );
        }