public void ShouldRefuseToCreateLevelWithNonUniqueName() { var structureId = new StructureId(); const string levelName = "New Level"; var structure = new Structure(structureId); var existingLevels = new[] { structure.CreateLevel(levelName, Enumerable.Empty <ILevel>()) }; LevelCreatedEvent result = null; DomainEvents.Register((LevelCreatedEvent evt) => { result = evt; }); structure.Invoking(it => it.CreateLevel(levelName, existingLevels)).ShouldThrow <Exception>("level names must be unique"); result.Should().BeNull("domain event should not be raised if validation fails"); }
public void ShouldCreateNewLevel() { var levelId = new LevelId(); var structureId = new StructureId(); const string levelName = "New Level"; LevelCreatedEvent result = null; DomainEvents.Register((LevelCreatedEvent evt) => { result = evt; }); var level = new Level(levelId, structureId, levelName); level.Id.Should().Be(levelId); level.Name.Should().Be(levelName); result.Should().NotBeNull("domain method should raise event"); }
private void Apply(LevelCreatedEvent evt) { this.id = evt.EntityId; this.name = evt.LevelName; }