public void Should_initialize_with_namespace_specific_string_only() { var urn = Urn.Parse("urn:ns"); urn.Nid.Should().BeEmpty(); urn.Nss.Should().Be("ns"); }
public void Parse_ValidUrns_ReturnsUrn(string content, string namespaceSpecificString, string expectedContent) { Urn urn = Urn.Parse(content); urn.NamespaceIdentifier.Should().Be(namespaceSpecificString); urn.GetContent <RawNamespaceSpecificString>().ToString().Should().Be(expectedContent); }
public bool Should_indicate_that_urn_is_child(string parentValue, string childValue) { var parent = Urn.Parse(parentValue); var child = Urn.Parse(childValue); return(child.IsChildOf(parent)); }
public IEnumerable <AggregateCommit> Apply(AggregateCommit current) { if (ShouldApply(current)) { var urnRaw = Urn.Parse(Encoding.UTF8.GetString(current.AggregateRootId)); var urn = AggregateUrn.Parse(urnRaw.Value); var fooId = new FooId(urn.Id, urn.Tenant); LoadFromEventStore(fooId); aggregateMaxRevision[fooId]++; var newFooEvents = new List <IEvent>(); foreach (IEvent @event in current.Events) { if (@event.GetType() == typeof(TestCreateEventBar)) { newFooEvents.Add(new TestCreateEventFoo(fooId)); } else if (@event.GetType() == typeof(TestUpdateEventBar)) { var theEvent = @event as TestUpdateEventBar; newFooEvents.Add(new TestUpdateEventFoo(fooId, theEvent.UpdatedFieldValue)); } } var aggregateCommitFooBar = new AggregateCommit(fooId.RawId, aggregateMaxRevision[fooId], newFooEvents); yield return(aggregateCommitFooBar); } else { yield return(current); } }
public bool Should_indicate_that_urn_is_parent(string parentValue, string childValue) { var parent = Urn.Parse(parentValue); var child = Urn.Parse(childValue); return(parent.IsParentOf(child)); }
public void Update(Package pack) { Guard.IsNotNull(pack, nameof(pack)); Model = pack; // Set URN string urn = $"urn:{ChocolateyHandler.NAMESPACE_CHOCO}:{Model.Id}"; if (Model.Version != null) { urn += ":" + Model.Version.ToString(); } Urn = Urn.Parse(urn); // Set base properties Title = pack.Title; PackageId = pack.Id; DeveloperName = pack.AuthorName; ReleaseDate = pack.Created; Description = pack.Description; Version = pack.Version.ToString(); Website = Link.Create(pack.ProjectUrl, "Project website"); // Set Choco package properties Links = new[] { Link.Create(pack.DocsUrl, ShortTitle + " docs"), Link.Create(pack.BugTrackerUrl, ShortTitle + " bug tracker"), Link.Create(pack.PackageSourceUrl, ShortTitle + " source"), Link.Create(pack.MailingListUrl, ShortTitle + " mailing list"), }; }
public override ApiTaskResult <TResult, TFailureResult> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { using var jsonDocument = JsonDocument.ParseValue(ref reader); var taskId = jsonDocument.RootElement.GetProperty(propNames.IdPropName.AsUtf8()).GetGuid(); var taskStateValue = jsonDocument.RootElement.GetProperty(propNames.TaskStatePropName.AsUtf8()).GetString(); var taskState = (ApiTaskState)Enum.Parse(typeof(ApiTaskState), taskStateValue !, true); var taskTypeValue = jsonDocument.RootElement.GetProperty(propNames.TaskTypePropName.AsUtf8()).GetString(); var taskType = taskTypeValue == null ? null : Urn.Parse(taskTypeValue); switch (taskState) { case ApiTaskState.Running: return(ApiTaskResult <TResult, TFailureResult> .Running(taskId, taskType)); case ApiTaskState.Succeed: return(DeserializeResult(jsonDocument, taskStateValue, taskId, taskType, options)); case ApiTaskState.Failed: var errorJson = jsonDocument.RootElement.GetProperty(propNames.ApiErrorPropName.AsUtf8()).GetRawText(); var error = DeserializeAs <ApiError>(errorJson, propNames.ApiErrorPropName, taskStateValue, options); return(ApiTaskResult <TResult, TFailureResult> .TaskFailure(error, taskId, taskType)); default: throw Errors.UnexpectedEnumMember(nameof(taskState), taskState); } }
public void Should_serialize_URN_to_the_string_representation(string value) { var urn = Urn.Parse(value); var json = serializer.SerializeToIndentedString(urn); json.Should().Be(value.ToQuoted()); }
public void Should_initialize_with_full_urn_string() { var urn = Urn.Parse("urn:ns:val"); urn.Nid.Should().Be("ns"); urn.Nss.Should().Be("val"); }
public async Task <IActionResult> ExploreAsync([FromQuery] RequestModel model) { var projectionType = model.ProjectionName.GetTypeByContract(); ProjectionDto result = await _projectionExplorer.ExploreAsync(Urn.Parse(model.Id), projectionType).ConfigureAwait(false); return(new OkObjectResult(new ResponseResult <ProjectionDto>(result))); }
public (Type page, object parameter) ParseProtocol(Url ptcl) { Type destination = ResolveType("HomeView"); object parameter = null; (Type page, object parameter)defaultResult = (destination, null); if (ptcl == null || string.IsNullOrWhiteSpace(ptcl.Path)) { return(defaultResult); } try { switch (string.IsNullOrEmpty(ptcl.Host) ? ptcl.Path : ptcl.Host) { case "package": destination = ResolveType("PackageView"); parameter = Urn.Parse(ptcl.PathSegments[0]); break; case "web": destination = ResolveType("PackageView"); parameter = (Url)ptcl.Path.Substring(1); break; case "crash": destination = ResolveType("HttpErrorPage"); int code = 418; string message = null; if (ptcl.QueryParams.TryGetFirst("code", out object codeParam)) { int.TryParse(codeParam.ToString(), out code); } if (ptcl.QueryParams.TryGetFirst("msg", out object messageParam)) { message = Encoding.UTF8.GetString(Convert.FromBase64String(messageParam.ToString())); } if (ptcl.QueryParams.TryGetFirst("trace", out object traceParam)) { message += "\r\n" + Encoding.UTF8.GetString(Convert.FromBase64String(messageParam.ToString())); } parameter = (code, message); break; default: PageInfo pageInfo = Pages.Find(p => p.Path == ptcl.Host); destination = pageInfo?.PageType ?? ResolveType("HomeView"); parameter = ptcl.QueryParams; break; } } catch { return(defaultResult); } return(destination, parameter); }
public void Should_indicate_that_document_type_is_belong_to_namespace(string documentSuffix, string namespaceValue, bool expectedResult) { var @namespace = Urn.Parse(namespaceValue); DocumentType documentType = $"urn:document:{documentSuffix}"; documentType.IsBelongTo(@namespace).Should().Be(expectedResult); }
public void Should_fail_when_given_invalid_child(string child) { var parent = Urn.Parse("urn:ns"); Action action = () => _ = new Urn(parent, child); action.Should().Throw <ArgumentException>(); }
public void Should_fail_when_given_null_child() { var parent = Urn.Parse("urn:ns"); Action action = () => parent.IsParentOf(null !); action.Should().Throw <ArgumentException>(); }
public void Should_fail_when_given_null_parent() { var child = Urn.Parse("urn:ns:val"); Action action = () => child.IsChildOf(null !); action.Should().Throw <ArgumentException>(); }
public void Should_combine_urn_to_new_urn() { var parent = Urn.Parse("urn:ns"); var child = parent.Append("val"); child.ToString().Should().Be("urn:ns:val"); }
public void Should_fail_when_given_invalid_segment(string?segment) { var parent = Urn.Parse("urn:ns"); Action action = () => parent.Append(segment !); action.Should().Throw <ArgumentException>(); }
public IEnumerable <AggregateCommit> Apply(AggregateCommit current) { if (ShouldApply(current)) { var urnRaw = Urn.Parse(Encoding.UTF8.GetString(current.AggregateRootId)); var urn = AggregateUrn.Parse(urnRaw.Value); string currentAggregateName = urn.AggregateRootName; if (currentAggregateName == targetAggregateFoo) { var fooBarId = new FooBarId("1234", "elders"); var newFooBarEvents = new List <IEvent>(); foreach (IEvent @event in current.Events) { if (@event.GetType() == typeof(TestCreateEventFoo)) { newFooBarEvents.Add(new TestCreateEventFooBar(fooBarId)); } else if (@event.GetType() == typeof(TestUpdateEventFoo)) { var theEvent = @event as TestUpdateEventFoo; newFooBarEvents.Add(new TestUpdateEventFooBar(fooBarId, theEvent.UpdatedFieldValue)); } } HandleMaxRevision(fooBarId); var aggregateCommitFooBar = new AggregateCommit(fooBarId.RawId, aggregateMaxRevision[fooBarId], newFooBarEvents); yield return(aggregateCommitFooBar); } else { var fooBarId = new FooBarId("1234", "elders"); var newFooBarEvents = new List <IEvent>(); foreach (IEvent @event in current.Events) { if (@event.GetType() == typeof(TestCreateEventBar)) { newFooBarEvents.Add(new TestCreateEventFooBar(fooBarId)); } else if (@event.GetType() == typeof(TestUpdateEventBar)) { var theEvent = @event as TestUpdateEventBar; newFooBarEvents.Add(new TestUpdateEventFooBar(fooBarId, theEvent.UpdatedFieldValue)); } } HandleMaxRevision(fooBarId); var aggregateCommitFooBar = new AggregateCommit(fooBarId.RawId, aggregateMaxRevision[fooBarId], newFooBarEvents); yield return(aggregateCommitFooBar); } } else { yield return(current); } }
// TODO: Does this really belong here? public static bool TryParseUrn(string str, [NotNullWhen(true)] out Urn urn) { try { urn = Urn.Parse(str); return(true); } catch { urn = default; return(false); } }
public void Should_be_equality_comparable() { var urn = Urn.Parse("urn:ns:val"); var equal = Urn.Parse("urn:ns:val"); var notEqual = Urn.Parse("urn:ns:another"); var parent = Urn.Parse("urn:ns"); var anotherNs = Urn.Parse("urn:other:val"); urn.Should().BeEqualAndHasSameHashCode(equal); urn.Should().NotBeEqualAndHasDifferentHashCode(notEqual); urn.Should().NotBeEqualAndHasDifferentHashCode(parent); urn.Should().NotBeEqualAndHasDifferentHashCode(anotherNs); }
public bool ShouldApply(AggregateCommit current) { var urnRaw = Urn.Parse(Encoding.UTF8.GetString(current.AggregateRootId)); var urn = AggregateUrn.Parse(urnRaw.Value); string currentAggregateName = urn.AggregateRootName; if (currentAggregateName == targetAggregateName) { return(true); } return(false); }
public void Update(Package pack) { Guard.IsNotNull(pack, nameof(pack)); Model = pack; // Set base properties Urn = Urn.Parse($"urn:{WinGetHandler.NAMESPACE_WINGET}:{Model.Id}"); Title = pack.Latest.Name; PublisherId = pack.GetPublisherAndPackageIds().PublisherId; DeveloperName = pack.Latest.Publisher; ReleaseDate = pack.CreatedAt; Description = pack.Latest.Description; Version = pack.Versions[^ 1];
public async Task LoadFeaturedAsync() { try { WeakReferenceMessenger.Default.Send(new PageLoadingMessage(true)); var featured = await FSApi.GetHomePageFeaturedAsync(Windows.ApplicationModel.Package.Current.Id.Version.ToVersion()); CarouselItems.CollectionChanged += CarouselItems_CollectionChanged; CarouselItems.Clear(); for (int i = 0; i < featured.Carousel.Count; i++) { try { Urn packageUrn = Urn.Parse(featured.Carousel[i]); var package = await PackageService.GetPackageAsync(packageUrn); CarouselItems.Add(new PackageViewModel(package)); if (i == 0) { SelectedCarouselItemIndex = i; } } catch (System.Exception ex) { var logger = Ioc.Default.GetRequiredService <LoggerService>(); logger.Warn(ex, ex.Message); } } CarouselItems.CollectionChanged -= CarouselItems_CollectionChanged; // Load featured packages from other sources FeaturedPackages = new ObservableCollection <HandlerPackageListPair>(); await foreach (HandlerPackageListPair pair in PackageService.GetFeaturedPackagesAsync()) { FeaturedPackages.Add(pair); } } catch (Flurl.Http.FlurlHttpException ex) { NavService.ShowHttpErrorPage(ex); } catch (System.Exception ex) { var logger = Ioc.Default.GetRequiredService <LoggerService>(); logger.Warn(ex, ex.Message); } WeakReferenceMessenger.Default.Send(new PageLoadingMessage(false)); }
public void Update(Collection collection) { Guard.IsNotNull(collection, nameof(collection)); Model = collection; // Set base properties Title = collection.Name; PublisherId = collection.AuthorId; Urn = Urn.Parse($"urn:{FluentStoreHandler.NAMESPACE_COLLECTION}:{PublisherId}:{Model.Id}"); //ReleaseDate = collection.LastUpdateDateUtc; Description = collection.Description; ShortTitle = Title; // Determine if collection can be edited if (Handler.AccSvc.TryGetAuthenticatedHandler <Users.FluentStoreAccountHandler>(out var accHandler)) { CanEdit = accHandler.CurrentUser.Id == collection.AuthorId; } }
public override ApiTaskResult <TResult> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { using var jsonDocument = JsonDocument.ParseValue(ref reader); var taskId = jsonDocument.RootElement.GetProperty(propNames.IdPropName.AsUtf8()).GetGuid(); var taskStateValue = jsonDocument.RootElement.GetProperty(propNames.TaskStatePropName.AsUtf8()).GetString(); var taskState = (ApiTaskState)Enum.Parse(typeof(ApiTaskState), taskStateValue !, true); var taskTypeValue = jsonDocument.RootElement.GetProperty(propNames.TaskTypePropName.AsUtf8()).GetString(); var taskType = taskTypeValue == null ? null : Urn.Parse(taskTypeValue); switch (taskState) { case ApiTaskState.Running: return(ApiTaskResult <TResult> .Running(taskId, taskType)); case ApiTaskState.Succeed: var resultJson = jsonDocument.RootElement.GetProperty(propNames.TaskResultPropName.AsUtf8()).GetRawText(); var successResult = DeserializeAs <TResult>(resultJson, propNames.TaskResultPropName, taskStateValue); return(ApiTaskResult <TResult> .Success(successResult, taskId, taskType)); case ApiTaskState.Failed: var errorJson = jsonDocument.RootElement.GetProperty(propNames.ApiErrorPropName.AsUtf8()).GetRawText(); var error = DeserializeAs <ApiError>(errorJson, propNames.ApiErrorPropName, taskStateValue); return(ApiTaskResult <TResult> .TaskFailure(error, taskId, taskType)); default: throw Errors.UnexpectedEnumMember(nameof(taskState), taskState); } T DeserializeAs <T>(string json, in Utf8String propName, string?taskStatePropValue) { return(JsonSerializer.Deserialize <T>(json, options) ?? throw Errors.JsonPropertyCannotBeNullIfAnotherPropertyHasValue( propName.ToString(), propNames.TaskStatePropName.ToString(), taskStatePropValue)); } }
public async Task HandleAsync(NewProjectionVersionIsNowLive @event) { var projectionType = @event.ProjectionVersion.ProjectionName.GetTypeByContract(); if (projectionType.IsRebuildableProjection()) { var id = Urn.Parse($"urn:cronus:{@event.ProjectionVersion.ProjectionName}"); IAmEventSourcedProjection projection = cronusContext.ServiceProvider.GetRequiredService(projectionType) as IAmEventSourcedProjection; try { var asyncCommits = projectionStore.EnumerateProjectionAsync(@event.ProjectionVersion, id).ConfigureAwait(false); await foreach (var commit in asyncCommits) { await projection.ReplayEventAsync(commit.Event).ConfigureAwait(false); } } catch (Exception ex) { logger.ErrorException(ex, () => "Error while replaying projection."); } } }
public DocflowExtendedStatus(string urn) : this(Urn.Parse(urn)) { }
public DraftBuilderType(string urn) : this(Urn.Parse(urn)) { }
public DocflowType(string urn) : this(Urn.Parse(urn)) { }
public PfrLetterType(string urn) : this(Urn.Parse(urn)) { }