Exemplo n.º 1
0
        /// <inheritdoc/>
        public override async Task <IEnumerable <Models.Location> > Handle(LocationParentsQuery param)
        {
            if (param == null)
            {
                throw new ArgumentNullException(nameof(param));
            }

            var locationId = param.LocationId;
            var maxLoops   = MaxLoopIterations;
            var result     = new List <Models.Location>();

            while (locationId != null && (maxLoops--) > 0)
            {
                var id = locationId;

                var item = await DatabaseAccess.GetItemAsync(
                    ConnectionSettings,
                    (Models.Location location) => location.LocationId == id);

                if (item == null)
                {
                    return(Enumerable.Empty <Models.Location>());
                }

                result.Add(item);

                locationId = item.ParentId;
            }

            return(result.AsEnumerable());
        }
Exemplo n.º 2
0
        public async Task Handle_ReturnsEmpty_WhenInvalidLocation()
        {
            // Arrange
            var query = new LocationParentsQuery("invalid");

            // Act
            var results = (await Service.Handle(query)).ToList();

            // Assert
            results.Should().NotBeNull();
            results.Count.Should().Be(0);
        }
Exemplo n.º 3
0
        public async Task Handle_ReturnsAllParents_FromRegion()
        {
            // Arrange
            var query = new LocationParentsQuery("region");

            // Act
            var results = (await Service.Handle(query)).ToList();

            // Assert
            results.Should().NotBeNull();
            results.Count.Should().Be(2);
            results.Count(l => l.Type == LocationType.National).Should().Be(1);
            results.Count(l => l.Type == LocationType.Region).Should().Be(1);
        }
Exemplo n.º 4
0
        public async Task Handle_ReturnsAllParents_FromNational()
        {
            // Arrange
            var locationId = "national";
            var location   = new Mock <MedicalExaminer.Models.Location>();
            var query      = new LocationParentsQuery(locationId);

            var connectionSettings = new Mock <IExaminationConnectionSettings>();
            var dbAccess           = new Mock <IDatabaseAccess>();

            dbAccess.Setup(db => db.GetItemByIdAsync <MedicalExaminer.Models.Location>(
                               connectionSettings.Object,
                               It.IsAny <string>()))
            .Returns(Task.FromResult(location.Object)).Verifiable();

            // Act
            var results = (await Service.Handle(query)).ToList();

            // Assert
            results.Should().NotBeNull();
            results.Count.Should().Be(1);
            results.Count(l => l.Type == LocationType.National).Should().Be(1);
        }