Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smocks on mono/xamarin studio throws System.Runtime.Serialization exception #12

Closed
StummeJ opened this issue Oct 12, 2015 · 8 comments
Closed
Labels

Comments

@StummeJ
Copy link

StummeJ commented Oct 12, 2015

While trying to run a test using Smocks on Xamarin Studio on Mac OS X a System.Runtime.Serialization exception. Smocks version 0.5.18 nuget package.

[Test]
public void ReadingNameUpdatesTimestamp()
{
    var now = DateTime.Now.AddMonths (18);
    var person = new Person { FirstName = "John", LastName = "Doe", Age = 24 };

    Smock.Run (ctx => {
        ctx.Setup (() => DateTime.Now).Returns (now);

        var name = person.FirstName;

        Assert.AreEqual (now, person.AccessedOn);
    });
}

image

@StummeJ StummeJ changed the title Smocks on mono/xamerin studio throws System.Runtime.Serialization exception Smocks on mono/xamarin studio throws System.Runtime.Serialization exception Oct 12, 2015
@vanderkleij
Copy link
Owner

Thanks for reporting! Could you provide the (essentials of the) Person class, particularly how the value of AccessedOn is determined?

Furthermore, please check that you are using the latest version of Smocks (0.5.18). What happens if you move var now = ... and var person = ... inside the Smock.Run invocation?

@StummeJ
Copy link
Author

StummeJ commented Oct 12, 2015

Person class:

public class Person : IAudit
{
    #region IAudit implementation
    public DateTime CreatedOn { get; set; }
    public DateTime AccessedOn { get; set; }
    public DateTime ModifiedOn { get; set; }
    #endregion

    public String FirstName { get; set; }
    public String LastName { get; set; }
    public int Age { get; set; }
}

This test should fail since the DateTime has not been set yet, but this does work in visual studio on windows. I am using the latest Smocks and placing them inside the Smock.Run invocation results in the same outcome.

@vanderkleij
Copy link
Owner

Thanks for the details, I'll try to look into it if I can get access to a similar environment to reproduce the issue. What environment do you run the test on?

On VS2013 and VS2015 on windows I get a NullReferenceException unless I move the person declaration inside the Smock.Run block. Once I do that, everything seems to work as expected.

@StummeJ
Copy link
Author

StummeJ commented Oct 12, 2015

VS2015 it works great on Windows (like wise once it was inside the run block.) Xamarin Studio on Mac OS X it does not. I will try Xamarin Studio and Mono on Windows when I get home today.

@StummeJ
Copy link
Author

StummeJ commented Oct 12, 2015

Here is a link to the demo code. https://github.com/StummeJ/AOP-Demo/tree/bugs/Smocks12

@StummeJ
Copy link
Author

StummeJ commented Oct 13, 2015

Looks like compiling with mono on windows causes the same exception.

xbuild AOP-Demo.snl
nunit-console AopDemo.Tests/bin/Debug/AopDemo.Tests.dll
Test Case Failures:
1) AopDemo.Tests.AccessAudit.ReadingNameUpdatesTimestamp : System.Runtime.Serialization.SerializationException : Type Smocks.Utility.Unit is not marked as Serializable.
at (wrapper xdomain-invoke) Smocks.AppDomains.SerializableLambdaInvoker:Invoke (Smocks.AppDomains.SerializableLambda`1<Smocks.Utility.Unit>,Smocks.Serialization.ISerializer,object[])
at (wrapper remoting-invoke-with-check) Smocks.AppDomains.SerializableLambdaInvoker:Invoke (Smocks.AppDomains.SerializableLambda`1<Smocks.Utility.Unit>,Smocks.Serialization.ISerializer,object[])
at Smocks.AppDomains.AppDomainContext.InvokeLambda[Unit] (Smocks.AppDomains.SerializableLambda`1 serializableLambda, System.Object[] arguments) [0x00000] in <filename unknown>:0
at Smocks.AppDomains.AppDomainContext.Invoke (System.Action action) [0x00000] in <filename unknown>:0
at Smocks.Smock.RunAction (System.Action`1 action, Smocks.Configuration configuration) [0x00000] in <filename unknown>:0
at Smocks.Smock.Run (Smocks.Configuration configuration, System.Action`1 action) [0x00000] in <filename unknown>:0
at Smocks.Smock.Run (System.Action`1 action) [0x00000] in <filename unknown>:0
at AopDemo.Tests.AccessAudit.ReadingNameUpdatesTimestamp () [0x00000] in <filename unknown>:0
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0

@vanderkleij
Copy link
Owner

This is fixed in Smocks 0.5.22 on nuget. Be aware that I ran into some other mono issues (#14) while fixing this. Please consider mono support highly experimental for now.

Thanks for reporting again!

@StummeJ
Copy link
Author

StummeJ commented Oct 13, 2015

Thanks for fixing this so quick!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants