private async Task HandleRouteNode(RouteNodeMessage routeNodeMessage) { if (IsRouteNodeDeleted(routeNodeMessage)) { return; } if (IsNodeNewlyDigitized(routeNodeMessage)) { var routeNodeDigitizedEvents = await _routeNodeEventFactory.CreateDigitizedEvent((RouteNode)routeNodeMessage.After); foreach (var routeNodeDigitizedEvent in routeNodeDigitizedEvents) { if (!(routeNodeDigitizedEvent is null)) { await _mediator.Publish(routeNodeDigitizedEvent); } } } else if (IsNodeUpdated(routeNodeMessage)) { var modifiedEvents = await _routeNodeInfoCommandFactory .Create(routeNodeMessage.Before, routeNodeMessage.After); var routeNodeUpdatedEvents = await _routeNodeEventFactory .CreateUpdatedEvent(routeNodeMessage.Before, routeNodeMessage.After); var possibleIllegalOperation = routeNodeUpdatedEvents.Any(x => x.GetType() == typeof(RouteNodeDeleted)); if (possibleIllegalOperation) { var hasRelatedEquipment = await _validationService.HasRelatedEquipment(routeNodeMessage.After.Mrid); if (hasRelatedEquipment) { throw new Exception("Cannot update route node since it has related equipment."); } } foreach (var modifiedEvent in modifiedEvents) { if (!(modifiedEvent is null)) { await _mediator.Publish(modifiedEvent); } } foreach (var routeNodeUpdatedEvent in routeNodeUpdatedEvents) { if (!(routeNodeUpdatedEvent is null)) { await _mediator.Publish(routeNodeUpdatedEvent); } } } else { await _mediator.Publish(new InvalidRouteNodeOperation { RouteNode = routeNodeMessage.After }); } }
public void Deserialize_ShouldReturnDeserializedNodeMessage_OnValidReceivedTransportMessage(string fileData) { var serializationMapper = A.Fake <IInfoMapper>(); var routeNodeSerializer = new RouteNetworkSerializer(serializationMapper); A.CallTo(() => serializationMapper.MapDeploymentState("InService")).Returns(DeploymentStateEnum.InService); A.CallTo(() => serializationMapper.MapRouteNodeFunction("FlexPoint")).Returns(RouteNodeFunctionEnum.FlexPoint); var position = new Position(string.Empty, 0, 0); var headers = new Dictionary <string, string>(); var body = Encoding.UTF8.GetBytes(fileData); var receivedTransportMessage = new ReceivedTransportMessage(position, headers, body); var expectedRouteNodeBefore = new RouteNode { ApplicationInfo = string.Empty, ApplicationName = string.Empty, Coord = Convert.FromBase64String("AQEAACDoZAAAqxoVSPa2H8GsStinzINUQQ=="), DeleteMe = false, MarkAsDeleted = false, Mrid = new Guid("9bffa519-c672-49fd-93d0-52cd22519346"), Username = string.Empty, WorkTaskMrid = Guid.Empty, LifeCycleInfo = null, MappingInfo = null, NamingInfo = null, RouteNodeInfo = null, SafetyInfo = null }; var expectedRouteNodeAfter = new RouteNode { ApplicationInfo = string.Empty, ApplicationName = string.Empty, Coord = Convert.FromBase64String("AQEAACDoZAAAqxoVSPa2H8GsStinzINUQQ=="), DeleteMe = false, MarkAsDeleted = true, Mrid = new Guid("9bffa519-c672-49fd-93d0-52cd22519346"), Username = string.Empty, WorkTaskMrid = Guid.Empty, LifeCycleInfo = new LifecycleInfo(DeploymentStateEnum.InService, DateTime.Parse("2020-08-12 00:00:00"), DateTime.Parse("2020-08-12 00:00:00")), MappingInfo = null, NamingInfo = null, RouteNodeInfo = new RouteNodeInfo(null, RouteNodeFunctionEnum.FlexPoint), SafetyInfo = null }; var expectedBody = new RouteNodeMessage(expectedRouteNodeBefore, expectedRouteNodeAfter); var expected = new ReceivedLogicalMessage(headers, expectedBody, position); var result = routeNodeSerializer.Deserialize(receivedTransportMessage); result.Should().BeEquivalentTo(expected); }
public void Deserialize_ShouldReturnDeserializedNodeMessageWithBeforebeingNull_OnValidReceivedTransportMessageWithBeforeBeingNull(string fileData) { var serializationMapper = A.Fake <IInfoMapper>(); A.CallTo(() => serializationMapper.MapDeploymentState("InService")).Returns(DeploymentStateEnum.InService); A.CallTo(() => serializationMapper.MapMappingMethod("Drafting")).Returns(MappingMethodEnum.Drafting); A.CallTo(() => serializationMapper.MapRouteNodeKind("CabinetBig")).Returns(RouteNodeKindEnum.CabinetBig); A.CallTo(() => serializationMapper.MapRouteNodeFunction("FlexPoint")).Returns(RouteNodeFunctionEnum.FlexPoint); var routeNodeSerializer = new RouteNetworkSerializer(serializationMapper); var position = new Position(string.Empty, 0, 0); var headers = new Dictionary <string, string>(); var body = Encoding.UTF8.GetBytes(fileData); var receivedTransportMessage = new ReceivedTransportMessage(position, headers, body); RouteNode expectedRouteNodeBefore = null; var expectedRouteNodeAfter = new RouteNode { ApplicationInfo = "Application information bla bla", ApplicationName = "GDB_INTEGRATOR", Coord = Convert.FromBase64String("AQEAACDoZAAADEpxfJCIIUFJI+ZYZL1XQQ=="), DeleteMe = false, MarkAsDeleted = false, Mrid = new Guid("66563e62-db0e-4184-be75-d55638bf33a5"), Username = "******", WorkTaskMrid = Guid.Parse("d80f6250-8132-4893-b38f-b64fafd74316"), LifeCycleInfo = new LifecycleInfo(DeploymentStateEnum.InService, DateTime.Parse("2020-08-12 00:00:00"), DateTime.Parse("2020-08-12 00:00:00")), MappingInfo = new MappingInfo(MappingMethodEnum.Drafting, "1", "2", DateTime.Parse("2020-08-12 00:00:00"), "Source info"), NamingInfo = new NamingInfo("AB13", "AB13 desc"), RouteNodeInfo = new RouteNodeInfo(RouteNodeKindEnum.CabinetBig, RouteNodeFunctionEnum.FlexPoint), SafetyInfo = new SafetyInfo("Very safe", "Nothing to say") }; var expectedBody = new RouteNodeMessage(expectedRouteNodeBefore, expectedRouteNodeAfter); var expected = new ReceivedLogicalMessage(headers, expectedBody, position); var result = routeNodeSerializer.Deserialize(receivedTransportMessage); result.Should().BeEquivalentTo(expected); }
private async Task HandleSubscribedEvent(RouteNodeMessage routeNodeMessage) { _logger.LogDebug($"Received message: {JsonConvert.SerializeObject(routeNodeMessage, Formatting.Indented)}"); await _mediator.Send(new GeoDatabaseUpdated { UpdateMessage = routeNodeMessage }); }