I am trying to run a test project, but I have no success, because I have a failure when connecting npgsql. I reinstalled Npgsql, Npgsql.EntityFramework, EntityFramwork ... but the problem persists. Report Results:
Testing the test TestUserControl.ControleBaseTest.TesteGetPermissoesUsuarioFixo gerou exceção:
System.NotSupportedException: Unable to determine the provider name for the factory provider of type 'Npgsql.NpgsqlFactory'. Verify that the ADO.NET provider is installed or registered in the application configuration. StackTrace Result:
I have an app.config file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<entityFramework>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, Npgsql.EntityFramework"> </provider>
</providers>
<defaultConnectionFactory type="Npgsql.NpgsqlConnectionFactory, Npgsql" />
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="Npgsql" />
<add name="Npgsql Data Provider" invariant="Npgsql" support="FF" description=".Net Framework Data Provider for Postgresql" type="Npgsql.NpgsqlFactory, Npgsql" />
</DbProviderFactories>
</system.data>
</configuration>
And DbConfig ...
public class CtxUser : DbContext
{
public CtxUser(string conexao) : base(conexao) { }
public CtxUser(DbConnection conexao) : base(conexao, true) { }
}
My model ...
[Serializable]
[Table("mytable", Schema = "public")]
public class Users
{
[Key, Column("userid")]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int UserId { get; set; }
[Column("login")]
public string Login { get; set; }
[Column("password")]
public string Password { get; set; }
}
My boolean class ...
private DbConnection Conexao { get; set; }
public ControleBase(DbConnection connector)
{
if(conexao == null)
throw new ArgumentException("blah blah", "connector");
Conexao = conexao;
}
public Usuarios GetUser(int id)
{
if(id <= 0)
throw new ArgumentException("blah blah");
Users user;
using (var ctx = new CtxUser(Connection))
{
user = ctx.DbUser.Find(id);
}
return user;
}
My testing method ...
[TestClass]
public class ControleBaseTest
{
private DbConnection Conexao
{
get
{
var cnxBuilder = new NpgsqlConnectionStringBuilder
{
Database = "mydatabase",
Host = "localhost",
Port = 5432,
UserName = "postgres",
Password = "postgres",
Enlist = true,
CommandTimeout = 30,
Timeout = 30,
Pooling = true,
MinPoolSize = 1,
MaxPoolSize = 20,
Compatible = new Version(2, 1),
PreloadReader = true
};
return new NpgsqlConnection(cnxBuilder);
}
}
[TestMethod]
public void TestGetUser()
{
IUserControl userControl = new ControleBase(Conexao);
var usuario = userControl.GetUsuario(9);
Assert.IsNotNull(usuario);
}
}
, Npgsql linq .. . - ?