Questions tagged [nbuilder]

Through a fluent, extensible interface, NBuilder allows you to rapidly create test data.

Through a fluent, extensible interface, NBuilder allows you to rapidly create test data, automatically assigning values to properties and public fields that are one of the built in .NET data types (e.g. ints and strings). NBuilder allows you to override for properties you are interested in using lambda expressions.

Resources

Installation

NBuilder can most easily be installed through its NuGet package.

Install-Package NBuilder
30 questions
14
votes
2 answers

Is it possible to use NBuilder to Build a collection of random strings?

pretty simple question: can I use NBuilder to create a collection of x number of random strings? I was trying... // NOTE: Tags need to be lowercase. return Builder .CreateListOfSize(10) .WhereAll() .Has(x => x =…
Pure.Krome
  • 84,693
  • 113
  • 396
  • 647
11
votes
5 answers

nBuilder alternative for Java

Is there any tool like nBuilder for java? I want to build objects for unit testing and I dont want to have one builder class for each entity in my domain. I am currently using mockito but it doesnt replace the functionality of nBuilder.
Pomber
  • 1,165
  • 2
  • 9
  • 13
6
votes
2 answers

How to Moq protected property in C#

public class Business { protected List BusinessRules { get; set; } } I tried: businessMockObject.Protected().SetupSet>("BusinessRules", ItExpr.IsAny>()).Verifiable(); var…
5
votes
3 answers

nBuilder only populating value types

I am using nBuilder to populate an object graph, but it is only populating the value types. I want it to populate the reference types (related objects). http://nbuilder.org/
Casey Burns
  • 1,223
  • 12
  • 15
5
votes
1 answer

Is there a way of creating an instance of a type with test data?

I have a type and want to create an instance of it with test data. I know that frameworks like NBuilder or AutoFixture can create instances of types that are known on design time (). Are those frameworks able to create an instance based on a…
Rookian
  • 19,841
  • 28
  • 110
  • 180
4
votes
1 answer

How to create child collections automatically with NBuilder?

Given the following classes: class Department { public String Name { get; set; } public IList Employees { get; set; } } class Employee { public String Name { get; set; } public String Address { get; set; } } With NBuilder…
Manuel
  • 10,869
  • 14
  • 55
  • 86
3
votes
3 answers

NBuilder parameterless constructor error

We are using NBuilder for generating test data for our tests. We have a few models with private setters. So setting thos properties is only possible throughout the constructor. The problem is that we get the following error from…
DAG
  • 2,460
  • 5
  • 33
  • 61
3
votes
1 answer

How to automatically create test data with builder that will take verifications into account

I am using NBuilder to create test data and my classes have a large number of properties so manual creation is out of question. Before I used NBuilder I copy pasted some SQL selects to csv files and recreated them in tests using automatic mapping.…
majkinetor
  • 8,730
  • 9
  • 54
  • 72
3
votes
2 answers

Class and extension method container class in same namespace. What is the benefit?

I was trying NBuilder in my unit test. An excellent library. However, I could not explain the following structure of classes and interfaces. In FizzWare.NBuilder namespace: ISingleObjectBuilder SingleObjectBuilderExtensions In…
Mohayemin
  • 3,841
  • 4
  • 25
  • 54
2
votes
2 answers

With NBuilder for .NET, what's the difference between .Has(..) and .Have(..)?

NBuilder has two of the following fluent methods .Has(..) .Have(..) eg. return Builder.CreateListOfSize(100) .WhereTheFirst(1) .Has(x => x.FirstName = "Jon Skeet") .Build(); return Builder.CreateListOfSize(100) …
Pure.Krome
  • 84,693
  • 113
  • 396
  • 647
2
votes
0 answers

Pick unique child list items using NBuilder

I'm using NBuilder for mocking up test data for a object graph of owner and cars. So the relationship between a single owner and cars is unique. Owner 1 - Car 2 - Car 3 Owner 2 - Car 4 - Car 5 So I have used the following code: var owners =…
Rubans
  • 4,188
  • 6
  • 40
  • 58
2
votes
1 answer

How to tell NBuilder to intercept getters when generating object?

I've got this NBuilder code: var fakeReviews = Builder .CreateListOfSize(100) .Build() .ToList() .AsReadOnly(); Pretty dead simple. But it's erroring here on this property on Review: public bool WasWrittenByAdmin { get …
RPM1984
  • 72,246
  • 58
  • 225
  • 350
2
votes
2 answers

How to mock a private readonly IList property using moq

I'm trying to mock this list: private readonly IList myList = new List(); using this (as seen here): IList mockList = Builder.CreateListOfSize(5).Build(); mockObj.SetupGet>(o =>…
epzee
  • 568
  • 8
  • 22
1
vote
1 answer

Is there a test data builder that works with classes without default constructor?

Due to introducing C# 8's non-nullable reference types to my codebase, I'm changing my domain classes to have constructors that accept parameters to initialize values of their non-nullable properties. In unit tests I don't want to bother with…
Павле
  • 800
  • 5
  • 20
1
vote
1 answer

NBuilder start integer at 0

I have this model: public class OrderProperty { [Required] public int Id { get; set; } [Required] public int Order { get; set; } } The Order property starts at 0 instead of 1. When I use NBuilder to build me a list of OrderProperties, it…
r3plica
  • 13,017
  • 23
  • 128
  • 290
1
2