public async Task Exception_Should_Be_Set() { var venue = new VenueEntity(); var vv = new VenueValidator(venue, (new GoogleGeo.GeoResponse { Success = false, Found = false, Exception = new ArgumentException(), GeoLocation = new GoogleGeo.GeoLocation { LocationType = GoogleGeo.LocationType.Approximate } }, new List <VenueDistanceResultRow>())); var factResult = await vv.CheckAsync(VenueValidator.FactId.CanBeLocated, CancellationToken.None); Assert.Multiple(() => { Assert.IsInstanceOf <ArgumentException>(vv.Data.GeoResponse.Exception); }); }
public async Task Address_Fields_Should_Be_Set(string postalCode, string city, string street, bool expected) { var venue = new VenueEntity { PostalCode = postalCode, City = city, Street = street }; var vv = new VenueValidator(venue, (new GoogleGeo.GeoResponse(), new List <VenueDistanceResultRow>())); var factResult = await vv.CheckAsync(VenueValidator.FactId.AddressFieldsAreSet, CancellationToken.None); Assert.Multiple(() => { Assert.IsTrue(factResult.Enabled); Assert.AreEqual(expected, factResult.Success); Assert.IsNull(factResult.Exception); }); }
public async Task StatusText_Should_Be_Set() { var venue = new VenueEntity(); var vv = new VenueValidator(venue, (new GoogleGeo.GeoResponse { Success = true, Found = true, StatusText = "OK", Exception = null, GeoLocation = new GoogleGeo.GeoLocation { LocationType = GoogleGeo.LocationType.Approximate } }, new List <VenueDistanceResultRow>())); var factResult = await vv.CheckAsync(VenueValidator.FactId.CanBeLocated, CancellationToken.None); Assert.Multiple(() => { Assert.AreEqual("OK", vv.Data.GeoResponse.StatusText); Assert.IsNull(vv.Data.GeoResponse.Exception); }); }
public async Task No_Close_By_Other_Venue(GoogleGeo.LocationType locationType, long venueId, bool isNew, bool emptyList, bool success) { var venue = new VenueEntity { Id = 1, IsNew = isNew }; var closeByVenues = new List <VenueDistanceResultRow> { new VenueDistanceResultRow { Id = 1, Distance = .3 }, new VenueDistanceResultRow { Id = 2, Distance = .4 }, new VenueDistanceResultRow { Id = 3, Distance = .7 }, new VenueDistanceResultRow { Id = 4, Distance = .9 } }; if (emptyList) { closeByVenues.Clear(); } var vv = new VenueValidator(venue, (new GoogleGeo.GeoResponse { Success = true, Found = true, GeoLocation = new GoogleGeo.GeoLocation { LocationType = locationType } }, closeByVenues)); var factResult = await vv.CheckAsync(VenueValidator.FactId.NotExistingGeoLocation, CancellationToken.None); Assert.Multiple(() => { Assert.IsTrue(factResult.Enabled); Assert.AreEqual(success, factResult.Success); if (!success) { Assert.IsTrue(factResult.Message.Contains((closeByVenues.Max(v => v.Distance) * 1000).ToString(CultureInfo.InvariantCulture))); } Assert.IsNull(factResult.Exception); }); }
public async Task Venue_Name_Should_Be_Set(string venueName, bool expected) { var venue = new VenueEntity { Name = venueName }; var vv = new VenueValidator(venue, (new GoogleGeo.GeoResponse(), new List <VenueDistanceResultRow>())); var factResult = await vv.CheckAsync(VenueValidator.FactId.NameIsSet, CancellationToken.None); Assert.Multiple(() => { Assert.IsTrue(factResult.Enabled); Assert.AreEqual(expected, factResult.Success); Assert.IsNull(factResult.Exception); }); }
public async Task No_Close_By_Other_Venue_Should_be_disabled(GoogleGeo.LocationType locationType, bool enabled) { var venue = new VenueEntity(); var vv = new VenueValidator(venue, (new GoogleGeo.GeoResponse { Success = true, Found = true, GeoLocation = new GoogleGeo.GeoLocation { LocationType = locationType } }, new List <VenueDistanceResultRow>())); var factResult = await vv.CheckAsync(VenueValidator.FactId.NotExistingGeoLocation, CancellationToken.None); Assert.Multiple(() => { Assert.AreEqual(factResult.Enabled, enabled); Assert.AreEqual(enabled, factResult.Success); Assert.IsNull(factResult.Exception); }); }
public async Task Position_should_be_found(GoogleGeo.LocationType locationType, bool expected) { var venue = new VenueEntity(); var vv = new VenueValidator(venue, (new GoogleGeo.GeoResponse { Success = true, Found = true, GeoLocation = new GoogleGeo.GeoLocation { LocationType = locationType } }, new List <VenueDistanceResultRow>())); var factResult = await vv.CheckAsync(VenueValidator.FactId.LocationIsPrecise, CancellationToken.None); Assert.Multiple(() => { Assert.IsTrue(factResult.Enabled); Assert.AreEqual(expected, factResult.Success); Assert.IsNull(factResult.Exception); }); }
public async Task Address_Should_Be_Locatable(bool found) { var venue = new VenueEntity(); var vv = new VenueValidator(venue, (new GoogleGeo.GeoResponse { Success = true, Found = found, StatusText = "OK", Exception = null, GeoLocation = new GoogleGeo.GeoLocation { LocationType = GoogleGeo.LocationType.Approximate } }, new List <VenueDistanceResultRow>())); var factResult = await vv.CheckAsync(VenueValidator.FactId.CanBeLocated, CancellationToken.None); Assert.Multiple(() => { Assert.IsTrue(factResult.Enabled); Assert.AreEqual(found, factResult.Success); Assert.IsNull(factResult.Exception); }); }
public async Task <bool> ValidateAsync(VenueValidator venueValidator, ModelStateDictionary modelState, CancellationToken cancellationToken) { await venueValidator.CheckAsync(cancellationToken); foreach (var fact in venueValidator.GetFailedFacts()) { if (fact.Exception != null) { throw new Exception(null, fact.Exception); } if (fact.Type == FactType.Critical || fact.Type == FactType.Error) { foreach (var fieldName in fact.FieldNames) { modelState.AddModelError(string.Join('.', Venue.HtmlFieldPrefix, fieldName), fact.Message); } } else { modelState.AddModelError(string.Empty, fact.Message); // Validator generates FactType.Warning only, if no errors exist IsWarning = true; } } // The Hash is re-calculated with the new submitted values. // We have to compare to the original hidden Hash field value, // because to override warnings, form fields must be unchanged since last post var newHash = ComputeInputHash(); if (IsWarning && OverrideWarnings && newHash == Hash) { modelState.Clear(); IsWarning = false; } if (!modelState.IsValid) { // Show checkbox unchecked OverrideWarnings = false; // Set hash field value to latest form fields content Hash = newHash; } return(modelState.IsValid); }
void Process() { if (executeUpload) { executeUpload = false; currentUploadService = null; if (!VenueValidator.ValidateVenue(out errorMessage)) { Debug.LogError(errorMessage); EditorUtility.DisplayDialog("ClusterVRSDK", errorMessage, "閉じる"); return; } try { AssetExporter.ExportCurrentSceneResource(venue.VenueId.Value, false); //Notice UnityPackage が大きくなりすぎてあげれないので一旦やめる } catch (Exception e) { errorMessage = $"現在のSceneのUnityPackage作成時にエラーが発生しました。 {e.Message}"; return; } currentUploadService = new UploadVenueService( userInfo.VerifiedToken, venue, () => errorMessage = "", exception => { errorMessage = $"会場データのアップロードに失敗しました。リトライしてみてください。 {exception.Message}"; EditorWindow.GetWindow <VenueUploadWindow>().Repaint(); }); currentUploadService.Run(); errorMessage = null; } }