ByteDecoder.ModelFactory
0.1.0
See the version list below for details.
dotnet add package ByteDecoder.ModelFactory --version 0.1.0
NuGet\Install-Package ByteDecoder.ModelFactory -Version 0.1.0
<PackageReference Include="ByteDecoder.ModelFactory" Version="0.1.0" />
paket add ByteDecoder.ModelFactory --version 0.1.0
#r "nuget: ByteDecoder.ModelFactory, 0.1.0"
// Install ByteDecoder.ModelFactory as a Cake Addin #addin nuget:?package=ByteDecoder.ModelFactory&version=0.1.0 // Install ByteDecoder.ModelFactory as a Cake Tool #tool nuget:?package=ByteDecoder.ModelFactory&version=0.1.0
ModelFactory
Easy way to create Models for use in Test Suites
Targeted to .Net Core 3.1
Installation
Install the ModelFactory NuGet Package.
Package Manager Console
Install-Package ByteDecoder.ModelFactory
.NET Core CLI
dotnet add package ByteDecoder.ModelFactory
Examples and usage
An easy way to define data for models is to create in your test project, internal static classes that define custom data for your models, and then create instances of these model data templates for testing, minimizing code duplication, and maximizing extensibility and maintainability via the ModelFactory. It also takes the advantage of method group provided by C#.
You can create a single instance or a collection of a given type T
// Model Example
public class Command
{
public int Id { get; set; }
public string HowTo { get; set; }
public string Platform { get; set; }
public string CommandLine { get; set; }
}
// Data Template example method
internal static class CommandFactory
{
internal static void BasicBuildOne(Command cmd)
{
cmd.HowTo = "Do Something";
cmd.Platform = "Some Platform";
cmd.CommandLine = "Some Command";
}
}
// Now, creating model instances with ModelFactory
[Fact]
public void Create_ShouldCreateModel_WhenMethodIsProvided()
{
// Arrange
// Act
var model = ModelFactory<Command>.Create(CommandFactory.BasicBuildOne);
// Assert
Assert.NotNull(model);
Assert.Equal("Do Something", model.HowTo);
}
[Fact]
public void Create_ShouldCreateCollection_WhenMethodIsProvided()
{
// Arrange
// Act
var models = ModelFactory<Command>.Create(2, CommandFactory.BasicBuildOne);
// Assert
Assert.NotNull(models);
Assert.Equal(2, models.Count());
}
// Also, you can define inline the model data as well
var model = ModelFactory<Command>.Create(m =>
{
m.Id = 666;
m.HowTo = "UPDATED";
m.Platform = "UPDATED";
m.CommandLine = "UPDATED";
});
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/ByteDecoder/ModelFactory.
Copyright (c) 2020 Rodrigo Reyes released under the MIT license
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp3.1 is compatible. |
-
.NETCoreApp 3.1
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.