Setting apartment state for using WatIn with MSTest - visual-studio-2010

I am getting the following error in:
The CurrentThread needs to have it's ApartmentState set to ApartmentState.STA to be able to automate Internet Explorer.
With the following code:
[TestClass]
public class UnitTest1
{
[AssemblyInitialize]
public static void AssemblySetup(TestContext context)
{
}
[TestMethod]
[HostType("ASP.NET")]
[AspNetDevelopmentServerHost("C:\\SomePath", "/")]
[UrlToTest("http://localhost/HomeView.aspx")]
public void TestMethod1()
{
using(IE ie = new IE("http://localhost/HomeView.aspx",true))
{
ie.TextField(Find.ById("MainContent_txtDLNumber")).TypeText("a235801945550");
}
}
}
Is there a different approach for using WatIn with MsTest?

You will probably need to adjust your config accordingly, below should give you a clue
<configuration>
<configSections>
<sectionGroup name="NUnit">
<section name="TestRunner" type="System.Configuration.NameValueSectionHandler"/>
</sectionGroup>
</configSections>
<NUnit>
<TestRunner>
<!-- Valid values are STA,MTA. Others ignored. -->
<add key="ApartmentState" value="STA" />
</TestRunner>
</NUnit>
</configuration>

Consider updating your code to use NUnit 2.5 with RequiresSTA attribute.

Try this instead:
[STAThread]
static void Main(string[] args)
{
}

Related

IBM: Add a workflow extension in TIM/SIM

I make my first workflow extension today, and the result isn't really good ! :)
I have this error :
CTGIMA411E The sendResult( workflow extension method in the com.orange.tiger.itim.extension.workflow.ResultCallback class cannot be processed.
And the trace.log file:
java.lang.ClassNotFoundException: com.orange.tiger.itim.extension.workflow.ResultCallback
Here this my java code :
package com.orange.tiger.itim.extension.workflow;
//my import
public class ResultCallback implements WorkflowApplication {
private WorkflowExecutionContext context;
private WorkflowProcessEntity processEntity;
public void setContext() {
this.context = null;
}
#Override
public void setContext(WorkflowExecutionContext context) {
//code
}
}
I modify the xml file:
<ACTIVITY ACTIVITYID="sendResult" LIMIT="600000">
<IMPLEMENTATION_TYPE>
<APPLICATION CLASS_NAME="com.orange.tiger.itim.extension.workflow.ResultCallback" METHOD_NAME="sendResult" />
</IMPLEMENTATION_TYPE>
<TRANSITION_RESTRICTION SPLIT="XOR" />
<PARAMETERS>
<IN_PARAMETERS PARAM_ID="summary" TYPE="String" />
<IN_PARAMETERS PARAM_ID="description" TYPE="String" />
</PARAMETERS>
<SCRIPT EVENT="onComplete">
<![CDATA[WorkflowRuntimeContext.setProcessResult(WorkflowRuntimeContext.getActivityResult());
WorkflowRuntimeContext.setProcessResultDetail(WorkflowRuntimeContext.getActivityResultDetail()); ]]>
</SCRIPT>
</ACTIVITY>
I add my jar in /opt/application/tgrtim/products/itim/lib/.
And finally I restart TIM via NDM console.
Maybe I missed something ? Or I did something wrong?
Thanks
I finally found, I forgot to modify a xml file :
/opt/websphere/7.0/profiles/Dmgr01/config/cells/udgis116Cell01/libraries.xml
And add this line : < classPath>${ITIM_HOME}/lib/result-callback.jar< /classPath>
You can also add result-callback.jar directly on Websphere under Environment -> Shared Libraries -> ITIM_LIB -> ${ITIM_HOME}/lib/result-callback.jar

Reading appsettings in Nancy

I have a web api in Nancy 1.4.3. I have defined some settings in web.config under applicationSettings section. I was wondering how can I read these settings in a Nancy module (or Bootstrapper)? Because the conventional ways of reading these settings as in MVC/WebAPI are not available in Nancy.
Please consider that I am using Nancy 1.4.3 not Nancy 2x and .net 4.6.1 not .net core.
For simplicity, I am writing how the applicationSettings section looks like in web.config:
<applicationSettings>
<Applicaton1.Properties.Settings>
<setting name="DefaultUserID" serializeAs="String">
<value>BatchReader</value>
</setting>
<setting name="DefaultPaymentFrequencyCode" serializeAs="String">
<value>0</value>
</setting>
<setting name="DefaultPaymentTypeCode" serializeAs="String">
<value>1</value>
</setting>
</Application1.Properties.Settings>
You should be able to read it exactly the same as any asp.net app.
Make sure you add reference to:
System.Configuration
In Web.config add your key:
<appSettings>
<add key="key" value="hello key" />
</appSettings>
Include System.Configuration in your Bootstrapper:
namespace Test
{
using System.Configuration;
using Nancy;
using Nancy.Authentication.Forms;
using Nancy.Bootstrapper;
using Nancy.TinyIoc;
public class Bootstrapper : DefaultNancyBootstrapper
{
protected override void ApplicationStartup (TinyIoCContainer container,
IPipelines pipelines)
{
base.ApplicationStartup (container, pipelines);
StaticConfiguration.DisableErrorTraces = false;
StaticConfiguration.EnableRequestTracing = true;
}
protected override void ConfigureApplicationContainer (TinyIoCContainer
container)
{
base.ConfigureApplicationContainer (container);
var key = ConfigurationManager
.AppSettings.Get ("key")
}
protected override void ConfigureRequestContainer (TinyIoCContainer container,
NancyContext context)
{
base.ConfigureRequestContainer (container, context);
}
protected override void RequestStartup (TinyIoCContainer container,
IPipelines pipelines,
NancyContext context)
{
base.RequestStartup (container, pipelines, context);
}
}
}
Thats it! :)
What conventional ways would you use in WebApi that are missing in Nancy ?
For a web app I think you should really be using System.Web.Configuration:
using System.Web.Configuration
For example:
var someVar = WebConfigurationManager.AppSettings["SomeSetting"];
See here for more information.

Registering HttpHandler in ASP.NET MVC 3 and getting 404 Not Found Error

I made a custom handler for test purposes, which looks like:
namespace MVCHttpHandlerProject
{
public class SomeHandler : IHttpHandler
{
public bool IsReusable
{
get { return true; }
}
public void ProcessRequest(HttpContext context)
{
context.Response.Write("SomeHandler test");
}
}
}
Then I added to my web.config next lines:
<httpHandlers>
<add path="SomeHandler.axd" verb="*" type="MVCHttpHandlerProject.SomeHandler, MVCHttpHandlerProject" /></httpHandlers>
and in <system.webServer>
<handlers>
<add path="SomeHandler.axd" verb="*" type="MVCHttpHandlerProject.SomeHandler, MVCHttpHandlerProject" name="SomeHandler.axd"/>
</handlers>
My Global.asax.cs was not modified and looks exactly as when it was generated with routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); in RegisterRoutes method.
Still, when I try to get to "http://localhost/Home/SomeHandler.axd", "The resource cannot be found" error occurs. Why? Did I miss something? How should I fix this?
You should be requesting http://localhost/SomeHandler.axd instead of http://localhost/Home/SomeHandler.axd. There's no Home.

dotlesscss does not show errors

There's something wrong with my css because no styles are being added to my website after compilation.
How do I get dotlesscss to show errors? Regular .less shows you a nice message that's very handy.
You can do this very easily with web.config. In your dotless configuration section, add the following: logger="dotless.Core.Loggers.AspResponseLogger". This will make dotless output the errors instead of blank css.
I've included the following as an example. ("..." represents existing stuff in your web.config). In my example below cache is set to false. This is useful for debugging purposes. It should probably be set to true under normal circumstances.
<configuration>
<configSections>
...
<section name="dotless" type="dotless.Core.configuration.DotlessConfigurationSectionHandler,dotless.Core" />
</configSections>
<dotless minifyCss="false" cache="false"
logger="dotless.Core.Loggers.AspResponseLogger" />
...
</configuration>
I just faced this today in my RequestReduce project. I was getting blank less -> css transforms because there were parse errors that appeared to be going into the ether. Thanks to
this related answer How can I output errors when using .less programmatically? I was able to work out a solution where I could write the errors to the response stream. You have to create a Logger derriving from dotless.Core.Loggers.ILogger:
public class LessLogger : ILogger
{
public void Log(LogLevel level, string message)
{
}
public void Info(string message)
{
}
public void Debug(string message)
{
}
public void Warn(string message)
{
}
public void Error(string message)
{
Response.Write(message);
}
public HttpResponseBase Response { get; set; }
}
You pass this into the Configuration sent to the EngineFactory:
var engine = new EngineFactory(new DotlessConfiguration
{
CacheEnabled = false,
Logger = typeof (LessLogger)
}
).GetEngine();
For unit testing purposes I wanted to pass in my HttpResponseBase that would write the error. This is where I felt things getting ugly with some nasty casting to get a reference to my logger:
((LessLogger)((LessEngine)((ParameterDecorator)engine).Underlying).Logger).Response = response;
I hope this helps you out.

OSGi Declarative Services - NullPointer Exception

I have a problem with my Declarative Services. I have 2 bundles, one is a server provider and another the user interface that consumes the service.
On server side, the implementation is:
public boolean checkUser(){
return true;
}
And the XML file inside OSGi-INF folder:
<component name="ZBService">
<implementation class="service.ZBService" />
<service>
<provide interface="service.IZBService" />
</service>
</component>
On client side, the implementation is:
public class GreetingServiceImpl extends RemoteServiceServlet implements GreetingService{
IZBService zb;
public void setZBService(IZBService eventAdmin) {
this.zb = eventAdmin;
}
public void unsetZBService(IZBService eventAdmin){
if(this.zb == eventAdmin){
this.zb = null;}
}
public boolean greetServer(String input, String input2) throws Exception {
return zb.checkUser();
}
}
And XML file:
<component name="ZBService">
<implementation class="main.java.com.gwt.app.server.GreetingServiceImpl" />
<service>
<provide interface="main.java.com.gwt.app.client.GreetingService"/>
</service>
<reference name="zb" interface="service.IZBService" bind="setZBService" unbind="unsetZBService" cardinality="0..n" policy="dynamic" />
</component>
Also, I have included the tag Service-Component on manifest file and I have deployed the equinox ds bundle that is ACTIVE.
The client is a GWT user interface, then I inject the service reference into server side of GWT. Well, when I deploy the application on Equinox it runs, but when I push the button, I launch an event to call ZBService. I have debugged the application and the error is zb attribute is null. It is to say, the dependence is nos injected. However the services are exposed on Equinox. If I write services on Equinox console, the services are deployed. Then, my conclusion is the error is due to the injection does not perform.
I would like to know if someone knows what is the reason??
Thanks a lot in advance!!
Nice day
EDIT:
I did your suggestions but it doesn't run. I change the component names and condinality/policy. The result is the same --> NullPointerException due to the injection isn't done.
Also I have debug the application to see if the methods bind and/or unbind are called, but they aren't.
The complete class is:
public class GreetingServiceImpl extends RemoteServiceServlet implements GreetingService{
static protected IZBService zb;
public GreetingServiceImpl(){
System.out.println("Constructor GreetingServiceImpl");
}
public IZBService getZb() {
return zb;
}
public void setZb(IZBService zb) {
GreetingServiceImpl.zb = zb;
}
public void unsetZb(IZBService zb) {
GreetingServiceImpl.zb = zb;
}
#Override
protected void service(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// Cache the current thread
Thread currentThread = Thread.currentThread();
// We are going to swap the class loader
ClassLoader oldContextClassLoader = currentThread.getContextClassLoader();
currentThread.setContextClassLoader(this.getClass().getClassLoader());
super.service(req, resp);
currentThread.setContextClassLoader(oldContextClassLoader);
}
public void activate(ComponentContext context) {
System.out.println("Creating new greeter for " + context.getProperties().get("name")
+ ": " + context.getComponentInstance().toString());
}
public void activate() {
System.out.println("Activando la referencia al servicio");
}
public void deactivate(ComponentContext context) {
System.out.println("Deactivating greeter for " + context.getProperties().get("name")
+ ": " + context.getComponentInstance().toString());
}
public boolean greetServer(String input, String input2) throws Exception {
return zb.checkUser();
}
}
And the XML client is:
<?xml version="1.0" encoding="UTF-8" ?>
<scr:component name="serviceZB" xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0">
<implementation class="main.java.com.gwt.app.server.GreetingServiceImpl" />
<!-- <service>
<provide interface="main.java.com.gwt.app.client.GreetingService"/>
</service> -->
<reference name="zb" interface="service.IZBService"
bind="setZb" unbind="unsetZb" cardinality="1..1"
policy="static" />
</scr:component>
Why isn't the service injected if the service is deployed???
Here is a list of things you can try:
First, remove the "static" of zb, that could be the problem.
If you are using Equinox, add the -Dequinox.ds.print=true flag to the VM arguments and see more information about parsing XMLs and so
Of course, add sysouts to setZB and unsetZB :)
Remember that IZBService implementation needs a constructor without arguments
If you are using Equinox use the "list -c" command to obtain information of each component (it's cool because says exactly why a component is not registered).
Set the "inmediate=true" in XMLs to force to inmediatly activation.
You have both components with the same name, , which is kind of awkward when discussing them.
The reference on the client side has: cardinality="0..n" policy="dynamic". Which means it can be activated with zero to n references. Yet your code does not handle this. It seems to expect exactly one reference. Perhaps you should use cardinality="1..1" policy="static".

Resources