public void Should_throw_exception_if_new_entity_has_invalid_version() { var factoryFunction = new DomainObjectFactoryFunction <DO>(passedId => { return(new DO(passedId, 0)); }); A.CallTo(() => serviceProvider.GetService(typeof(DomainObjectFactoryFunction <DO>))) .Returns(factoryFunction); var sut = new DefaultDomainObjectFactory(serviceProvider); Assert.Throws <InvalidOperationException>(() => sut.CreateNew <DO>(Guid.NewGuid())); }
public void Should_throw_if_new_entity_has_invalid_version() { var serviceProvider = new Mock <IServiceProvider>(); var factoryFunction = new DomainObjectFactoryFunction <DO>(passedId => { return(new DO(passedId, 0)); }); serviceProvider.Setup(x => x.GetService(typeof(DomainObjectFactoryFunction <DO>))).Returns(factoryFunction); var sut = new DefaultDomainObjectFactory(serviceProvider.Object); Assert.Throws <InvalidOperationException>(() => sut.CreateNew(typeof(DO), Guid.NewGuid())); }
public void Should_create_domain_object_with_autofac() { var factoryFunction = new DomainObjectFactoryFunction <DO>(passedId => { return(new DO(passedId, -1)); }); A.CallTo(() => serviceProvider.GetService(typeof(DomainObjectFactoryFunction <DO>))) .Returns(factoryFunction); var sut = new DefaultDomainObjectFactory(serviceProvider); var id = Guid.NewGuid(); var domainObject = sut.CreateNew <DO>(id); Assert.Equal(id, domainObject.Id); Assert.Equal(-1, domainObject.Version); }