public async Task Updates_ApiDocument_On_Existing_Item()
            {
                var model = new ServiceApiDescriptionBuilder().WithServiceId("Updates_DisplayName_On_Existing_Item").Build();

                using (var context = new RepositoryDbContext(DbContextOptions, StoreOptions))
                {
                    context.Apis.Add(model.ToEntity());
                    context.SaveChanges();
                }

                model.ApiDocument.Info.Title = "New title";

                using (var context = new RepositoryDbContext(DbContextOptions, StoreOptions))
                {
                    var store = new ApiStore(context, new Mock <ILogger <ApiStore> >().Object);
                    await store.StoreAsync(model);
                }

                using (var context = new RepositoryDbContext(DbContextOptions, StoreOptions))
                {
                    var item = context.Apis.SingleOrDefault(s => s.ServiceId == model.ServiceId);
                    item.Should().NotBeNull();

                    var document = OpenApiDocumentHelper.ReadFromJson(item.ApiDocument);

                    document.Info.Title.Should().Be(model.ApiDocument.Info.Title);
                }
            }
Ejemplo n.º 2
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            if (reader.TokenType == JsonToken.StartObject)
            {
                JObject item = JObject.Load(reader);

                return(OpenApiDocumentHelper.ReadFromJson(item.ToString()));
            }

            return(null);
        }
        public void UpdateEntity_Updates_ApiDocument()
        {
            var model  = new ServiceApiDescriptionBuilder().Build();
            var entity = model.ToEntity();

            model.ApiDocument.Info.Title = "UpdateEntity_Updates_ApiDocument";
            model.UpdateEntity(entity);

            var document = OpenApiDocumentHelper.ReadFromJson(entity.ApiDocument);

            document.Info.Title.Should().Be(model.ApiDocument.Info.Title);
        }
        public void Maps_All_Properties()
        {
            var model  = new ServiceApiDescriptionBuilder().Build();
            var entity = model.ToEntity();

            entity.ServiceId.Should().Be(model.ServiceId);

            var document = OpenApiDocumentHelper.ReadFromJson(entity.ApiDocument);

            var newmodel = entity.ToModel();

            newmodel.ApiDocument.Info.Title.Should().Be(model.ApiDocument.Info.Title);
            document.Info.Title.Should().Be(model.ApiDocument.Info.Title);
        }
        /// <summary>
        /// Creates a new instance of the service mapper profile
        /// </summary>
        public ApiDescriptionMapperProfile()
        {
            CreateMap <ServiceApiDescription, ApiDescription>()
            .ForMember(dest => dest.Id, opt => opt.Ignore());

            CreateMap <string, OpenApiDocument>()
            .ConstructUsing(src => OpenApiDocumentHelper.ReadFromJson(src))
            .ForMember(dest => dest.Components, opt => opt.Ignore())
            .ForMember(dest => dest.Extensions, opt => opt.Ignore())
            .ForMember(dest => dest.ExternalDocs, opt => opt.Ignore())
            .ForMember(dest => dest.Info, opt => opt.Ignore())
            .ForMember(dest => dest.Paths, opt => opt.Ignore())
            .ForMember(dest => dest.SecurityRequirements, opt => opt.Ignore())
            .ForMember(dest => dest.Servers, opt => opt.Ignore())
            .ForMember(dest => dest.Tags, opt => opt.Ignore())
            ;

            CreateMap <OpenApiDocument, string>()
            .ConstructUsing(src => src.ToJson());
        }