コード例 #1
0
 public static WoodyPlantDetailModel ToDetail(this WoodyPlantDocument doc)
 {
     return(new WoodyPlantDetailModel
     {
         Id = doc.Id,
         LocalizedNames = doc.LocalizedNames.ToModel(),
         LocalizedNotes = doc.LocalizedNotes.ToModel(),
         LocalizedSpecies = doc.LocalizedSpecies.ToModel(),
         ImageUrls = doc.ImageUrls,
         Location = doc.Location.ToModel()
     });
 }
コード例 #2
0
        public async Task HandleGet_Exception_TestAsync()
        {
            var id            = ObjectId.GenerateNewId();
            var request       = new GetWoodyPlantRequest(id);
            var expectedPlant = new WoodyPlantDocument {
                Id = id
            };

            fWoodyPlantsRepository
            .GetByIdAsync(Arg.Is(id), Arg.Is(default(CancellationToken)))
            .Returns((WoodyPlantDocument?)null);

            await Assert.ThrowsAsync <NotFoundException>(async() => await new WoodyPlantsRequestHandler(fWoodyPlantsRepository, fVersionRepository).Handle(request, default));
        }
コード例 #3
0
        public static WoodyPlantPreviewModel ToPreview(this WoodyPlantDocument doc)
        {
            if (doc is null)
            {
                throw new ArgumentNullException(nameof(doc));
            }

            return(new WoodyPlantPreviewModel
            {
                Id = doc.Id,
                LocalizedNames = doc.LocalizedNames.ToModel(),
                LocalizedNotes = doc.LocalizedNotes.ToModel(),
                LocalizedSpecies = doc.LocalizedSpecies.ToModel(),
                ImageUrls = doc.ImageUrls,
                Location = doc.Location.ToModel()
            });
        }
コード例 #4
0
        public async Task HandleGet_Success_TestAsync()
        {
            var id            = ObjectId.GenerateNewId();
            var request       = new GetWoodyPlantRequest(id);
            var expectedPlant = new WoodyPlantDocument
            {
                Id             = id,
                TextMatchScore = 5,
                ImageUrls      = new[] { "http://obj.cz" },
                Location       = new LocationDocument {
                    Name = "Loc", Geometry = new PointGeometry()
                },
                InnerWoodyPlantIds = Array.Empty <ObjectId>(),
                LocalizedNames     = new LocalizedStringDocument {
                    Czech = "name"
                },
                LocalizedNotes = new LocalizedStringDocument {
                    Czech = "note"
                },
                LocalizedSpecies = new LocalizedStringDocument {
                    Czech = "specie"
                },
                Type    = PlantType.AreaOfTrees,
                Version = null,
            };

            fWoodyPlantsRepository
            .GetByIdAsync(Arg.Is(id), Arg.Is(default(CancellationToken)))
            .Returns(expectedPlant);

            var result = await new WoodyPlantsRequestHandler(fWoodyPlantsRepository, fVersionRepository).Handle(request, default);

            Assert.NotNull(result);
            Assert.Equal(expectedPlant.Id, result.Id);
            Assert.Equal(expectedPlant.LocalizedSpecies.Czech, result.LocalizedSpecies.Czech);
            Assert.Equal(expectedPlant.LocalizedNames.Czech, result.LocalizedNames.Czech);
            Assert.Equal(expectedPlant.LocalizedNotes.Czech, result.LocalizedNotes.Czech);
            Assert.Equal(expectedPlant.Location.Name, result.Location !.Name);
            Assert.Equal(expectedPlant.Location.Geometry.Type, result.Location.Geometry !.Type);
            var image = Assert.Single(result.ImageUrls);

            Assert.Equal("http://obj.cz", image);
        }