autofixture

Ploeh AutoFixture was unable to create an instance from System.Runtime.Serialization.ExtensionDataObject

强颜欢笑 提交于 2019-12-19 13:51:59
问题 We have an MVC project with references to WCF services. Those references added (ExtensionDataObject)ExtensionData property to every DTO and Response object and now AutoFixture fails to create anonymous instances of these types. Example: public partial class SearchResultsDto : object, System.Runtime.Serialization.IExtensibleDataObject, System.ComponentModel.INotifyPropertyChanged { [System.NonSerializedAttribute()] private System.Runtime.Serialization.ExtensionDataObject extensionDataField;

Specifying [readonly] property values [via ctor args] when instantiating [immutable] objects with AutoFixture

丶灬走出姿态 提交于 2019-12-18 04:52:28
问题 My test requires that I set the Response property on an immutable Rsvp object (see below) to a specific value. public class Rsvp { public string Response { get; private set; } public Rsvp(string response) { Response = response; } } I initially tried to do this using Build<Rsvp>().With(x => x.Rsvp, "Attending") , but realized this only supports writable properties. I replaced that with Build<Rsvp>().FromFactory(new Rsvp("Attending")) . This works, but is cumbersome for more complex objects

Automocking Web Api 2 controller

我的梦境 提交于 2019-12-17 21:56:35
问题 I am trying to auto mock ApiController class in my test cases. It worked perfectly when I was using WebApi1. I started to use WebApi2 on the new project and I am getting this exception thrown after I try to run my new tests: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Security.Cryptography.CryptographicException: pCertContext is an invalid handle. at System.Security.Cryptography.CAPI.CertSetCertificateContextProperty

Easy way to specify the value of a single constructor parameter?

南楼画角 提交于 2019-12-17 12:35:57
问题 Is there some easy way in Autofixture to new-up an object using it's constructor, but hard-code/specify the value to use for a single parameter in the constructor? I see that this can be done with properties, using something like: fixture.Build<MyObj>().With(x=x.Val,"hard coded value").Create() 回答1: From the discussion about this question in the comments: Often I want to new-up an object, but I'm only concerned about a single parameter. Maybe the parameter value drives a calculation or

Creating recursive tree with AutoFixture

纵然是瞬间 提交于 2019-12-17 11:44:33
问题 I have just started using AutoFixture and have this semi-complex data structure that I would like to create some specimen for. In the tests I am working with I don't care too much about content of the data structure. I just want reasonable default values. Part of this data structure is a recursive tree. More specific, one class holds a collection of some other class that contains a list of children of itself. Something akin to: public class A { private IEnumerable<B> bNodes; public A

Generating complex types with all properties equivalent

丶灬走出姿态 提交于 2019-12-13 17:41:14
问题 Does AutoFixture have a facility to create multiple instances of a given type with all the same data? My classes are not serializable and I need two models which are not reference equivalent, but instead have matching properties. public class Foo { // Many more properties and similar models needing the same semantics. public string Name { get; set; } } var a = fixture.Create<Foo>(); var b = fixture.Create<Foo>(); Assert.False(ReferenceEquals(a, b)); Assert.Equal(a.Name, b.Name); 回答1: I don't

Autofixture, create a list of dictionary<string, object> with alternating key

爱⌒轻易说出口 提交于 2019-12-13 15:16:03
问题 I need a list of dictionaries, each dictionary should contain a known number of string, string pairs, the keys are deterministic but values should be a random string and each dictionary in the list must have the same keys. Some background info: the string, string pairs represents values in a database table containing product entities, I use a dictionary to add a new row to my testdatabase. To create two rows, I need two dictionaries like so: new Dictionary<string, string>() { { "productno",

Autofixture strange error

坚强是说给别人听的谎言 提交于 2019-12-13 14:29:51
问题 I'm getting this error. Ploeh.AutoFixture.Kernel.IllegalRequestException : A request for an IntPtr was detected. This is an unsafe resource that will crash the process if used, so the request is denied. A common source of IntPtr requests are requests for delegates such as Func or Action. If this is the case, the expected workaround is to Customize (Register or Inject) the offending type by specifying a proper creational strategy. This is my test code.I'm using autofac and one of the

Customize AutoFixture property generation using constrained random values

血红的双手。 提交于 2019-12-13 06:31:24
问题 Context I would like to create a collection of my class, but some of its string property has constrained values. I would like to those values to be still random within the constrained set. I figured out the customization way, but my the random generation implementation seems to be not using any AutoFixture feature, and I do not want to reinvent the wheel: var random = new Random(); var fixture = new Fixture(); fixture.Customize<MyClass>(b => b .With(i => i.MyProperty, random.Next(2) == 0 ? "O

AutoFixture cannot create Claim (with .NET Framework 4.6)

拜拜、爱过 提交于 2019-12-12 11:32:43
问题 I've just installed VS2015, which at the same time installed .NET Framework 4.6, and suddenly AutoFixture 3.30.8 is unable to create a Claim object. I'm guessing having the new .NET Framework version 4.6 is causing some issue inside AutoFixture. I created a test project (targeting .NET Framework 4.5.1) containing the following code in VS2013: using System; using Microsoft.VisualStudio.TestTools.UnitTesting; using Ploeh.AutoFixture; namespace AutoFixtureTester { [TestClass] public class