c# - NUnit: Unit Testing Entity Framework ViewModel in WPF MVVM? -
c# - NUnit: Unit Testing Entity Framework ViewModel in WPF MVVM? -
i'm getting started absolute basics of unit testing. i've used beginners tutorial nunit beginners guide guide.
here's test viewmodel has 1 method performs linq query ef. class in same project application now.
namespace diientitlements.tests { [testfixture] public class entitlementsviewmodeltests : notifypropertybase { entitlemententities _context = new entitlemententities(); private observablecollection<vwaccountheader> _accountheadercollection; public observablecollection<vwaccountheader> accountheadercollection { { homecoming _accountheadercollection; } set { _accountheadercollection = value; onpropertychanged("accountheadercollection"); } } [test] public void getaccountheaders() { var query = in _context.vwaccountheaders select a; accountheadercollection = new observablecollection<vwaccountheader>(query); } }
when run test in nunit next exception:
"no connection string named 'entitlemententities' found in application config file"
now presumably because .nunit
test file can't access app.config
connection string within project?
is there work around & best approach or should mocking db testing?
you're getting error because don't have connection string unit testing project.
as mocking, depends on want; usually, on unit testing, test business code , mock integration points(database, web services , on). if need test whole flow, presentation layer database, have integration testing, , don't need mock.
hope helps.
c# wpf entity-framework unit-testing mvvm
Comments
Post a Comment