I'm using VS2010. Silverlight 4, NUnit 2.5.5, and TypeMock
TypemockIsolatorSetup6.0.3.619.msi
In the test project MVVM is implemented, PeopleViewModel is a ViewModel which I want to test.
Please advise if you use other products for unit testing of MVVM Silverlight. Or please help to win this TypeMock. TIA
This is the code of the test:
[Test]
[SilverlightUnitTest]
public void SomeTestAgainstSilverlight()
{
PeopleViewModel o = new PeopleViewModel();
var res = o.People;
Assert.AreEqual(15, res.Count());
}
While running the test in ReSharper i get the following error:
TestA.SomeTestAgainstSilverlight : Failed******************************************
*Loading Silverlight Isolation Aspects...*
******************************************
TEST RESULTS:
---------------------------------------------
System.MissingMethodException : Method not found: 'hv TypeMock.ArrangeActAssert.Isolate.a(System.Delegate)'.
at a4.a(ref Delegate A_0)
at a4.a(Boolean A_0)
at il.b()
at CThru.Silverlight.SilverlightUnitTestAttribute.Init()
at CThru.Silverlight.SilverlightUnitTestAttribute.Execute()
at TypeMock.MockManager.a(String A_0, String A_1, Object A_2, Object A_3, Boolean A_4, Object[] A_5)
at TypeMock.InternalMockManager.getReturn(Object that, String typeName, String methodName, Object methodParameters, Boolean isInjected)
at Tests.TestA.SomeTestAgainstSilverlight() in TestA.cs: line 21
While running test in NUnit i get:
Tests.TestA.SomeTestAgainstSilverlight:
System.DllNotFoundException : Unable to load DLL 'agcore': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
at MS.Internal.XcpImports.Application_GetCurrentNative(IntPtr context, IntPtr& obj)
at MS.Internal.XcpImports.Application_GetCurrent(IntPtr& pApp)
at System.Windows.Application.get_Current()
at ViewModelExample.ViewModel.ViewModelBase.get_IsDesignTime() in C:\Documents and Settings\USER\Desktop\ViewModelExample\ViewModelExample\ViewModel\ViewModelBase.cs:line 20
at ViewModelExample.ViewModel.PeopleViewModel..ctor(IServiceAgent serviceAgent) in C:\Documents and Settings\USER\Desktop\ViewModelExample\ViewModelExample\ViewModel\PeopleViewModel.cs:line 28
at ViewModelExample.ViewModel.PeopleViewModel..ctor() in C:\Documents and Settings\USER\Desktop\ViewModelExample\ViewModelExample\ViewModel\PeopleViewModel.cs:line 24
at Tests.TestA.SomeTestAgainstSilverlight() in C:\Documents and Settings\USER\Desktop\ViewModelExample\Tests\TestA.cs:line 22
UPDATE: I'm not following the question. I've switched to other tools.
This message looks like a mismatched files issue. Try creating a new test project from scratch.
Start by adding references to Typemock.dll and Typemock.ArrangeActAssert.dll. From the CThru directory add both CThru.dll and CThru.Silverlight.dll.
Add a reference to System.Windows (located at C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\Silverlight\v4.0\System.Windows.dll).
Try creating a new test method, and decorate it with SilverlightUnitTest attribute:
using NUnit.Framework;
using CThru.Silverlight;
[TestFixture]
public class SilverlightTest
{
[Test, SilverlightUnitTest]
public void EmptyTest()
{
}
}
Run this empty test. If you're still having the problem you described, please contact support at typemock.com for further assistance.
Related
Using ABP Framework (3.3) and ASP.NET Core (3.1).
I'm attempting to generate swagger.json using Swashbuckle.AspNetCore.Cli (https://github.com/domaindrivendev/Swashbuckle.AspNetCore#retrieve-swagger-directly-from-a-startup-assembly) after compiling the application, pointing to the compiled dll using the following command:
dotnet swagger tofile --output "C:\temp\swagger" .\bin\Release\netcoreapp3.1\MyBin.dll v1
It gives me the below exception:
Unhandled exception. System.ArgumentNullException: Value cannot be null. (Parameter 'provider')
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceCollectionCommonExtensions.GetRequiredService[T](IServiceCollection services)
at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
at System.Lazy`1.CreateValue()
at System.Lazy`1.get_Value()
at Volo.Abp.AspNetCore.Mvc.AbpDataAnnotationAutoLocalizationMetadataDetailsProvider.CreateDisplayMetadata(DisplayMetadataProviderContext context)
at Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.DefaultCompositeMetadataDetailsProvider.CreateDisplayMetadata(DisplayMetadataProviderContext context)
at Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.DefaultModelMetadata.get_DisplayMetadata()
at Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.DefaultModelMetadata.get_Order()
at Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.DefaultModelMetadata.<>c.<get_Properties>b__78_0(ModelMetadata p)
at System.Linq.EnumerableSorter`2.ComputeKeys(TElement[] elements, Int32 count)
at System.Linq.EnumerableSorter`1.ComputeMap(TElement[] elements, Int32 count)
at System.Linq.EnumerableSorter`1.Sort(TElement[] elements, Int32 count)
at System.Linq.OrderedEnumerable`1.ToList()
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Microsoft.AspNetCore.Mvc.ModelBinding.ModelPropertyCollection..ctor(IEnumerable`1 properties)
at Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.DefaultModelMetadata.get_Properties()
at Microsoft.AspNetCore.Mvc.ModelBinding.ModelMetadataProviderExtensions.GetMetadataForProperty(IModelMetadataProvider provider, Type containerType, String propertyName)
at Microsoft.AspNetCore.Mvc.ApplicationModels.DefaultApplicationModelProvider.CreatePropertyModel(PropertyInfo propertyInfo)
at Microsoft.AspNetCore.Mvc.ApplicationModels.DefaultApplicationModelProvider.OnProvidersExecuting(ApplicationModelProviderContext context)
at Microsoft.AspNetCore.Mvc.ApplicationModels.ApplicationModelFactory.CreateApplicationModel(IEnumerable`1 controllerTypes)
at Microsoft.AspNetCore.Mvc.ApplicationModels.ControllerActionDescriptorProvider.GetDescriptors()
at Microsoft.AspNetCore.Mvc.ApplicationModels.ControllerActionDescriptorProvider.OnProvidersExecuting(ActionDescriptorProviderContext context)
at Microsoft.AspNetCore.Mvc.Infrastructure.DefaultActionDescriptorCollectionProvider.UpdateCollection()
at Microsoft.AspNetCore.Mvc.Infrastructure.DefaultActionDescriptorCollectionProvider.Initialize()
at Microsoft.AspNetCore.Mvc.Infrastructure.DefaultActionDescriptorCollectionProvider.get_ActionDescriptors()
at Microsoft.AspNetCore.Mvc.ApiExplorer.ApiDescriptionGroupCollectionProvider.get_ApiDescriptionGroups()
at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GetSwagger(String documentName, String host, String basePath)
at Swashbuckle.AspNetCore.Cli.Program.<>c.<Main>b__0_3(IDictionary`2 namedArgs) in C:\projects\ahoy\src\Swashbuckle.AspNetCore.Cli\Program.cs:line 72
at Swashbuckle.AspNetCore.Cli.CommandRunner.Run(IEnumerable`1 args) in C:\projects\ahoy\src\Swashbuckle.AspNetCore.Cli\CommandRunner.cs:line 68
at Swashbuckle.AspNetCore.Cli.CommandRunner.Run(IEnumerable`1 args) in C:\projects\ahoy\src\Swashbuckle.AspNetCore.Cli\CommandRunner.cs:line 68
at Swashbuckle.AspNetCore.Cli.Program.Main(String[] args) in C:\projects\ahoy\src\Swashbuckle.AspNetCore.Cli\Program.cs:line 111
I've tried also creating a public class as per the Swashbuckle docs, as we are using Autofac:
public class SwaggerHostFactory
{
public static IHost CreateHost()
{
return Program.CreateHostBuilder(new string[0]).Build(); //Calls the same builder that's used to run the app
}
}
The intent is to allow running this in our pipelines to auto-generate ApiClient libraries.
I'm at a bit of a loss as to how to resolve this. The swagger.json is generated at runtime perfectly fine?
Any help appreciated!
One way to avoid this is to make sure your program continues without these app settings
var connectionString = config["MyConnectionString"];
if (connectionString != null)
{
services.AddDbContext<AppDbContext>(options =>
options.UseSqlServer(connectionString));
}
You can get the Swagger.json in a simple way without Swagger CLI.
Run your web with the dotnet command:
dotnet MyCompanyName.MyProjectName.Web.dll
Then download the Swagger.json with the following Powershell command:
Invoke-WebRequest -Uri https://localhost:5001/swagger/v1/swagger.json -OutFile c:\temp\swagger.json
Asp.Net Core integration testing seems pretty simple but for the life of me I can't test the starter app with my react dev server. It runs fine from a browser so I assume node, npm and react are set up correctly but not under xUnit. It fails with the following exception:
System.AggregateException: One or more errors occurred. ---> System.AggregateException: One or more errors occurred. ---> System.InvalidOperationException: Failed to start 'npm'. To resolve this:.
[1] Ensure that 'npm' is installed and can be found in one of the PATH directories.
Current PATH enviroment variable is: {PATH}
Make sure the executable is in one of those directories, or update your PATH.
[2] See the InnerException for further details of the cause. ---> System.ComponentModel.Win32Exception: The directory name is invalid
...
I assume this is because it can't find the content root of my spa so I have tried adding to my web host builder with no luck:
.UseSolutionRelativeContentRoot( "Solution Relative Path to My App" ) );
This is my test class:
public class SampleDataControllerTest
{
private readonly TestServer server;
private readonly HttpClient client;
public SampleDataControllerTest()
{
server = new TestServer( WebHost.CreateDefaultBuilder()
.UseStartup<Startup>()
.UseSolutionRelativeContentRoot( "Solution Relative Path to My App" ) );
.UseEnvironment( "Development" );
client = server.CreateClient();
}
[Fact]
public async Task RootTest()
{
HttpResponseMessage page = await client.GetAsync( "/" );
Assert.NotNull( page );
Assert.Equal( HttpStatusCode.OK, page.StatusCode );
}
What am I missing?
The trick for me was setting the development environment variable to point to the directory where the packages.json file resides.
Below is an excerpt of the constructor of my xUnit integration test class.
Note that it first determines the solution directory (using GetExecutingAssembly().Location), and then points to the web source project folder. (In our environment, Client.React is a directory under the solution directory that contains the packages.json file).
Then, the directory is set using Directory.SetCurrentDirectory, followed by the test server being set up wit hthe UseWebRoot, again pointing to the directory where the packages.json file resides.
Startup is the ASP.NET web startup class.
/// <summary>
/// Constructor
/// </summary>
public IntegrationTest() : base()
{
var testAssemblyPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
// Remove the "\\bin\\Debug\\netcoreapp2.1"
var solutionPath = Directory.GetParent(testAssemblyPath.Substring(0, testAssemblyPath.LastIndexOf(#"\bin\", StringComparison.Ordinal))).FullName;
var clientReactPath = Path.Join(solutionPath, "Client.React");
// Important to ensure that npm loads and is pointing to correct directory
Directory.SetCurrentDirectory(clientReactPath);
var server = new TestServer(new WebHostBuilder()
.UseEnvironment("Development")
.UseWebRoot(clientReactPath)
.UseStartup<Startup>());
_client = server.CreateClient();
}
I saw you answered a question for another user for a similar issue and was hoping you could help.
I'm trying to build a settings page for my module.....the module actually works ok, its just when I added a new settings ascx page I started having problems.
My code behind on the settings page
using System;
using DotNetNuke.Entities.Modules;
namespace Ukiset.Registration
{
public partial class Settings : ModuleSettingsBase
{
protected void Page_Load(object sender, EventArgs e)
{
}
public override void LoadSettings()
{
base.LoadSettings();
}
public override void UpdateSettings()
{
base.UpdateSettings();
}
}
}
My design view on settings.ascx
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="Settings.ascx.cs" Inherits="Ukiset.Registration.Settings" %>
This is what i'm getting from the event viewer when it throws an error
<pre>
AbsoluteURL:/Default.aspx
DefaultDataProvider:DotNetNuke.Data.SqlDataProvider, DotNetNuke
ExceptionGUID:d1050063-f221-43ad-8118-571e7d9818a4
AssemblyVersion:
PortalId:-1
UserId:-1
TabId:-1
RawUrl:
Referrer:
UserAgent:
ExceptionHash:SOKwQeZDhciTuPHTIxGH0w==
Message:Could not load type 'MySite.Registration.Settings'.
StackTrace:
</pre>
in my build output path I have pointed it to C:\DNN\MyDNNSite\bin\ yet it still throws this problem, can you help?
Your problem appears to be a Namespace issue.
MySite.Registration.Settings
vs
Ukiset.Registration.Settings
Do you have "MySite" anywhere in your project? Perhaps you've got an ASCX file that still points to MySite.Registration.Settings instead of Ukiset.Registration.Settings?
Is your development solution/project inside of C:\DNN\MyDNNSite\DesktopModules\ ?
As for the BIN folder, after you compile, are you getting the DLL in the c:\dnn\mydnnsite\bin folder?
I am developing a web application that is using Entity Freamwork 5 Visual Studio 2012 and it need to support both SQL Server and Oracle database providers. I created entity model for Oracle Database. I thought it would work after some changes in connectionstrings, bu no it is not that easy .. I found this post:
http://www.codeproject.com/Articles/82017/Preparing-an-Entity-Framework-model-for-multi-prov
Now I am getting following error
Schema specified is not valid. Errors: my_s_entity.ssdl(2,12) :
warning 0005: Could not find schema information for the attribute
'Version'. my_s_entity.ssdl(2,2) : error 0010: The element Edmx in
namespace http://schemas.microsoft.com/ado/2009/11/edmx was unexpected
for the root element. The expected Schema in one of the following
namespaces: http://schemas.microsoft.com/ado/2006/04/edm/ssdl,
http://schemas.microsoft.com/ado/2009/02/edm/ssdl,
http://schemas.microsoft.com/ado/2009/11/edm/ssdl.
Stack trace:
[MetadataException: Schema specified is not valid. Errors:
my_s_entity.ssdl(2,12) : warning 0005: Could not find schema information for the attribute 'Version'.
my_s_entity.ssdl(2,2) : error 0010: The element Edmx in namespace http://schemas.microsoft.com/ado/2009/11/edmx was unexpected for the root element. The expected Schema in one of the following namespaces: http://schemas.microsoft.com/ado/2006/04/edm/ssdl, http://schemas.microsoft.com/ado/2009/02/edm/ssdl, http://schemas.microsoft.com/ado/2009/11/edm/ssdl.]
System.Web.UI.WebControls.EntityDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +965
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +21
System.Web.UI.WebControls.DataBoundControl.PerformSelect() +138
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +30
System.Web.UI.WebControls.GridView.DataBind() +4
System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +105
System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +75
System.Web.UI.Control.EnsureChildControls() +83
System.Web.UI.Control.PreRenderRecursiveInternal() +42
System.Web.UI.Control.PreRenderRecursiveInternal() +168
System.Web.UI.Control.PreRenderRecursiveInternal() +168
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +974
I have searched on web but not able to find any solution. Why I am getting this issue? If anyone have every faced same and have any solution please share.
Add a project reference to EntityFramework.SqlServer.dll
I had this error, This solution works for me
public MyContext : DbContext
{
public MyContext() : base("name=MyContext")
{
// the terrible hack
var ensureDLLIsCopied =
System.Data.Entity.SqlServer.SqlProviderServices.Instance;
}
If you open Your edmx file in the xml editor it should look like this:
<edmx:Edmx Version="2.0" xmlns:edmx="http://schemas.microsoft.com/ado/2008/10/edmx">
<edmx:Runtime>
<edmx:StorageModels>
<Schema Namespace="XXX.Store" Alias="Self" Provider="System.Data.SqlClient" ProviderManifestToken="2008" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns="http://schemas.microsoft.com/ado/2009/02/edm/ssdl">
There is a relationship between the xmlns namespace and the Version of EF you are using. There is some mismatch in the EF Version you created the model With and where you are trying to use it.
I am creating a simple REST API via Google app engine. I have Task and Project objects. A Project can have one or more Tasks. Here is some details about these data objects:
#Entity
public class Project implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Key id;
private String title;
private String description;
private Date createdAt;
// Section 1
// #OneToMany(mappedBy = "project")
// private List<Task> tasks;
// ...
}
#Entity
public class Task implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private Key id;
private String shortDescription;
private String longDescription;
private Date createdAt;
private Date dueDate;
private boolean completed;
// Section 2
// #ManyToOne
// #JoinColumn(name = "id_project")
// private Project project;
// ...
}
The way I implemented the class above works fine (Section 1 and Section 2 are commented out). However, what I want to do is to relate Task objects to Project. Whenever I remove the comments above and activate Section 1 and Section 2 the errors below occur.
The error appears for Project operations
HTTP ERROR 500
Problem accessing /api/project. Reason:
Could not initialize class com.aspect.todo.dao.EMFService
Caused by:
java.lang.NoClassDefFoundError: Could not initialize class com.aspect.todo.dao.EMFService
at com.aspect.todo.dao.Dao.getProjects(Dao.java:144)
at com.aspect.todo.server.ProjectService.get(ProjectService.java:23)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
...
The error appears for Task operations
HTTP ERROR 500
Problem accessing /api/task. Reason:
INTERNAL_SERVER_ERROR
Caused by:
java.lang.ExceptionInInitializerError
at com.aspect.todo.dao.Dao.getTasks(Dao.java:98)
at com.aspect.todo.server.TaskService.get(TaskService.java:24)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
...
Caused by:
javax.persistence.PersistenceException: Provider error. Provider: org.datanucleus.store.appengine.jpa.DatastorePersistenceProvider
at javax.persistence.Persistence.createFactory(Persistence.java:176)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:112)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:66
...
Caused by:
Errors were encountered when initialising the specified MetaData. See the nested exceptions for details
org.datanucleus.exceptions.NucleusUserException: Errors were encountered when initialising the specified MetaData. See the nested exceptions for details
at org.datanucleus.metadata.MetaDataManager.initialiseFileMetaDataForUse(MetaDataManager.java:892)
at org.datanucleus.metadata.MetaDataManager.loadPersistenceUnit(MetaDataManager.java:794)
at org.datanucleus.jpa.EntityManagerFactoryImpl.initialisePMF(EntityManagerFactoryImpl.java:488)
...
Caused by:
Found Meta-Data for class com.aspect.todo.model.Task but this class is not enhanced!! Please enhance the class before running DataNucleus.
org.datanucleus.exceptions.NucleusUserException: Found Meta-Data for class com.aspect.todo.model.Task but this class is not enhanced!! Please enhance the class before running DataNucleus.
at org.datanucleus.metadata.MetaDataManager.initialiseClassMetaData(MetaDataManager.java:2225)
at org.datanucleus.metadata.MetaDataManager.initialiseFileMetaData(MetaDataManager.java:2176)
at org.datanucleus.metadata.MetaDataManager.initialiseFileMetaDataForUse(MetaDataManager.java:881)
...
The weird thing is when I start with these sections commented out, compile and run and then activate only Section 2 and rerun it works fine. If close and reopen Eclipse try again the error occurs again.
NOTE: Datanucleus JDO/JPA version: v1
Found Meta-Data for class com.aspect.todo.model.Task but this class is not enhanced!!
Please enhance the class before running DataNucleus.
The fact is that the classes are not enhanced at runtime and you have to find a way to enhance them prior to runtime that works for your environment ... Maven, Ant, command-line, DataNucleus Eclipse plugin, or GAE Eclipse plugin.
If you are using ANT then add the below lines in your build.xml before </project> tag close
<target name="datanucleusenhance" depends="compile"
description="Performs JDO enhancement on compiled data classes.">
<enhance_war war="war" />
And give the following command when build the ant "ant datanucleusenhance runserver"
Hope this is useful, it took me a while to find the solution.
Just upgrade your GAE SDK, it solved the problem for me.
Found Meta-Data for class com.aspect.todo.model.Task but this class is not enhanced!!
Please enhance the class before running DataNucleus.
I'll show here a way to enhance classes in Gradle environment. Use the following configuration.
Dependencies:
dependencies {
appengineSdk 'com.google.appengine:appengine-java-sdk:<version>'
compile 'org.datanucleus:datanucleus-enhancer:<version>'
compile 'org.datanucleus:datanucleus-api-jpa:<version>' // or datanucleus-api-jdo
/* other dependencies */
}
Plugin:
(for gradle-appengine-plugin version 1.9.5 or higher)
appengine {
enhancer {
version = "v2"
api = "jpa" // or "jdo"
enhanceOnBuild = true
}
/*...*/
}
(for older versions of gradle-appengine-plugin)
appengine {
enhancerVersion = "v2"
}
To make enhance run automatically before creating the war in your build.gradle file:
war.dependsOn appengineEnhance
If you have problems executing task :appengineEnhance, try to run it with --stacktrace (to view the stacktrace) or --info (to find the location of the error log file) options.