Mocking FileReference.data with mockolate? - actionscript-3

I'm trying to mock FileReference in a flex project I'm working on.
Stubbing out some properties, such as name and size works fine, but data just refuses to work.
Here is code that illustrates the problem:
[Test]
public function FileReferenceMockTest():void {
var frMock:FileReference = nice(FileReference);
var bytes:ByteArray = new ByteArray();
stub(frMock).getter("data").returns(bytes);
stub(frMock).getter("name").returns("filename");
assertThat(frMock.name, equalTo("filename")); // works
assertThat(frMock.data, sameInstance(bytes)); // Fails and says that frMock.data is null
}
If I set a breakpoint and check frMock in the debugger it looks like this:
frMock
[inherited]
data = null
creationDate = null
creator = null
modificationDate = null
name = "filename"
__proxy__ = InterceptorProxyListener
...
As you can see, data is treated differently by the mock.
I've been banging my head against this problem for several hours now and could really really use some help figuring this out.
Update:
The code works when run either as a Flex Library Project or a Flex Project (Air). It's when the code is run in a browser plugin that it fails.
A check in the debugger in the library project also shows that the data property is not nested inside [Inherited], but on the same level as the other properties.
Update:
I encountered the same problem with URLLoader, but this time the other way around. Mocking of the URLLoader only works when running the tests in a browser plugin.
Since I'm creating a class to handle local and remote file loading, using either FileReference or URLLoader, depending on input, I'm effectively prevented from unit testing this class completely. :(

Related

Blazor WebAssembly JsonException: A possible object cycle was detected which is not supported

I get this error because I have circular references defined in my object model. My question is, is there any way to resolve this using one of the following two options?
Using Newtonsoft.Json and options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
Using System.Text.Json and options.JsonSerializerOptions.ReferenceHandler = System.Text.Json.Serialization.ReferenceHandler.Preserve;
I'm not seeing a way to switch to Newtonsoft.Json in a Blazor WebAssembly application and I tried implementing option 2 in the ConfigureServices function of Startup.cs in my Server project but I still kept getting the error.
I'm just trying to find a solution that doesn't require me redefining my object model. The JsonIgnore attribute does not appear to be an option either because I assume, and it appears, that then any fields I define it on do not exist in the Json on the client which breaks my application.
Update: I found this site which looks to me like discusses exactly what I'm referring to here and how to implement the solution but I have not got it to work yet. If anyone is successfully using Blazor WebAssembly with circular references in your object model please let me know what you're doing.
https://github.com/dotnet/aspnetcore/issues/28286
Thank you for pointing out this error in Blazor. I found the answer in the issue you mentioned (this comment). You need to change json options also on the Client side. This works for me:
On server
services.AddControllersWithViews().AddJsonOptions(options =>
{
options.JsonSerializerOptions.ReferenceHandler = System.Text.Json.Serialization.ReferenceHandler.Preserve;
options.JsonSerializerOptions.PropertyNamingPolicy = null;
});
On client
var response = await Http.GetFromJsonAsync<T>("{Address}", new JsonSerializerOptions
{
ReferenceHandler = System.Text.Json.Serialization.ReferenceHandler.Preserve,
PropertyNamingPolicy = null
});
To the two options you mentioned there is a third option available if you use .NET 6 or above.
Using System.Text.Json and options.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.IgnoreCycles;
Beware that ignoring cycles have issues on its own (such as data corruption) but if you were depending on it when you were using Newtonsoft.Json then you will be fine as it is basically the same behavior.
If you prefer to go with ReferenceHandler.Preserve, please share more info on what error you are getting and I can try to help you out.
One way to go about this is specify how much depth an object is allowed to have. Please see the documentation here regarding how to do this with System.Text.Json. I think this may help.

Windsor WcfFacility: Setting ServiceBehavior properties

I'm hosting a service using Windsor's WCF Facility, but I can't get UseSynchronisationContext and ConcurrencyMode set that one would normally do using the ServiceBehaviorAttribute. I've seen two options that apparently should work (but tried both to no avail):
Registering ServiceBehaviorAttribute as a Component for IServiceBehavior
Modifying the Description collection of Behaviors in the OnCreated configuration callback in the WCF registration.
A third method that I've tried is using AddExtensions, but that results in an exception because there's already a ServiceBehaviorAttribute (by default?) in the list of Behaviors. This is also the case with method 2, but in that case I can remove it and add a new one, or modify the existing entry.
It's really frustrating that there doesn't seem any documentation on this except a line stating 'Remove the ServiceBehaviorAttribute' from your services, apparently because it can conflict with the WcfFacility.
Can someone point me on how to properly do this? Any hint is appreciated!
Unfortunately I didn't properly test. Modifying the properties of the ServiceBehaviorAttribute in the list of Behaviors of the Description property in the OnCreated action actually works as intended.
Sample registration:
container.Register(Component.For<IWCFWarehouseServiceAsyncCallback>()
.ImplementedBy<WarehouseService>()
.AsWcfService(new DefaultServiceModel()
.AddBaseAddresses(baseAddress)
.OnCreated(host =>
{
var sb = host.Description.Behaviors.Find<ServiceBehaviorAttribute>();
sb.UseSynchronizationContext = false;
sb.ConcurrencyMode = ConcurrencyMode.Reentrant;
})
.AddEndpoints(WcfEndpoint.BoundTo(binding).At("WarehouseService"))));

Box API .NET SDK: "pad block corrupted" exception when instantiating BoxJWTAuth

I'm using the Box SDK for .NET and just trying to get started authenticating using the Java Web Token workflow. I'm using code that's pretty much the same as the code sample that's included in the SDK's code examples.
var jwtPrivateKey = File.ReadAllText("private_key.pem");
var boxConfig = new BoxConfig(ClientId, ClientSecret, EnterpriseId, jwtPrivateKey, JwtPrivateKeyPassword, JwtPublicKeyId);
var boxJwt = new BoxJWTAuth(boxConfig);
But at that last line I'm getting an exception that says "pad block corrupted". The stack trace seems to indicate that it involves reading the private key, but I don't see what I could be doing wrong considering this is basically the same as the code sample (https://github.com/box/box-windows-sdk-v2/blob/master/Box.V2.Samples.JWTAuth/Program.cs).
Any ideas?
After re-generating the private key with Cygwin, things are working for me.
I believe what happened was I opened the private key in Notepad or something, then saved it in some format it didn't like (maybe changed encoding to UTF-8, or saved it with Windows-style line breaks).

com.adobe.indesign::IDSWFFile : Null-exception when loading swf-files

This is my class in essence
import mx.controls.Image;
public class ImageFrameView extends Image
{
//Model. Contains x, y, z and z. Url for the png/jpg or swf-file
private var m_imageFrame:ImageFrame;
public function ImageFrameView(imageFrame:ImageFrame)
{
super();
m_imageFrame = imageFrame;
initFrameView();
}
private function initFrameView():void
{
maintainAspectRatio = false;
width = m_imageFrame.width;
height = m_imageFrame.height;
x = m_imageFrame.x;
y = m_imageFrame.y;
rotation = m_imageFrame.rotation;
source = m_imageFrame.url; //Url points to a handler on the same server which serves images and/or swf-files.
}
}
And it's used like this in a class SpreadView which extends UIComponent
var imageFrameView:ImageFrameView = new ImageFrameView(contentFrame as ImageFrame);
addChild(imageFrameView);
Png and Jpeg works fine. And swf-files which I export from Indesign CS4 or Indesign CS5 works fine aswell. But recently,older swf-files which have been exported using the same method and parameters (in Indesign CS4) and which used to work, have suddenly refused to load and I get the following error, when UpdateDisplayList is called for the ImageFrameView:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com.adobe.indesign::IDSWFFile/readConfigurationData()
at com.adobe.indesign::IDSWFFile()
What happens is that the loaded swf-file throws an exception when it tries to read its own configuration.
All swf-files that I've created past and present still work. All swf-files that clients have created created past and present - doesn't work even tough they worked in the past. As far as I know the swf-files is created using the same method and parameters.
Can there be some sudden change in Adobe Flash that I'm not aware of? Me and my client is using Flash 10.1 or higher. Where does the error orgin from?
It seems like it is page transistions and/or page curl was the culprit. I don't know why but when I ticked off the options for page transistions the error vanished when the pdf is loaded. As such features is meaningless in my app I will make sure that such options is disallowed when the clients exports swf-files from indesign.

"Cannot call method 'indexOf' of undefined" when using Google Chrome (*googlechrome) as Selenium RC target

I'm trying to run a test in Google Chrome 9.0.597.98 beta using Selenium Grid. I'm firing the test off from C# using the default *googlechrome target that ships with Selenium Grid. When I try to open a site, I'm greeted with a "Cannot call method 'indexOf' of undefined" error.
I've found a post from someone who suggests that the solution is to drop security on Chrome a bit by passing in some parameters. This post suggest using something like this:
DefaultSelenium selenium = new DefaultSelenium(location, port, browser, targetPath);
BrowserConfigurationOptions bco = new BrowserConfigurationOptions();
selenium.start(bco.setCommandLineFlags("--disable-web-security"));
For some reason I don't see the BrowserConfigurationOptions anywhere. Is this something that ships with the Selenium dll? Is it something that's not available in the .NET version, but is in others? What options do I have to setting this "--disable-web-security" option and is there a better way of doing this?
Try this
[TestInitialize]
public void PreTest()
{
selenium = new DefaultSelenium("localhost",4444,"googlechrome","http://www.ryanhayes.net")
}
[TestMethod]
public void TestRyanHayesDotNet()
{
selenium.Open("/")
}
removing the / after the ryanhayes.net fixes the problem
Thanks a lot for this, I was looking this information and I got it here!
Now I'm able to run my test in googlechrome, earlier I was getting the same problem.
Following code is working for me:
BrowserConfigurationOptions webSec = new BrowserConfigurationOptions();
selenium.start(webSec.setCommandLineFlags("--disable-web-security"));
You're correct in assuming .Net doesn't have BrowserConfigurationOptions object, but fortunately you don't need it (it's only a thin wrapper). DefaultSelenium has two overrides for the Start() method. One of them takes no parameters and starts the browser normally, but the other takes a string specifying browser options. try selenium.Start("--disable-web-security")