public async Task CreateUpdatedEvent_ShouldReturnDoNothing_OnRouteNodeMarkedAsDeletedAndCoordBeingTheSame()
        {
            var applicationSetting  = A.Fake <IOptions <ApplicationSetting> >();
            var geoDatabase         = A.Fake <IGeoDatabase>();
            var integratorRouteNode = A.Fake <RouteNode>();
            var beforeNode          = A.Fake <RouteNode>();
            var afterNode           = A.Fake <RouteNode>();

            A.CallTo(() => afterNode.Mrid).Returns(Guid.NewGuid());

            A.CallTo(() => geoDatabase.GetRouteNodeShadowTable(afterNode.Mrid, false))
            .Returns(integratorRouteNode);

            A.CallTo(() => afterNode.GetGeoJsonCoordinate())
            .Returns("[565931.4446905176,6197297.75114815]");
            A.CallTo(() => afterNode.MarkAsDeleted).Returns(true);

            A.CallTo(() => integratorRouteNode.GetGeoJsonCoordinate())
            .Returns("[565931.4446905176,6197297.75114815]");
            A.CallTo(() => integratorRouteNode.MarkAsDeleted).Returns(true);

            var factory = new RouteNodeCommandFactory(applicationSetting, geoDatabase);

            var result = (await factory.CreateUpdatedEvent(beforeNode, afterNode)).First();

            result.Should().BeOfType <DoNothing>();
        }
        public async Task CreateUpdatedEvent_ShouldReturnRouteNodeLocationChanged_OnRouteNodeChanged()
        {
            var applicationSetting   = A.Fake <IOptions <ApplicationSetting> >();
            var geoDatabase          = A.Fake <IGeoDatabase>();
            var beforeNode           = A.Fake <RouteNode>();
            var afterNode            = A.Fake <RouteNode>();
            var shadowTableRouteNode = A.Fake <RouteNode>();

            A.CallTo(() => afterNode.Mrid).Returns(Guid.NewGuid());
            A.CallTo(() => geoDatabase.GetRouteNodeShadowTable(afterNode.Mrid, false)).Returns(shadowTableRouteNode);

            A.CallTo(() => afterNode.GetGeoJsonCoordinate())
            .Returns("[665931.4446905176,7197297.75114815]");
            A.CallTo(() => afterNode.MarkAsDeleted).Returns(false);

            A.CallTo(() => shadowTableRouteNode.GetGeoJsonCoordinate())
            .Returns("[565931.4446905176,6197297.75114815]");
            A.CallTo(() => shadowTableRouteNode.MarkAsDeleted).Returns(false);

            var factory = new RouteNodeCommandFactory(applicationSetting, geoDatabase);

            var result = (RouteNodeLocationChanged)(await factory.CreateUpdatedEvent(beforeNode, afterNode)).First();

            using (var scope = new AssertionScope())
            {
                result.Should().BeOfType(typeof(RouteNodeLocationChanged));
                result.RouteNodeAfter.Should().Be(afterNode);
            }
        }
        public async Task CreateUpdatedEvent_ShouldReturnRouteNodeDeletedEvent_OnRouteNodeMarkAsDeletedSetAndNoIntersectingSegments()
        {
            var applicationSetting = A.Fake <IOptions <ApplicationSetting> >();
            var geoDatabase        = A.Fake <IGeoDatabase>();
            var beforeNode         = A.Fake <RouteNode>();
            var afterNode          = A.Fake <RouteNode>();

            var mrid = Guid.NewGuid();

            A.CallTo(() => beforeNode.MarkAsDeleted).Returns(false);
            A.CallTo(() => beforeNode.Mrid).Returns(mrid);
            A.CallTo(() => afterNode.MarkAsDeleted).Returns(true);
            A.CallTo(() => afterNode.Mrid).Returns(mrid);

            A.CallTo(() => geoDatabase.GetIntersectingRouteSegments(afterNode))
            .Returns(new List <RouteSegment> {
            });

            var factory = new RouteNodeCommandFactory(applicationSetting, geoDatabase);
            var result  = (RouteNodeDeleted)(await factory.CreateUpdatedEvent(beforeNode, afterNode)).First();

            using (new AssertionScope())
            {
                result.RouteNode.Should().Be(afterNode);
            }
        }
        public async Task CreateUpdatedEvent_ShouldReturnRollbackInvalidRouteNodeOperation_OnRouteNodeIntersectingWithOtherRouteNodes()
        {
            var applicationSetting = A.Fake <IOptions <ApplicationSetting> >();
            var geoDatabase        = A.Fake <IGeoDatabase>();
            var beforeNode         = A.Fake <RouteNode>();
            var afterNode          = A.Fake <RouteNode>();

            A.CallTo(() => afterNode.MarkAsDeleted).Returns(true);
            A.CallTo(() => afterNode.Mrid).Returns(Guid.NewGuid());

            A.CallTo(() => geoDatabase.GetIntersectingRouteSegments(afterNode))
            .Returns(new List <RouteSegment>());

            A.CallTo(() => geoDatabase.GetIntersectingRouteNodes(afterNode))
            .Returns(new List <RouteNode> {
                A.Fake <RouteNode>()
            });

            var factory = new RouteNodeCommandFactory(applicationSetting, geoDatabase);
            var result  = await factory.CreateUpdatedEvent(beforeNode, afterNode);

            var expected = new RollbackInvalidRouteNode(beforeNode, "Is not a valid route node update");

            result.Should().BeEquivalentTo(expected);
        }
Beispiel #5
0
        public async Task CreateUpdatedEvent_ShouldReturnRollbackInvalidRouteNode_OnIsModifiedDistanceLessThanTolerance()
        {
            var applicationSetting   = A.Fake <IOptions <ApplicationSetting> >();
            var geoDatabase          = A.Fake <IGeoDatabase>();
            var beforeNode           = A.Fake <RouteNode>();
            var afterNode            = A.Fake <RouteNode>();
            var shadowTableRouteNode = A.Fake <RouteNode>();
            var appSettings          = new ApplicationSetting {
                Tolerance = 0.01
            };

            A.CallTo(() => applicationSetting.Value).Returns(appSettings);
            A.CallTo(() => afterNode.Mrid).Returns(Guid.NewGuid());
            A.CallTo(() => afterNode.GetGeoJsonCoordinate()).Returns("[552428.7508312801, 6188868.185819111]");
            A.CallTo(() => afterNode.GetPoint()).Returns(CreatePoint(552428.7508312801, 6188868.185819111));
            A.CallTo(() => geoDatabase.GetRouteNodeShadowTable(afterNode.Mrid, false)).Returns(shadowTableRouteNode);
            A.CallTo(() => shadowTableRouteNode.GetGeoJsonCoordinate()).Returns("[552428.7515896157,6188868.184787691]");
            A.CallTo(() => shadowTableRouteNode.GetPoint()).Returns(CreatePoint(552428.7515896157, 6188868.184787691));

            var factory = new RouteNodeCommandFactory(applicationSetting, geoDatabase);

            var result = (await factory.CreateUpdatedEvent(beforeNode, afterNode)).First();

            var expected = new RollbackInvalidRouteNode(shadowTableRouteNode, "Modified distance less than tolerance.");

            result.Should().BeOfType <RollbackInvalidRouteNode>();
        }
Beispiel #6
0
        public async Task CreateUpdatedEvent_ShouldReturnRollbackInvalidRouteNodeOperation_OnRouteNodeIntersectingWithOtherRouteNodes()
        {
            var applicationSetting   = A.Fake <IOptions <ApplicationSetting> >();
            var geoDatabase          = A.Fake <IGeoDatabase>();
            var beforeNode           = A.Fake <RouteNode>();
            var afterNode            = A.Fake <RouteNode>();
            var shadowTableRouteNode = A.Fake <RouteNode>();
            var appSettings          = new ApplicationSetting {
                Tolerance = 0.01
            };

            A.CallTo(() => applicationSetting.Value).Returns(appSettings);
            A.CallTo(() => afterNode.Mrid).Returns(Guid.NewGuid());
            A.CallTo(() => geoDatabase.GetRouteNodeShadowTable(afterNode.Mrid, false)).Returns(shadowTableRouteNode);
            A.CallTo(() => geoDatabase.GetIntersectingRouteSegments(afterNode)).Returns(new List <RouteSegment>());
            A.CallTo(() => afterNode.GetPoint()).Returns(CreatePoint(565931.4446905176, 6197297.75114815));
            A.CallTo(() => shadowTableRouteNode.GetPoint()).Returns(CreatePoint(565920.4446905176, 6197297.74114815));
            A.CallTo(() => afterNode.GetGeoJsonCoordinate()).Returns("[565931.4446905176,6197297.75114815]");
            A.CallTo(() => shadowTableRouteNode.GetGeoJsonCoordinate()).Returns("[565920.4446905176,6197297.74114815]");
            A.CallTo(() => geoDatabase.GetIntersectingRouteNodes(afterNode)).Returns(new List <RouteNode> {
                A.Fake <RouteNode>()
            });

            var factory = new RouteNodeCommandFactory(applicationSetting, geoDatabase);
            var result  = (await factory.CreateUpdatedEvent(beforeNode, afterNode)).First();

            var expected = new RollbackInvalidRouteNode(beforeNode, "Is not a valid route node update.");

            result.Should().BeOfType(typeof(RollbackInvalidRouteNode)).And.BeEquivalentTo(expected);
        }
Beispiel #7
0
        public async Task CreateUpdatedEvent_ShouldReturnRollbackInvalidRouteNodeOperation_OnRouteNodeMarkAsDeletedSetAndInsectsWithAnyRouteSegments()
        {
            var applicationSetting = A.Fake <IOptions <ApplicationSetting> >();
            var geoDatabase        = A.Fake <IGeoDatabase>();
            var shadowTableNode    = A.Fake <RouteNode>();
            var beforeNode         = A.Fake <RouteNode>();
            var afterNode          = A.Fake <RouteNode>();
            var validationService  = A.Fake <IValidationService>();

            A.CallTo(() => afterNode.Mrid).Returns(Guid.NewGuid());
            A.CallTo(() => afterNode.MarkAsDeleted).Returns(true);
            A.CallTo(() => shadowTableNode.Mrid).Returns(Guid.NewGuid());
            A.CallTo(() => validationService.HasRelatedEquipment(afterNode.Mrid)).Returns(true);
            A.CallTo(() => geoDatabase.GetRouteNodeShadowTable(afterNode.Mrid, false)).Returns(shadowTableNode);
            A.CallTo(() => geoDatabase.GetIntersectingStartRouteSegments(shadowTableNode)).Returns(new List <RouteSegment> {
                A.Fake <RouteSegment>()
            });
            A.CallTo(() => geoDatabase.GetIntersectingEndRouteSegments(shadowTableNode)).Returns(new List <RouteSegment> {
                A.Fake <RouteSegment>()
            });
            A.CallTo(() => afterNode.GetPoint()).Returns(CreatePoint(665931.4446905176, 7197297.75114815));
            A.CallTo(() => shadowTableNode.GetPoint()).Returns(CreatePoint(565931.4446905176, 6197297.75114815));

            var factory = new RouteNodeCommandFactory(applicationSetting, geoDatabase);
            var result  = await factory.CreateUpdatedEvent(beforeNode, afterNode);

            var expected = new RollbackInvalidRouteNode(shadowTableNode, "Is not a valid route node update.");

            using (var scope = new AssertionScope())
            {
                result.Should().HaveCount(1);
                result[0].Should().BeOfType(typeof(RollbackInvalidRouteNode)).And.BeEquivalentTo(expected);
            }
        }
Beispiel #8
0
        public async Task CreateUpdatedEvent_ShouldReturnRouteNodeDeletedEvent_OnRouteNodeMarkAsDeletedSetAndNoIntersectingSegments()
        {
            var applicationSetting   = A.Fake <IOptions <ApplicationSetting> >();
            var geoDatabase          = A.Fake <IGeoDatabase>();
            var beforeNode           = A.Fake <RouteNode>();
            var afterNode            = A.Fake <RouteNode>();
            var shadowTableRouteNode = A.Fake <RouteNode>();
            var appSettings          = new ApplicationSetting {
                Tolerance = 0.01
            };

            var mrid = Guid.NewGuid();

            A.CallTo(() => beforeNode.MarkAsDeleted).Returns(false);
            A.CallTo(() => beforeNode.Mrid).Returns(mrid);
            A.CallTo(() => afterNode.MarkAsDeleted).Returns(true);
            A.CallTo(() => afterNode.Mrid).Returns(mrid);
            A.CallTo(() => afterNode.GetPoint()).Returns(CreatePoint(565931.4446905176, 6197297.75114815));
            A.CallTo(() => shadowTableRouteNode.GetPoint()).Returns(CreatePoint(565930.4446905176, 6197297.75114815));
            A.CallTo(() => applicationSetting.Value).Returns(appSettings);
            A.CallTo(() => geoDatabase.GetRouteNodeShadowTable(afterNode.Mrid, false)).Returns(shadowTableRouteNode);
            A.CallTo(() => geoDatabase.GetIntersectingRouteSegments(afterNode)).Returns(new List <RouteSegment> {
            });

            var factory = new RouteNodeCommandFactory(applicationSetting, geoDatabase);
            var result  = (RouteNodeDeleted)(await factory.CreateUpdatedEvent(beforeNode, afterNode)).First();

            using (new AssertionScope())
            {
                result.RouteNode.Should().Be(afterNode);
            }
        }
        public async Task CreateUpdatedEvent_ShouldThrowArgumentNullException_OnBeingPassedAfterNodeBeingNull()
        {
            var       applicationSetting = A.Fake <IOptions <ApplicationSetting> >();
            var       geoDatabase        = A.Fake <IGeoDatabase>();
            var       beforeNode         = A.Fake <RouteNode>();
            RouteNode afterNode          = null;

            var factory = new RouteNodeCommandFactory(applicationSetting, geoDatabase);

            Func <Task> act = async() => await factory.CreateUpdatedEvent(beforeNode, afterNode);

            await act.Should().ThrowExactlyAsync <ArgumentNullException>();
        }
        public async Task CreateUpdatedEvent_ShouldReturnDoNothing_OnShadowTableRouteNodeBeingNull()
        {
            var       applicationSetting   = A.Fake <IOptions <ApplicationSetting> >();
            var       geoDatabase          = A.Fake <IGeoDatabase>();
            var       beforeNode           = A.Fake <RouteNode>();
            var       afterNode            = A.Fake <RouteNode>();
            RouteNode shadowTableRouteNode = null;

            A.CallTo(() => afterNode.Mrid).Returns(Guid.NewGuid());
            A.CallTo(() => geoDatabase.GetRouteNodeShadowTable(afterNode.Mrid, false)).Returns(shadowTableRouteNode);

            var factory = new RouteNodeCommandFactory(applicationSetting, geoDatabase);

            var result = (await factory.CreateUpdatedEvent(beforeNode, afterNode)).First();

            result.Should().BeOfType(typeof(DoNothing));
        }
Beispiel #11
0
        public async Task CreateUpdatedEvent_ShouldReturnRollbackInvalidRouteNode_OnIntersectingRouteSegment()
        {
            var applicationSetting   = A.Fake <IOptions <ApplicationSetting> >();
            var geoDatabase          = A.Fake <IGeoDatabase>();
            var beforeNode           = A.Fake <RouteNode>();
            var afterNode            = A.Fake <RouteNode>();
            var shadowTableRouteNode = A.Fake <RouteNode>();
            var appSettingsValue     = new ApplicationSetting {
                Tolerance = 0.01
            };

            A.CallTo(() => applicationSetting.Value).Returns(appSettingsValue);
            A.CallTo(() => afterNode.Mrid).Returns(Guid.NewGuid());
            A.CallTo(() => geoDatabase.GetRouteNodeShadowTable(afterNode.Mrid, false)).Returns(shadowTableRouteNode);
            A.CallTo(() => afterNode.GetGeoJsonCoordinate()).Returns("[665931.4446905176,7197297.75114815]");
            A.CallTo(() => afterNode.MarkAsDeleted).Returns(false);
            A.CallTo(() => shadowTableRouteNode.GetGeoJsonCoordinate()).Returns("[565931.4446905176,6197297.75114815]");
            A.CallTo(() => shadowTableRouteNode.MarkAsDeleted).Returns(false);
            A.CallTo(() => afterNode.GetPoint()).Returns(CreatePoint(665931.4446905176, 7197297.75114815));
            A.CallTo(() => shadowTableRouteNode.GetPoint()).Returns(CreatePoint(565931.4446905176, 6197297.75114815));
            A.CallTo(() => geoDatabase.GetIntersectingRouteSegments(afterNode)).Returns(new List <RouteSegment> {
                A.Fake <RouteSegment>()
            });

            var factory = new RouteNodeCommandFactory(applicationSetting, geoDatabase);

            var result = await factory.CreateUpdatedEvent(beforeNode, afterNode);

            var rollbackInvalidRouteNode = (RollbackInvalidRouteNode)result[0];

            var expected = new RollbackInvalidRouteNode(beforeNode, "Update to route node is invalid because it is insecting with route-segments.");

            using (var scope = new AssertionScope())
            {
                result.Should().HaveCount(1);
                rollbackInvalidRouteNode.Should().BeEquivalentTo(expected);
            }
        }