public static async Task InitializeAsync(UserManager <ApplicationUser> userManager, ICommandDispatcher commands) { IdentityResult userResult = await userManager.CreateAsync( new ApplicationUser(ClaimsPrincipalExtensions.DemoUserName), ClaimsPrincipalExtensions.DemoUserPassword ); if (!userResult.Succeeded) { throw Ensure.Exception.InvalidOperation("Unnable to create demo user."); } ApplicationUser user = await userManager.FindByNameAsync(ClaimsPrincipalExtensions.DemoUserName); if (user == null) { throw Ensure.Exception.InvalidOperation("Unnable find created demo user."); } IKey userKey = StringKey.Create(user.Id, "User"); await commands.HandleAsync(WrapCommand(userKey, new CreateCurrency("USD", "$"))); await commands.HandleAsync(WrapCommand(userKey, new CreateCategory("Car", "Gas etc.", Color.FromArgb(255, 145, 206, 234)))); await commands.HandleAsync(WrapCommand(userKey, new CreateCategory("Home", "DIY", Color.FromArgb(255, 207, 180, 141)))); await commands.HandleAsync(WrapCommand(userKey, new CreateCategory("Food", "Ingredients for home made meals", Color.FromArgb(255, 155, 237, 144)))); }
public async Task <IHttpActionResult> Post(string boardSlug, BoardTask boardTask) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var result = await commandDispatcher.HandleAsync <CreateBoardTaskCommand, BoardTask>(new CreateBoardTaskCommand { BoardSlug = boardSlug, BoardTask = boardTask }); hyperMediaFactory.Apply(result); return(Created(hyperMediaFactory.GetLink(result, Link.SELF), result)); } catch (BoardColumnNotFoundException) { return(BadRequest("Board Column Not Found")); } catch (BoardNotFoundException) { return(NotFound()); } }
public async void ReverseVerticalAlligmentInContainerInJ2_ShouldSucceed() { var utilityNetwork = _eventStore.Projections.Get <UtilityNetworkProjection>(); var sutNodeContainerId = TestUtilityNetwork.NodeContainer_J_1; utilityNetwork.TryGetEquipment <NodeContainer>(sutNodeContainerId, out var nodeContainerBeforeFlip); var reverseCmd = new ReverseNodeContainerVerticalContentAlignment(sutNodeContainerId); var reverseResult = await _commandDispatcher.HandleAsync <ReverseNodeContainerVerticalContentAlignment, Result>(reverseCmd); var equipmentQueryResult = await _queryDispatcher.HandleAsync <GetEquipmentDetails, Result <GetEquipmentDetailsResult> >( new GetEquipmentDetails(new InterestIdList() { nodeContainerBeforeFlip.InterestId }) ); // Assert nodeContainerBeforeFlip.VertialContentAlignmemt.Should().Be(NodeContainerVerticalContentAlignmentEnum.Bottom); reverseResult.IsSuccess.Should().BeTrue(); equipmentQueryResult.IsSuccess.Should().BeTrue(); equipmentQueryResult.Value.NodeContainers[sutNodeContainerId].VertialContentAlignmemt.Should().Be(NodeContainerVerticalContentAlignmentEnum.Top); // Check if an event is published to the notification.utility-network topic having an idlist containing the node container we just changed var utilityNetworkNotifications = _externalEventProducer.GetMessagesByTopic("notification.utility-network").OfType <RouteNetworkElementContainedEquipmentUpdated>(); var utilityNetworkUpdatedEvent = utilityNetworkNotifications.First(n => n.Category == "EquipmentModification" && n.IdChangeSets != null && n.IdChangeSets.Any(i => i.IdList.Any(i => i == sutNodeContainerId))); utilityNetworkUpdatedEvent.AffectedRouteNetworkElementIds.Should().Contain(TestRouteNetwork.J_1); }
public async void AddSpanStructureSpecificationTest() { // Setup var spec1 = new SpanStructureSpecification(Guid.NewGuid(), "Conduit", "Ø12", "Red") { OuterDiameter = 12, InnerDiameter = 10 }; var spec2 = new SpanStructureSpecification(Guid.NewGuid(), "Conduit", "Ø50", "Red") { OuterDiameter = 50, InnerDiameter = 45 }; // Act var cmd1 = new AddSpanStructureSpecification(spec1); Result cmd1Result = await _commandDispatcher.HandleAsync <AddSpanStructureSpecification, Result>(cmd1); var cmd2 = new AddSpanStructureSpecification(spec2); Result cmd2Result = await _commandDispatcher.HandleAsync <AddSpanStructureSpecification, Result>(cmd2); var spanStructureSpecificationsQueryResult = await _queryDispatcher.HandleAsync <GetSpanStructureSpecifications, Result <LookupCollection <SpanStructureSpecification> > >(new GetSpanStructureSpecifications()); // Assert cmd1Result.IsSuccess.Should().BeTrue(); cmd2Result.IsSuccess.Should().BeTrue(); spanStructureSpecificationsQueryResult.IsSuccess.Should().BeTrue(); spanStructureSpecificationsQueryResult.Value[spec1.Id].Should().BeEquivalentTo(spec1); spanStructureSpecificationsQueryResult.Value[spec2.Id].Should().BeEquivalentTo(spec2); }
public void EnqueueCreateInvoice(int invoiceId) { BackgroundJob.Enqueue(() => _commandDispatcher.HandleAsync( new CreateExternalInvoiceCommand { InvoiceId = invoiceId }, CancellationToken.None)); }
private async void AddSpecification(SpanEquipmentSpecification spec) { var cmd = new AddSpanEquipmentSpecification(spec); var cmdResult = await _commandDispatcher.HandleAsync <AddSpanEquipmentSpecification, Result>(cmd); if (cmdResult.IsFailed) { throw new ApplicationException(cmdResult.Errors.First().Message); } }
private async Task CreateDefaultCategoriesAsync() { await commandDispatcher.HandleAsync(new CreateCategory("Bills", "Regular expenses", ColorConverter.Map(Colors.DarkGreen))); await commandDispatcher.HandleAsync(new CreateCategory("Home", "Do it yourself", ColorConverter.Map(Colors.SandyBrown))); await commandDispatcher.HandleAsync(new CreateCategory("Food", "Home cooked meals", ColorConverter.Map(Colors.OrangeRed))); await commandDispatcher.HandleAsync(new CreateCategory("Eating Out", "Outsourcing food creation", ColorConverter.Map(Colors.DarkRed))); }
private async Task AddSpecification(SpanEquipmentSpecification spec) { var cmd = new AddSpanEquipmentSpecification(Guid.NewGuid(), new UserContext("test", Guid.Empty), spec); var cmdResult = await _commandDispatcher.HandleAsync <AddSpanEquipmentSpecification, Result>(cmd); if (cmdResult.IsFailed) { throw new ApplicationException(cmdResult.Errors.First().Message); } }
public async void ValidateValidWalk_ShouldSucceed() { var walk = new RouteNetworkElementIdList() { TestRouteNetwork.S2, TestRouteNetwork.S1, TestRouteNetwork.S4 }; var validateInterestCommand = new ValidateWalkOfInterest(Guid.NewGuid(), new UserContext("test", Guid.Empty), walk); var validateResult = await _commandDispatcher.HandleAsync <ValidateWalkOfInterest, Result <ValidatedRouteNetworkWalk> >(validateInterestCommand); // Assert validateResult.IsSuccess.Should().BeTrue(); validateResult.Value.NodeIds.Count.Should().Be(4); validateResult.Value.SegmentIds.Count.Should().Be(3); validateResult.Value.NodeIds[0].Should().Be(TestRouteNetwork.CO_1); validateResult.Value.NodeIds[1].Should().Be(TestRouteNetwork.HH_1); validateResult.Value.NodeIds[2].Should().Be(TestRouteNetwork.HH_2); validateResult.Value.NodeIds[3].Should().Be(TestRouteNetwork.CC_1); validateResult.Value.SegmentIds[0].Should().Be(TestRouteNetwork.S1); validateResult.Value.SegmentIds[1].Should().Be(TestRouteNetwork.S2); validateResult.Value.SegmentIds[2].Should().Be(TestRouteNetwork.S4); }
private void AddSpecification(SpanEquipmentSpecification spec) { var cmd = new AddSpanEquipmentSpecification(Guid.NewGuid(), new UserContext("specification seeder", _specSeederId), spec); var cmdResult = _commandDispatcher.HandleAsync <AddSpanEquipmentSpecification, Result>(cmd).Result; if (cmdResult.IsFailed) { throw new ApplicationException(cmdResult.Errors.First().Message); } }
private async Task UpgradeVersion1() { RecreateEventSourcingContext(); await RecreateReadModelContextAsync(); await commandDispatcher.HandleAsync(new CreateCategory("Home", "DIY", ColorConverter.Map(Colors.SandyBrown))); await commandDispatcher.HandleAsync(new CreateCategory("Food", "Home boilt stuff", ColorConverter.Map(Colors.OrangeRed))); await commandDispatcher.HandleAsync(new CreateCategory("Eating Out", "Outsourced", ColorConverter.Map(Colors.DarkRed))); }
public virtual async Task <IActionResult> SetUserImage( [FromRoute, NotEmptyGuid] Guid userId, [FromForm(Name = "photo"), AllowedFileTypes(fileTypes: new String[] { ".jpg", ".jpeg" })] IFormFile file) { using (var memoryStream = new MemoryStream()) { await file.CopyToAsync(memoryStream); await _commandDispather.HandleAsync <SetUserImageCommand>(new SetUserImageCommand(userId, memoryStream.ToArray())); } return(CreatedAtRoute(routeName: "Image", routeValues: new { userId = userId.ToString() }, value: null));; }
public async void UpdateMarkingInfo_ShouldSucceed() { var utilityNetwork = _eventStore.Projections.Get <UtilityNetworkProjection>(); var sutSpanEquipmentId = TestUtilityNetwork.MultiConduit_3x10_SDU_1_to_SDU_2; utilityNetwork.TryGetEquipment <SpanEquipment>(sutSpanEquipmentId, out var spanEquipmentBeforeUpdate); var updateCmd = new UpdateSpanEquipmentProperties(spanEquipmentOrSegmentId: sutSpanEquipmentId) { MarkingInfo = new MarkingInfo() { MarkingColor = "Red", MarkingText = "Rød" } }; var updateResult = await _commandDispatcher.HandleAsync <UpdateSpanEquipmentProperties, Result>(updateCmd); utilityNetwork.TryGetEquipment <SpanEquipment>(sutSpanEquipmentId, out var spanEquipmentAfterUpdate); // Assert updateResult.IsSuccess.Should().BeTrue(); spanEquipmentAfterUpdate.MarkingInfo.Should().BeEquivalentTo(updateCmd.MarkingInfo); // Check if an event is published to the notification.utility-network topic having an idlist containing the span equipment id we just created var utilityNetworkNotifications = _externalEventProducer.GetMessagesByTopic("notification.utility-network").OfType <RouteNetworkElementContainedEquipmentUpdated>(); var utilityNetworkUpdatedEvent = utilityNetworkNotifications.First(n => n.Category == "EquipmentModification.PropertiesUpdated" && n.IdChangeSets != null && n.IdChangeSets.Any(i => i.IdList.Any(i => i == sutSpanEquipmentId))); utilityNetworkUpdatedEvent.AffectedRouteNetworkElementIds.Should().Contain(TestRouteNetwork.J_1); }
public async Task ShowAsync(object parameter) { if (parameter is CategoryCreateParameter create) { key = KeyFactory.Empty(typeof(Category)); model = new CategoryNameDescriptionModel(null, null); } else if (parameter is CategoryRenameParameter rename) { key = rename.Key; model = await queryDispatcher.QueryAsync(new GetCategoryNameDescription(key)); Name = model.Name; Description = model.Description; } ContentDialogResult result = await ShowAsync(); if ((result == ContentDialogResult.Primary || IsEnterPressed) && (Name != model.Name || Description != model.Description)) { if (key.IsEmpty) { if (String.IsNullOrEmpty(Name)) { return; } Color color = ColorConverter.Map(Colors.Black); await commandDispatcher.HandleAsync(new CreateCategory(Name, Description, color)); Name = Name; } else { if (Name != model.Name) { await commandDispatcher.HandleAsync(new RenameCategory(key, Name)); Name = Name; } if (Description != model.Description) { await commandDispatcher.HandleAsync(new ChangeCategoryDescription(key, Description)); Description = Description; } } } }
public async void QueryReferencesFromRouteElementAndInterestObjects_ShouldReturnAllInterestInformation() { // Create interest (CO_1) <- (S1) -> (HH_1) that we can then try query var interestId = Guid.NewGuid(); var walk = new RouteNetworkElementIdList() { TestRouteNetwork.S1 }; var createInterestCommand = new RegisterWalkOfInterest(Guid.NewGuid(), new UserContext("test", Guid.Empty), interestId, walk); await _commandDispatcher.HandleAsync <RegisterWalkOfInterest, Result <RouteNetworkInterest> >(createInterestCommand); // Act: Query CO_1, S1, HH_1 and HH_2 var routeNetworkQuery = new GetRouteNetworkDetails(new RouteNetworkElementIdList() { TestRouteNetwork.CO_1, TestRouteNetwork.S1, TestRouteNetwork.HH_1, TestRouteNetwork.HH_2 }) { RelatedInterestFilter = RelatedInterestFilterOptions.ReferencesFromRouteElementAndInterestObjects }; Result <GetRouteNetworkDetailsResult> queryResult = await _queryDispatcher.HandleAsync <GetRouteNetworkDetails, Result <GetRouteNetworkDetailsResult> >(routeNetworkQuery); // Assert that we got information back on all 4 network elements queried Assert.True(queryResult.IsSuccess); Assert.Equal(4, queryResult.Value.RouteNetworkElements.Count); // Assert that we got back one interest related to the 3 network elements that the walk of interest covers Assert.NotNull(queryResult.Value.Interests); Assert.Contains(queryResult.Value.Interests, i => i.Id == interestId); Assert.Equal(RouteNetworkInterestKindEnum.WalkOfInterest, queryResult.Value.Interests[interestId].Kind); Assert.Equal(3, queryResult.Value.Interests[interestId].RouteNetworkElementRefs.Count); Assert.Contains(TestRouteNetwork.CO_1, queryResult.Value.Interests[interestId].RouteNetworkElementRefs); Assert.Contains(TestRouteNetwork.S1, queryResult.Value.Interests[interestId].RouteNetworkElementRefs); Assert.Contains(TestRouteNetwork.HH_1, queryResult.Value.Interests[interestId].RouteNetworkElementRefs); // Assert that route element 1 (CO_1) has interest information with correct relation type Assert.NotNull(queryResult.Value.RouteNetworkElements[TestRouteNetwork.CO_1].InterestRelations); Assert.Contains(queryResult.Value.RouteNetworkElements[TestRouteNetwork.CO_1].InterestRelations, r => r.RefId == interestId && r.RelationKind == RouteNetworkInterestRelationKindEnum.Start); // Assert that route element 2 (S1) has interest information with correct relation type Assert.NotNull(queryResult.Value.RouteNetworkElements[TestRouteNetwork.S1].InterestRelations); Assert.Contains(queryResult.Value.RouteNetworkElements[TestRouteNetwork.S1].InterestRelations, r => r.RefId == interestId && r.RelationKind == RouteNetworkInterestRelationKindEnum.PassThrough); // Assert that route element 3 (HH_1) has interest information with correct relation type Assert.NotNull(queryResult.Value.RouteNetworkElements[TestRouteNetwork.HH_1].InterestRelations); Assert.Contains(queryResult.Value.RouteNetworkElements[TestRouteNetwork.HH_1].InterestRelations, r => r.RefId == interestId && r.RelationKind == RouteNetworkInterestRelationKindEnum.End); }
public async void TestAddAdditionalStructuresTo5x10_ShouldSucceed() { var utilityNetwork = _eventStore.Projections.Get <UtilityNetworkProjection>(); var sutSpanEquipmentId = TestUtilityNetwork.FlexConduit_40_Red_CC_1_to_SP_1; utilityNetwork.TryGetEquipment <SpanEquipment>(sutSpanEquipmentId, out var sutSpanEquipment); var addStructure = new PlaceAdditionalStructuresInSpanEquipment( spanEquipmentId: sutSpanEquipmentId, structureSpecificationIds: new Guid[] { TestSpecifications.Ø10_Red, TestSpecifications.Ø10_Violet } ); var addStructureResult = await _commandDispatcher.HandleAsync <PlaceAdditionalStructuresInSpanEquipment, Result>(addStructure); var equipmentQueryResult = await _queryDispatcher.HandleAsync <GetEquipmentDetails, Result <GetEquipmentDetailsResult> >( new GetEquipmentDetails(new EquipmentIdList() { sutSpanEquipmentId }) ); var equipmentAfterAddingStructure = equipmentQueryResult.Value.SpanEquipment[sutSpanEquipmentId]; // Assert addStructureResult.IsSuccess.Should().BeTrue(); equipmentQueryResult.IsSuccess.Should().BeTrue(); equipmentAfterAddingStructure.SpanStructures.Count(s => s.Level == 2).Should().Be(2); equipmentAfterAddingStructure.SpanStructures.Count(s => s.Level == 2 && s.Position == 1).Should().Be(1); equipmentAfterAddingStructure.SpanStructures.Count(s => s.Level == 2 && s.Position == 2).Should().Be(1); equipmentAfterAddingStructure.SpanStructures[1].Id.Should().NotBeEmpty(); equipmentAfterAddingStructure.SpanStructures[1].SpanSegments[0].Id.Should().NotBeEmpty(); equipmentAfterAddingStructure.SpanStructures[2].Id.Should().NotBeEmpty(); equipmentAfterAddingStructure.SpanStructures[2].SpanSegments[0].Id.Should().NotBeEmpty(); // Check utility graph utilityNetwork.Graph.TryGetGraphElement <IUtilityGraphSegmentRef>(equipmentAfterAddingStructure.SpanStructures[2].SpanSegments[0].Id, out var fromGraphSegmentRef); fromGraphSegmentRef.SpanSegment(utilityNetwork).FromTerminalId.Should().BeEmpty(); fromGraphSegmentRef.SpanSegment(utilityNetwork).ToTerminalId.Should().BeEmpty(); // Check if an event is published to the notification.utility-network topic having an idlist containing the span equipment id we just created var utilityNetworkNotifications = _externalEventProducer.GetMessagesByTopic("notification.utility-network").OfType <RouteNetworkElementContainedEquipmentUpdated>(); var utilityNetworkUpdatedEvent = utilityNetworkNotifications.First(n => n.Category == "EquipmentModification.StructuresAdded" && n.IdChangeSets != null && n.IdChangeSets.Any(i => i.IdList.Any(i => i == sutSpanEquipmentId))); utilityNetworkUpdatedEvent.AffectedRouteNetworkElementIds.Should().Contain(TestRouteNetwork.CC_1); }
public async Task PublishAsync() { log.Debug("Publishing.."); if (network.IsOnline) { log.Debug("Network is online."); var commands = await storage.LoadAsync(); if (commands != null && commands.Count > 0) { log.Debug($"Publishing '{commands.Count}' expenses."); foreach (CreateOutcome command in commands) { await commandDispatcher.HandleAsync(command); } await storage.DeleteAsync(); await eventDispatcher.PublishAsync(new LocallyStoredExpensesPublished()); } else { log.Debug($"Local storage is empty."); } } }
public Task <IKey> SaveAsync(T model, IKey sourceCommandKey) { base.SaveAsync(model); IEnumerable <Envelope <ICommand> > commands = model.Commands; if (commands.Any()) { IEnumerable <CommandModel> commandModels = commands.Select(c => { if (sourceCommandKey != null) { c.AddSourceCommandKey(sourceCommandKey); } return(new CommandModel(c.Body.Key, commandFormatter.SerializeCommand(c))); }); commandStore.Save(commandModels); foreach (Envelope <ICommand> e in commands) { commandDispatcher.HandleAsync(e).Wait(); } } return(Task.FromResult(model.Key)); }
public async void TestAffixConduitToContainer_ShouldSucceed() { var nodeContainerId = PlaceNodeContainer(TestRouteNetwork.HH_2); var testNetwork = new TestUtilityNetwork(_commandDispatcher, _queryDispatcher).Run(); var testConduitId = TestUtilityNetwork.MultiConduit_5x10_HH_1_to_HH_10; var testConduit = _eventStore.Projections.Get <UtilityNetworkProjection>().SpanEquipments[testConduitId]; var affixConduitToContainerCommand = new AffixSpanEquipmentToNodeContainer( spanEquipmentOrSegmentId: testConduit.SpanStructures[0].SpanSegments[0].Id, nodeContainerId: nodeContainerId, nodeContainerIngoingSide: NodeContainerSideEnum.West ); var affixResult = await _commandDispatcher.HandleAsync <AffixSpanEquipmentToNodeContainer, Result>(affixConduitToContainerCommand); var equipmentQueryResult = await _queryDispatcher.HandleAsync <GetEquipmentDetails, Result <GetEquipmentDetailsResult> >( new GetEquipmentDetails(new EquipmentIdList() { testConduitId }) ); equipmentQueryResult.IsSuccess.Should().BeTrue(); equipmentQueryResult.Value.SpanEquipment[testConduitId].NodeContainerAffixes.First(n => n.NodeContainerId == nodeContainerId).NodeContainerIngoingSide.Should().Be(NodeContainerSideEnum.West); // Check if an event is published to the notification.utility-network topic having an idlist containing the span equipment id we just created var utilityNetworkNotifications = _externalEventProducer.GetMessagesByTopic("notification.utility-network").OfType <RouteNetworkElementContainedEquipmentUpdated>(); var utilityNetworkUpdatedEvent = utilityNetworkNotifications.First(n => n.IdChangeSets != null && n.IdChangeSets.Any(i => i.IdList.Any(i => i == nodeContainerId) && i.ChangeType == Events.Changes.ChangeTypeEnum.Modification)); utilityNetworkUpdatedEvent.AffectedRouteNetworkElementIds.Should().Contain(TestRouteNetwork.HH_2); }
private Guid PlaceConduit(Guid specificationId, RouteNetworkElementIdList walkIds) { // Register walk of interest var walkOfInterestId = Guid.NewGuid(); var registerWalkOfInterestCommand = new RegisterWalkOfInterest(walkOfInterestId, walkIds); var registerWalkOfInterestCommandResult = _commandDispatcher.HandleAsync <RegisterWalkOfInterest, Result <RouteNetworkInterest> >(registerWalkOfInterestCommand).Result; // Place conduit var placeSpanEquipmentCommand = new PlaceSpanEquipmentInRouteNetwork(Guid.NewGuid(), specificationId, registerWalkOfInterestCommandResult.Value); var placeSpanEquipmentResult = _commandDispatcher.HandleAsync <PlaceSpanEquipmentInRouteNetwork, Result>(placeSpanEquipmentCommand).Result; if (placeSpanEquipmentResult.IsFailed) { throw new ApplicationException(placeSpanEquipmentResult.Errors.First().Message); } return(placeSpanEquipmentCommand.SpanEquipmentId); }
public async void TestDrawingOneRackInFP2() { var sutRouteNetworkElement = TestRouteNetwork.FP_2; var utilityNetwork = _eventStore.Projections.Get <UtilityNetworkProjection>(); // Act var placeRackCmd = new PlaceRackInNodeContainer( Guid.NewGuid(), new UserContext("test", Guid.Empty), TestUtilityNetwork.NodeContainer_FP_2, TestSpecifications.Rack_ESTI, "Rack 1", 80 ); var placeRackResult = await _commandDispatcher.HandleAsync <PlaceRackInNodeContainer, Result>(placeRackCmd); // Assert placeRackResult.IsSuccess.Should().BeTrue(); var getDiagramQueryResult = await _queryDispatcher.HandleAsync <GetDiagram, Result <GetDiagramResult> >(new GetDiagram(sutRouteNetworkElement)); var diagram = getDiagramQueryResult.Value.Diagram; if (System.Environment.OSVersion.Platform.ToString() == "Win32NT") { new GeoJsonExporter(diagram).Export("c:/temp/diagram/test.geojson"); } // Assert getDiagramQueryResult.IsSuccess.Should().BeTrue(); diagram.DiagramObjects.Count(o => o.Style == "Rack").Should().Be(1); diagram.DiagramObjects.Count(o => o.Style == "SubrackSpace").Should().Be(1); diagram.DiagramObjects.Count(o => o.Style == "RackLabel").Should().Be(1); diagram.DiagramObjects.Count(o => o.Style == "RackUnitLabel").Should().Be(81); diagram.DiagramObjects.Count(o => o.Style == "Rack" && o.IdentifiedObject.RefId != Guid.Empty).Should().Be(1); }
private async void btnAmount_Click(object sender, RoutedEventArgs e) { OutcomeOverviewViewModel viewModel = (OutcomeOverviewViewModel)((Button)sender).DataContext; OutcomeAmount dialog = new OutcomeAmount(queryDispatcher); dialog.Value = viewModel.Amount.Value; dialog.Currency = viewModel.Amount.Currency; ContentDialogResult result = await dialog.ShowAsync(true); decimal newValue = dialog.Value; if (result == ContentDialogResult.Primary && newValue != viewModel.Amount.Value) { Price newAmount = new Price(newValue, dialog.Currency); await commandDispatcher.HandleAsync(new ChangeOutcomeAmount(viewModel.Key, newAmount)); } }
private async Task ShowInternalAsync(CurrencyName dialog, string errorMessage) { dialog.ErrorMessage = errorMessage; ContentDialogResult result = await dialog.ShowAsync(); if ((result == ContentDialogResult.Primary || dialog.IsEnterPressed) && !String.IsNullOrEmpty(dialog.UniqueCode)) { await commandDispatcher.HandleAsync(new CreateCurrency(dialog.UniqueCode, dialog.Symbol)); } }
public async void ConnectConduitInSDU1_ShouldSucceed() { var utilityNetwork = _eventStore.Projections.Get <UtilityNetworkProjection>(); var sutSpanEquipment1 = TestUtilityNetwork.MultiConduit_3x10_SDU_1_to_SDU_2; var sutSpanEquipment2 = TestUtilityNetwork.MultiConduit_12x7_SDU_1_to_J_1; utilityNetwork.TryGetEquipment <SpanEquipment>(sutSpanEquipment1, out var spanEquipment1BeforeConnect); utilityNetwork.TryGetEquipment <SpanEquipment>(sutSpanEquipment2, out var spanEquipment2BeforeConnect); // Connect inner conduit 1 var connectCmd = new ConnectSpanSegmentsAtRouteNode( routeNodeId: TestRouteNetwork.SDU_1, spanSegmentsToConnect: new Guid[] { spanEquipment1BeforeConnect.SpanStructures[1].SpanSegments[0].Id, spanEquipment2BeforeConnect.SpanStructures[1].SpanSegments[0].Id } ); var connectResult = await _commandDispatcher.HandleAsync <ConnectSpanSegmentsAtRouteNode, Result>(connectCmd); // Assert connectResult.IsSuccess.Should().BeTrue(); // Assert trace is correct var traceQueryResult = await _queryDispatcher.HandleAsync <GetEquipmentDetails, Result <GetEquipmentDetailsResult> >( new GetEquipmentDetails(new EquipmentIdList() { sutSpanEquipment2 }) { EquipmentDetailsFilter = new EquipmentDetailsFilterOptions() { IncludeRouteNetworkTrace = true } } ); traceQueryResult.IsSuccess.Should().BeTrue(); var innerConduit1TraceId = traceQueryResult.Value.SpanEquipment[sutSpanEquipment2].RouteNetworkTraceRefs.First(tr => tr.SpanEquipmentOrSegmentId == spanEquipment2BeforeConnect.SpanStructures[1].SpanSegments[0].Id).TraceId; var routeNetworkTraces = traceQueryResult.Value.RouteNetworkTraces[innerConduit1TraceId]; routeNetworkTraces.FromRouteNodeId.Should().Be(TestRouteNetwork.J_1); routeNetworkTraces.ToRouteNodeId.Should().Be(TestRouteNetwork.SDU_2); }
public async void CreateAndRemoveWalkOfInterest_ShouldReturnSuccess() { // Route network subset used in this test: // (CO_1) <- (S1) -> (HH_1) var interestId = Guid.NewGuid(); var walk = new RouteNetworkElementIdList() { TestRouteNetwork.S1 }; var routeNetworkQuery = new GetRouteNetworkDetails(new RouteNetworkElementIdList() { TestRouteNetwork.CO_1 }) { RelatedInterestFilter = RelatedInterestFilterOptions.ReferencesFromRouteElementAndInterestObjects }; // Act var registerWalkOfInterestCommand = new RegisterWalkOfInterest(Guid.NewGuid(), new UserContext("test", Guid.Empty), interestId, walk); var registerWalkOfInterestCommandResult = await _commandDispatcher.HandleAsync <RegisterWalkOfInterest, Result <RouteNetworkInterest> > (registerWalkOfInterestCommand); Result <GetRouteNetworkDetailsResult> routeNetworkQueryResultBefore = await _queryDispatcher.HandleAsync <GetRouteNetworkDetails, Result <GetRouteNetworkDetailsResult> >(routeNetworkQuery); var unregisterWalkOfInterestCommand = new UnregisterInterest(Guid.NewGuid(), new UserContext("test", Guid.Empty), interestId); var unregisterWalkOfInterestCommandResult = await _commandDispatcher.HandleAsync <UnregisterInterest, Result>(unregisterWalkOfInterestCommand); Result <GetRouteNetworkDetailsResult> routeNetworkQueryResultAfter = await _queryDispatcher.HandleAsync <GetRouteNetworkDetails, Result <GetRouteNetworkDetailsResult> >(routeNetworkQuery); // Assert command result registerWalkOfInterestCommandResult.IsSuccess.Should().BeTrue(); unregisterWalkOfInterestCommandResult.IsSuccess.Should().BeTrue(); // Assert query result routeNetworkQueryResultBefore.IsSuccess.Should().BeTrue(); routeNetworkQueryResultBefore.Value.Interests.ContainsKey(interestId).Should().BeTrue(); routeNetworkQueryResultAfter.IsSuccess.Should().BeTrue(); routeNetworkQueryResultAfter.Value.Interests.ContainsKey(interestId).Should().BeFalse(); }
public async void TestCut5x10ConduitAtCC_1_ShouldSucceed() { var utilityNetwork = _eventStore.Projections.Get <UtilityNetworkProjection>(); var sutSpanEquipment = TestUtilityNetwork.MultiConduit_5x10_HH_1_to_HH_10; utilityNetwork.TryGetEquipment <SpanEquipment>(sutSpanEquipment, out var spanEquipment); // Cut the outer conduit and 4 inner conduit var cutCmd = new CutSpanSegmentsAtRouteNode( routeNodeId: TestRouteNetwork.CC_1, spanSegmentsToCut: new Guid[] { spanEquipment.SpanStructures[0].SpanSegments[0].Id, spanEquipment.SpanStructures[1].SpanSegments[0].Id, spanEquipment.SpanStructures[2].SpanSegments[0].Id, spanEquipment.SpanStructures[3].SpanSegments[0].Id, spanEquipment.SpanStructures[4].SpanSegments[0].Id } ); var cutResult = await _commandDispatcher.HandleAsync <CutSpanSegmentsAtRouteNode, Result>(cutCmd); var equipmentQueryResult = await _queryDispatcher.HandleAsync <GetEquipmentDetails, Result <GetEquipmentDetailsResult> >( new GetEquipmentDetails(new EquipmentIdList() { sutSpanEquipment }) ); equipmentQueryResult.IsSuccess.Should().BeTrue(); // Assert cutResult.IsSuccess.Should().BeTrue(); var spanEquipmentAfterCut = equipmentQueryResult.Value.SpanEquipment[sutSpanEquipment]; spanEquipmentAfterCut.NodesOfInterestIds.Length.Should().Be(3); spanEquipmentAfterCut.NodesOfInterestIds[0].Should().Be(spanEquipment.NodesOfInterestIds[0]); spanEquipmentAfterCut.NodesOfInterestIds[1].Should().Be(TestRouteNetwork.CC_1); spanEquipmentAfterCut.NodesOfInterestIds[2].Should().Be(spanEquipment.NodesOfInterestIds[1]); // Outer conduit spanEquipmentAfterCut.SpanStructures[0].SpanSegments.Length.Should().Be(2); // Last inner conduit (should not be cut) spanEquipmentAfterCut.SpanStructures[5].SpanSegments.Length.Should().Be(1); // Second inner conduit spanEquipmentAfterCut.SpanStructures[2].SpanSegments.Length.Should().Be(2); // Check if an event is published to the notification.utility-network topic having an idlist containing the span equipment id we just created var utilityNetworkNotifications = _externalEventProducer.GetMessagesByTopic("notification.utility-network").OfType <RouteNetworkElementContainedEquipmentUpdated>(); var utilityNetworkUpdatedEvent = utilityNetworkNotifications.First(n => n.IdChangeSets != null && n.IdChangeSets.Any(i => i.IdList.Any(i => i == sutSpanEquipment))); utilityNetworkUpdatedEvent.AffectedRouteNetworkElementIds.Should().Contain(TestRouteNetwork.CC_1); }
public Task HandleAsync <TCommand>(TCommand command) { Envelope envelope = command as Envelope; if (envelope == null) { envelope = Envelope.Create <TCommand>(command); } envelope.Metadata.Add("UserKey", userKeyGetter()); return(inner.HandleAsync(envelope)); }
public async void TestConnectTwo5x10inCO1_ShouldSucceed() { var utilityNetwork = _eventStore.Projections.Get <UtilityNetworkProjection>(); var sutConnectFromSpanEquipment = TestUtilityNetwork.MultiConduit_5x10_CO_1_to_HH_1; var sutConnectToSpanEquipment = TestUtilityNetwork.MultiConduit_5x10_HH_1_to_HH_10; utilityNetwork.TryGetEquipment <SpanEquipment>(sutConnectFromSpanEquipment, out var sutFromSpanEquipment); utilityNetwork.TryGetEquipment <SpanEquipment>(sutConnectToSpanEquipment, out var sutToSpanEquipment); var connectCmd = new ConnectSpanSegmentsAtRouteNode( routeNodeId: TestRouteNetwork.HH_1, spanSegmentsToConnect: new Guid[] { sutFromSpanEquipment.SpanStructures[1].SpanSegments[0].Id, sutToSpanEquipment.SpanStructures[1].SpanSegments[0].Id, sutFromSpanEquipment.SpanStructures[2].SpanSegments[0].Id, sutToSpanEquipment.SpanStructures[2].SpanSegments[0].Id, sutFromSpanEquipment.SpanStructures[3].SpanSegments[0].Id, sutToSpanEquipment.SpanStructures[3].SpanSegments[0].Id, sutFromSpanEquipment.SpanStructures[4].SpanSegments[0].Id, sutToSpanEquipment.SpanStructures[4].SpanSegments[0].Id, sutFromSpanEquipment.SpanStructures[5].SpanSegments[0].Id, sutToSpanEquipment.SpanStructures[5].SpanSegments[0].Id, } ); var connectResult = await _commandDispatcher.HandleAsync <ConnectSpanSegmentsAtRouteNode, Result>(connectCmd); // Assert connectResult.IsSuccess.Should().BeTrue(); }
public async void TestDrawingCableEndOutsideConduitInRouteNode() { var utilityNetwork = _eventStore.Projections.Get <UtilityNetworkProjection>(); var sutRouteNetworkElement = TestRouteNetwork.CC_1; // Setup var specs = new TestSpecifications(_commandDispatcher, _queryDispatcher).Run(); // Cable directly in route network from HH_1 to CC_1 var routingHops = new RoutingHop[] { new RoutingHop( new Guid[] { TestRouteNetwork.HH_1, TestRouteNetwork.S2, TestRouteNetwork.HH_2, TestRouteNetwork.S4, TestRouteNetwork.CC_1 } ), }; var placeSpanEquipmentCommand = new PlaceSpanEquipmentInUtilityNetwork(Guid.NewGuid(), new UserContext("test", Guid.Empty), Guid.NewGuid(), TestSpecifications.FiberCable_192Fiber, routingHops) { NamingInfo = new NamingInfo("K12345678", null), ManufacturerId = Guid.NewGuid() }; // Act var placeSpanEquipmentResult = await _commandDispatcher.HandleAsync <PlaceSpanEquipmentInUtilityNetwork, Result>(placeSpanEquipmentCommand); utilityNetwork.TryGetEquipment <SpanEquipment>(placeSpanEquipmentCommand.SpanEquipmentId, out var placedSpanEquipment); // Act var getDiagramQueryResult = await _queryDispatcher.HandleAsync <GetDiagram, Result <GetDiagramResult> >(new GetDiagram(sutRouteNetworkElement)); var diagram = getDiagramQueryResult.Value.Diagram; if (System.Environment.OSVersion.Platform.ToString() == "Win32NT") { new GeoJsonExporter(diagram).Export("c:/temp/diagram/test.geojson"); } // Assert diagram.DiagramObjects.Count(o => o.Style == "FiberCable" && o.Geometry is LineString).Should().Be(1); diagram.DiagramObjects.Count(o => o.Label != null && o.Label.Contains("K12345678")).Should().Be(1); }
public async void AddValidNodeContainerSpecification_ShouldSucceed() { // Create manufacturer var manufacturer = new Manufacturer(Guid.NewGuid(), "Node Container Manufacturer"); await _commandDispatcher.HandleAsync <AddManufacturer, Result>(new AddManufacturer(manufacturer)); // Setup a node equipment container specification var newNodeContainerSpecification = new NodeContainerSpecification(Guid.NewGuid(), "ManHoles", "Draka xyz") { Description = "Draka super duper xyz", ManufacturerRefs = new Guid[] { manufacturer.Id } }; // Act var addNodeSpecificationCommandResult = await _commandDispatcher.HandleAsync <AddNodeContainerSpecification, Result>(new AddNodeContainerSpecification(newNodeContainerSpecification)); var nodeContainerSpecificationsQueryResult = await _queryDispatcher.HandleAsync <GetNodeContainerSpecifications, Result <LookupCollection <NodeContainerSpecification> > >(new GetNodeContainerSpecifications()); // Assert addNodeSpecificationCommandResult.IsSuccess.Should().BeTrue(); nodeContainerSpecificationsQueryResult.IsSuccess.Should().BeTrue(); nodeContainerSpecificationsQueryResult.Value[newNodeContainerSpecification.Id].Name.Should().Be(newNodeContainerSpecification.Name); nodeContainerSpecificationsQueryResult.Value[newNodeContainerSpecification.Id].Description.Should().Be(newNodeContainerSpecification.Description); }