コード例 #1
0
    public async Task Step_Validate_Wrong_Postcode()
    {
        const string postcode  = "dddfd";
        const double latitude  = 50.0123;
        const double longitude = 1.987;
        const bool   isValid   = false;

        var postcodeLocation = new PostcodeLocation
        {
            Postcode  = postcode,
            Latitude  = latitude,
            Longitude = longitude
        };

        var viewModel = new FindViewModel
        {
            Postcode = postcode
        };

        var context = new SearchContext(viewModel);

        _providerSearchService.IsSearchPostcodeValid(Arg.Is <string>(p => p == postcode)).Returns((isValid, postcodeLocation));

        await _searchStep.Execute(context);

        context.ViewModel.ValidationStyle.Should().Be(AppConstants.ValidationStyle);
        context.ViewModel.PostcodeValidationMessage.Should().Be(AppConstants.RealPostcodeValidationMessage);
        context.Continue.Should().BeFalse();
        await _providerSearchService.Received(1).IsSearchPostcodeValid(Arg.Is <string>(p => p == postcode));
    }
コード例 #2
0
    public async Task Execute(ISearchContext context)
    {
        if (string.IsNullOrEmpty(context.ViewModel.Postcode))
        {
            context.ViewModel.PostcodeValidationMessage = AppConstants.PostcodeValidationMessage;
        }
        else
        {
            var(isValid, postcodeLocation) = await _providerSearchService.IsSearchPostcodeValid(context.ViewModel.Postcode);

            if (isValid)
            {
                context.ViewModel.Postcode  = postcodeLocation.Postcode;
                context.ViewModel.Latitude  = postcodeLocation.Latitude.HasValue ? postcodeLocation.Latitude.Value.ToString(CultureInfo.InvariantCulture) : "";
                context.ViewModel.Longitude = postcodeLocation.Longitude.HasValue ? postcodeLocation.Longitude.Value.ToString(CultureInfo.InvariantCulture) : "";
            }
            else
            {
                context.ViewModel.PostcodeValidationMessage = AppConstants.RealPostcodeValidationMessage;
            }
        }

        if (!string.IsNullOrEmpty(context.ViewModel.PostcodeValidationMessage))
        {
            context.ViewModel.ValidationStyle = AppConstants.ValidationStyle;
            context.Continue = false;
        }
    }
    public async Task IsSearchPostcodeValid_Validates_Postcode_Via_Service(string postcode, bool expected)
    {
        _distanceCalculationService
        .IsPostcodeValid(postcode)
        .Returns((expected, new PostcodeLocation {
            Postcode = postcode
        }));

        var(isValid, postcodeLocation) = await _service.IsSearchPostcodeValid(postcode);

        isValid.Should().Be(expected);
        postcodeLocation.Should().NotBeNull();
        postcodeLocation.Postcode.Should().Be(postcode);

        await _distanceCalculationService
        .Received(1)
        .IsPostcodeValid(postcode);
    }