首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Servicestack测试:未找到方法:'Int32 Int32

Servicestack测试:未找到方法:'Int32 Int32
EN

Stack Overflow用户
提问于 2021-12-21 20:41:02
回答 1查看 132关注 0票数 1

试图在ServiceStack中构建与db连接的集成测试。我的ServiceStack应用程序运行良好,但是当我运行简单测试时,我得到了如下错误消息:22

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

这里有一种小鳕鱼:

代码语言:javascript
复制
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));
        }
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-12-22 00:34:54

每当您看到缺少类型的缺少的方法异常时,使用MyGet预发布包就意味着安装很脏(即使用来自不同构建时间的预发布包)。

在这种情况下,您需要清除Nuget包缓存并再次下载最新的包,这将确保您的所有包都来自最新的相同构建:

代码语言:javascript
复制
$ dotnet nuget locals all -clear
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70441382

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档