{"_id":"561c8271c5c3b22b00e449ba","project":"56000f0d8c0c9d0d00dcad21","category":{"_id":"561c81d0e822e12b00e1fe00","__v":5,"pages":["561c8359f067153500bf6e2c","561c8433b1e87c0d00eee837","561c8502a46cd40d00b11d9d","561c85ace822e12b00e1fe0a","5625969d23053b2300f59733"],"project":"56000f0d8c0c9d0d00dcad21","version":"56000f0e8c0c9d0d00dcad24","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-10-13T04:00:16.895Z","from_sync":false,"order":4,"slug":"spaceevent-sourcing","title":"space:event-sourcing"},"githubsync":"","__v":7,"user":"5600910981a9670d006d144f","version":{"_id":"56000f0e8c0c9d0d00dcad24","project":"56000f0d8c0c9d0d00dcad21","__v":13,"createdAt":"2015-09-21T14:07:10.176Z","releaseDate":"2015-09-21T14:07:10.176Z","categories":["56000f0e8c0c9d0d00dcad25","56008f2497f69f1700f21a36","560091601503430d007cc936","560e0d8054af2b0d005bbe92","560e3ce7ad6b200d00ff471c","560e3cf2c4e4ae0d00b42ed1","561c81d0e822e12b00e1fe00","561c81e9e822e12b00e1fe01","561c823d20b4a92b007d5147","56257f8951bf1c0d001f660a","562d5f165bd25e0d0054dbd4","562d68d5d38b650d0044472a","56421aebb0dc090d00f88438"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-10-13T04:02:57.237Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":2,"body":"[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"describe 'MyNamespace.myBoundedContext.MyAggregate', ->\\n  beforeEach ->\\n    :::at:::app = new MyApp()\\n    @app.start()\\n    @aggregateId = new Guid()\\n    @data = {\\n      someValue: 'TestValue'\\n    }\\n    @anotherValue = 'TestValue2'\\n  it 'generates the MyAggregate created event', ->\\n    @app.given(\\n        new MyNamespace.myBoundedContext.CreateMyAggregate _.extend {}, @data, {\\n          targetId: @aggregateId\\n          timestamp: new Date()\\n        }\\n      )\\n      .expect([\\n        new MyNamespace.MyAggregateCreated _.extend {}, @data, {\\n          sourceId: @aggregateId\\n        }\\n      ])\\n      \\n    it 'generates the MyAggregate created event', ->\\n    @app.given(\\n        new MyNamespace.MyAggregateCreated _.extend {}, @data, {\\n          sourceId: @aggregateId\\n          timestamp: new Date()\\n        }\\n      )\\n      .when([\\n        new MyNamespace.myBoundedContext.DoSomething({\\n          targetId: @aggregateId\\n          timestamp: new Date()\\n          someValue: @anotherValue\\n        }) \\n      ])\\n      .expect([\\n        new MyNamespace.MyAggregateChanged _.extend {}, @data, {\\n          sourceId: @aggregateId\\n        }\\n      ])\",\n      \"language\": \"coffeescript\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"What about unit testing in the domain?\",\n  \"body\": \"One advantage of an event-sourced system based on the [CQRS pattern](https://meteor-space.readme.io/v1.0/docs/cqrs) is we can effectively omit fine-grained and arguably brittle unit tests since we really only need to check the events generated as a result of a command being sent in on the Command Bus. The messaging and event-sourcing libraries provide test coverage for reliable delivery, so you can focus on writing tests that ensure the aggregates are delivering the business requirements and are protecting themselves from invariants.\"\n}\n[/block]","excerpt":"Specify the expected events to be published as a result of the given command. Simple!","slug":"domain-logic","type":"basic","title":"Testing domain logic"}

Testing domain logic

Specify the expected events to be published as a result of the given command. Simple!

[block:code] { "codes": [ { "code": "describe 'MyNamespace.myBoundedContext.MyAggregate', ->\n beforeEach ->\n @app = new MyApp()\n @app.start()\n @aggregateId = new Guid()\n @data = {\n someValue: 'TestValue'\n }\n @anotherValue = 'TestValue2'\n it 'generates the MyAggregate created event', ->\n @app.given(\n new MyNamespace.myBoundedContext.CreateMyAggregate _.extend {}, @data, {\n targetId: @aggregateId\n timestamp: new Date()\n }\n )\n .expect([\n new MyNamespace.MyAggregateCreated _.extend {}, @data, {\n sourceId: @aggregateId\n }\n ])\n \n it 'generates the MyAggregate created event', ->\n @app.given(\n new MyNamespace.MyAggregateCreated _.extend {}, @data, {\n sourceId: @aggregateId\n timestamp: new Date()\n }\n )\n .when([\n new MyNamespace.myBoundedContext.DoSomething({\n targetId: @aggregateId\n timestamp: new Date()\n someValue: @anotherValue\n }) \n ])\n .expect([\n new MyNamespace.MyAggregateChanged _.extend {}, @data, {\n sourceId: @aggregateId\n }\n ])", "language": "coffeescript" } ] } [/block] [block:callout] { "type": "info", "title": "What about unit testing in the domain?", "body": "One advantage of an event-sourced system based on the [CQRS pattern](https://meteor-space.readme.io/v1.0/docs/cqrs) is we can effectively omit fine-grained and arguably brittle unit tests since we really only need to check the events generated as a result of a command being sent in on the Command Bus. The messaging and event-sourcing libraries provide test coverage for reliable delivery, so you can focus on writing tests that ensure the aggregates are delivering the business requirements and are protecting themselves from invariants." } [/block]