/// <summary> /// Удаляет из цели правило выбора страны /// </summary> /// <param name="target">Цель геолокации</param> /// <param name="country">Двухсимвольный код страны</param> public void RemoveCountryFromTarget(Target target, string country) { CountryRule rule = CountryRuleRepository.FindByTargetAndCountry(target, country); if (rule != null) { CountryRuleRepository.Delete(rule); } }
public void GivenValidateWhenCountryIsPolandThenReturnTrue() { var countryRule = new CountryRule(); var applicantRequest = new ApplicantRequest { Country = "Poland" }; var result = countryRule.Validate(applicantRequest); Assert.True(result); }
public void IsAllowed_WithBritishIPAddressAndUKCountryCode_ReturnsTrue() { var ukIPAddress = IPAddress.Parse("217.146.29.77"); var httpContext = new DefaultHttpContext(); httpContext.Connection.RemoteIpAddress = ukIPAddress; var rule = new CountryRule(new DenyAllRule(), new [] { CountryCode.GB }); var result = rule.IsAllowed(httpContext); Assert.True(result); }
public void IsAllowed_WithJapaneseIPAddressAndUKCountryCode_ReturnsFalse() { var japaneseIPAddress = IPAddress.Parse("161.202.65.101"); var httpContext = new DefaultHttpContext(); httpContext.Connection.RemoteIpAddress = japaneseIPAddress; var rule = new CountryRule(new DenyAllRule(), new [] { CountryCode.GB }); var result = rule.IsAllowed(httpContext); Assert.False(result); }
/// <summary> /// Добавляет к цели правило выбора страны /// </summary> /// <param name="target">Цель геолокации</param> /// <param name="country">Двухсимвольный код страны</param> /// <param name="kind">Вид правила включения</param> public void AddCountryToTarget(Target target, string country, RuleKind kind) { CountryRule rule = CountryRuleRepository.FindByTargetAndCountry(target, country); if (rule == null) { rule = new CountryRule() { TargetId = target.Id, Country = country, Kind = kind }; CountryRuleRepository.Create(rule); } else if (rule.Kind != kind) { rule.Kind = kind; CountryRuleRepository.Save(rule); } }