Error in MVC4 application while trying to run unit-test with the tool Effort: The type date is not a qualified namespace

StackOverflow https://stackoverflow.com/questions/20332912

Question

I am doing everything I can to create unit tests on my MVC4 project. To do this I am using the Entity Framework Unit Testing Tool Effort (as described in this tutorial. This tool creates a database/context in memory on which tests can be run.

The connection string works in my main project. But when I try to use it from my Test project while running the following test:

[TestInitialize]
    public void Initialize()
    {
        DbConnection connection = Effort.DbConnectionFactory.CreateTransient();

        using (var context = new seashell_brawl_corveeContext(connection))
        {
            // Add test data to the database here
            context.Products.Add(new Product() { ProductId = 1 });
        }

        //_context 
    }

the test fails with the following resulting message:

Initialization method Project.Tests.Controllers.ShoppingCartTest.Initialize threw exception.  
System.Data.MetadataException: System.Data.MetadataException: Schema specified is not valid. 
Errors: 

(47,6) : error 0040: The Type date is not qualified with a namespace or alias. Only primitive 
types can be used without qualification.

(57,6) : error 0040: The Type date is not qualified with a namespace or alias. Only primitive 
types can be used without qualification.

(76,6) : error 0040: The Type date is not qualified with a namespace or alias. Only primitive 
types can be used without qualification..

And the stack trace can be found in this gist.

Does anybody know how to resolve this issue? Do I refer to my connection string correctly? I have no reference to my connectionstring in the Project.Test app.config file. All my data types with dates have the following attributes:

[Column(TypeName = "Date")]
[DataType(DataType.DateTime)]

Should this be changed to something else?

I hope someone can give me a hint in the right direction.

Was it helpful?

Solution

There is no "Date" type in .NET. There are DateTime and DateTimeOffset types, but even the Date property of a DateTime object is a DateTIme.

I'm also not sure what a "TypeName" property of the Column attribute is. It's not in the documentation

Also, nowhere in your sample is lower case d, "date" shown, so I'm not sure where "date" is coming from in the error.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top