I'm wirting some integration test for our application. I'm using mspec and got a invalid operation exception on subject.
using FluentAssertions;
using Machine.Fakes;
using Machine.Specifications;
using Mehdime.Entity;
using Castle.Core.Internal;
namespace Bachem.Dispo.BusinessLogic.Tests
{
[Subject(typeof(MitarbeiterManager))]
public class MitarbeiterManagerSpecification : WithSubject<MitarbeiterManager>
{
protected static DispoDataContext DataContext;
protected static MitarbeiterManager mitarbeiterManager;
protected static int mitarbeiterId;
Establish context = () =>
{
With(new DropAndCreateDatabaseBehaviorConfiguration());
Configure(x => x.For<IDbContextScopeFactory>().Use<DbContextScopeFactory>());
Configure(x => x.For<IDbContextFactory>().Use<DbContextFactory>());
Configure(x => x.For<IMitarbeiterRepository>().Use<MitarbeiterRepository>());
MappingConfig.Initialize();
mitarbeiterId = 1339;
var mitarbeiter = new Mitarbeiter
{
Id = mitarbeiterId,
Vorname = "Hans",
Nachname = "Peter",
Personalnummer = 1337,
Anrede = 1,
Postleitzahl = "33100",
Strasse = "Hauptstrasse 32",
Ort = "Paderborn",
Telefonnummer = null,
Email = null,
Mobilnummer = null
};
using (var context = DataContextFactory.CreateDataContextStatic())
{
context.Mitarbeiter.Add(mitarbeiter);
context.SaveChanges();
}
};
}
public class Can_get_Mitarbeiter : MitarbeiterManagerSpecification
{
protected static MitarbeiterDto[] result;
Because of = () =>
{
result = Subject.GetMitarbeiter();
};
It it_should_be_hans_peter = () =>
{
result.Find(r => r.Id == mitarbeiterId).Id.Should().Be(mitarbeiterId);
};
}
}
The exception only tells me that a invaild operation is used on subject. Subject comes from machine fakes.
The test should add a new "Mitarbeiter" to the database and load this "Mitarbeiter" and check for equality.
The method used to load "Mitarbeiter" returns an array of type "MitarbeiterDto"
Aucun commentaire:
Enregistrer un commentaire