【问题标题】:Servicestack Test: Method not found: 'Int32 ServiceStack.DataAnnotations.CustomFieldAttribute.get_Order()Servicestack 测试:找不到方法:'Int32 ServiceStack.DataAnnotations.CustomFieldAttribute.get_Order()
【发布时间】:2022-01-23 05:24:16
【问题描述】:

尝试构建与 ServiceStack 中的 db 连接的集成测试。 我的 ServiceStack 应用程序运行良好,但是当我运行简单测试时,我在第 22 行收到此错误消息

System.MissingMethodException: '找不到方法:'Int32 ServiceStack.DataAnnotations.CustomFieldAttribute.get_Order()'。'

有一条小鳕鱼:

using ServiceStack;
using ServiceStack.OrmLite;
using ServiceStack.Data;
using NUnit.Framework;
using ServiceStack.DataAnnotations;
using System.Collections.Generic;

namespace oth.Tests.IntegrationTests
{
    public class AppHost2 : AppSelfHostBase
    {
        public AppHost2() : base("Customer REST Example", typeof(CustomerService).Assembly) { }

        public override void Configure(Container container)
        {
            var connectionString =  "Host=localhost;Port=5432;Database=test_1234;Username=postgres;Password=local";
            container.Register<IDbConnectionFactory>(c =>
                new OrmLiteConnectionFactory(connectionString, PostgreSqlDialect.Provider));

            using var db = container.Resolve<IDbConnectionFactory>().Open();
            db.CreateTableIfNotExists<Customer>();
        }
    }

    public class Customer
    {
        [AutoIncrement]
        public int Id { get; set; }

        public string Name { get; set; }
    }
    
    [Route("/customers", "GET")]
    public class GetCustomers : IReturn<GetCustomersResponse> { }
    public class GetCustomersResponse
    {
        public List<Customer> Results { get; set; }
    }


    public class CustomerService : Service
    {
        public object Get(GetCustomers request)
        {
            return new GetCustomersResponse { Results = Db.Select<Customer>() };
        }
    }

    public class CustomerRestExample
    {
        const string BaseUri = "http://localhost:2000/";
        ServiceStackHost appHost;

        public CustomerRestExample()
        {
            //Start your AppHost on TestFixture SetUp
            appHost = new AppHost2()
                .Init()
                .Start(BaseUri);
        }

        [OneTimeTearDown]
        public void OneTimeTearDown() => appHost.Dispose();

        /* Write your Integration Tests against the self-host instance */

        [Test]
        public void Run_Customer_REST_Example()
        {
            var client = new JsonServiceClient(BaseUri);

            var all = client.Get(new GetCustomers());
            Assert.That(all.Results.Count, Is.EqualTo(0));
        }
    }
}

【问题讨论】:

    标签: c# postgresql servicestack ormlite-servicestack


    【解决方案1】:

    当您在使用MyGet pre-release packages 时看到 缺少类型缺少方法 异常时,这意味着您的安装不正确(即使用来自不同版本的预发布包次)。

    在这种情况下,您需要Clear your Nuget packages cache 并再次下载最新的包,以确保您的所有包都来自最新的同一版本:

    $ dotnet nuget locals all -clear
    

    【讨论】:

      猜你喜欢
      • 2015-05-22
      • 1970-01-01
      • 1970-01-01
      • 2016-07-21
      • 1970-01-01
      • 2022-01-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多