evt-entity_projection-fixtures 0.0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: eadac8b371d8b9b14a76d346cc71ed287fdd93c3c688449535edbcfdfcd40d6d
4
+ data.tar.gz: 9aeca4bc99ea35a32e7d739a478d09db694ffed614d6ef6513bd20eadb9b202a
5
+ SHA512:
6
+ metadata.gz: b1c12582935814efc392a8c7f9828a6c9a6715e1342530c283ff1e0fd8aeb334f5f4a6b6a602cf08b6765969684e648df551f24ba2575d92e2dc1438b2e5b7f9
7
+ data.tar.gz: fe6e19130648c20d60d8ea3c6571053f7a310e4577a315169248bc3b02b0fdd039636f6f13e32b0d4cbbefc42ec954ef635f314831997177fc5b8db51cdf8db3
@@ -0,0 +1,5 @@
1
+ require 'schema/fixtures'
2
+
3
+ require 'entity_projection'
4
+
5
+ require 'entity_projection/fixtures/fixture'
@@ -0,0 +1,7 @@
1
+ require 'message_store/controls'
2
+
3
+ require 'entity_projection/fixtures/controls/id'
4
+ require 'entity_projection/fixtures/controls/time'
5
+ require 'entity_projection/fixtures/controls/event'
6
+ require 'entity_projection/fixtures/controls/entity'
7
+ require 'entity_projection/fixtures/controls/projection'
@@ -0,0 +1,34 @@
1
+ module EntityProjection
2
+ module Fixtures
3
+ module Controls
4
+ module Entity
5
+ def self.id
6
+ ID.example(increment: id_increment)
7
+ end
8
+
9
+ def self.id_increment
10
+ 11
11
+ end
12
+
13
+ def self.amount
14
+ 1
15
+ end
16
+
17
+ class Example
18
+ include Schema::DataStructure
19
+
20
+ attribute :id, String
21
+ attribute :amount, Numeric, default: 0
22
+ attribute :time, ::Time
23
+ attribute :updated_time, ::Time
24
+ end
25
+
26
+ module New
27
+ def self.example
28
+ Entity::Example.new
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,35 @@
1
+ module EntityProjection
2
+ module Fixtures
3
+ module Controls
4
+ module Event
5
+ def self.example
6
+ example = Example.new
7
+
8
+ example.example_id = example_id
9
+ example.amount = 11
10
+ example.time = Time::Effective.example
11
+ example.processed_time = Time::Processed.example
12
+
13
+ example
14
+ end
15
+
16
+ def self.example_id
17
+ Entity.id
18
+ end
19
+
20
+ def self.amount
21
+ 11
22
+ end
23
+
24
+ class Example
25
+ include Messaging::Message
26
+
27
+ attribute :example_id, String
28
+ attribute :amount, Numeric, default: 0
29
+ attribute :time, String
30
+ attribute :processed_time, String
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,7 @@
1
+ module EntityProjection
2
+ module Fixtures
3
+ module Controls
4
+ ID = MessageStore::Controls::ID
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,20 @@
1
+ module EntityProjection
2
+ module Fixtures
3
+ module Controls
4
+ module Projection
5
+ class Example
6
+ include ::EntityProjection
7
+
8
+ entity_name :example
9
+
10
+ apply Event::Example do |event|
11
+ example.id = event.example_id
12
+ example.amount = event.amount
13
+ example.time = ::Time.parse(event.time)
14
+ example.updated_time = ::Time.parse(event.processed_time)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,7 @@
1
+ module EntityProjection
2
+ module Fixtures
3
+ module Controls
4
+ Time = MessageStore::Controls::Time
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,91 @@
1
+ module EntityProjection
2
+ module Fixtures
3
+ class Projection
4
+ include TestBench::Fixture
5
+ include Initializer
6
+
7
+ def entity_class
8
+ entity.class
9
+ end
10
+
11
+ def event_class
12
+ event.class
13
+ end
14
+
15
+ initializer :projection, :control_entity, :entity, :event, :action
16
+
17
+ def self.build(projection, event, &action)
18
+ entity = projection.entity
19
+ control_entity = entity.clone
20
+
21
+ new(projection, control_entity, entity, event, action)
22
+ end
23
+
24
+ def call
25
+ projection_type = projection.class.name.split('::').last
26
+ entity_type = entity.class.name.split('::').last
27
+ event_type = event.message_type
28
+
29
+ detail "Projection Class: #{projection.class.name}"
30
+
31
+ context "Apply #{event.message_type} to #{entity.class.type}" do
32
+
33
+ detail "Event Class: #{event.class.name}"
34
+ detail "Entity Class: #{entity.class.name}"
35
+
36
+ projection.(event)
37
+
38
+ if not action.nil?
39
+ action.call(self)
40
+ end
41
+ end
42
+ end
43
+
44
+ def assert_attributes_copied(attribute_names=nil)
45
+ fixture(
46
+ Schema::Fixtures::Equality,
47
+ event,
48
+ entity,
49
+ attribute_names,
50
+ ignore_class: true,
51
+ print_title_context: false,
52
+ attributes_context_name: 'Copied'
53
+ )
54
+ end
55
+
56
+ def assert_transformed_and_copied(attribute_name, &transform)
57
+ if attribute_name.is_a?(Hash)
58
+ event_attribute_name = attribute_name.keys.first
59
+ entity_attribute_name = attribute_name.values.first
60
+ else
61
+ event_attribute_name = attribute_name
62
+ entity_attribute_name = attribute_name
63
+ end
64
+
65
+ event_attribute_value = event.public_send(event_attribute_name)
66
+ entity_attribute_value = entity.public_send(entity_attribute_name)
67
+
68
+ context "Transformed and Copied" do
69
+ detail "#{event_class.name.split('::').last} Value (#{event_attribute_value.class.name}): #{event_attribute_value.inspect}"
70
+ detail "#{entity_class.name.split('::').last} Value (#{entity_attribute_value.class.name}): #{entity_attribute_value.inspect}"
71
+
72
+ printed_attribute_name = self.class.printed_attribute_name(event_attribute_name, entity_attribute_name)
73
+
74
+ transformed_event_value = transform.call(event_attribute_value)
75
+
76
+ test printed_attribute_name do
77
+ assert(transformed_event_value == entity_attribute_value)
78
+ end
79
+ end
80
+ end
81
+
82
+ def self.printed_attribute_name(event_time_attribute, entity_time_attribute)
83
+ if event_time_attribute == entity_time_attribute
84
+ return event_time_attribute.to_s
85
+ else
86
+ return "#{event_time_attribute} => #{entity_time_attribute}"
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: evt-entity_projection-fixtures
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - The Eventide Project
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-08-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: evt-entity_projection
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: evt-schema-fixtures
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: test_bench
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: " "
56
+ email: opensource@eventide-project.org
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - lib/entity_projection/fixtures.rb
62
+ - lib/entity_projection/fixtures/controls.rb
63
+ - lib/entity_projection/fixtures/controls/entity.rb
64
+ - lib/entity_projection/fixtures/controls/event.rb
65
+ - lib/entity_projection/fixtures/controls/id.rb
66
+ - lib/entity_projection/fixtures/controls/projection.rb
67
+ - lib/entity_projection/fixtures/controls/time.rb
68
+ - lib/entity_projection/fixtures/fixture.rb
69
+ homepage: https://github.com/eventide-project/entity-projection-fixtures
70
+ licenses:
71
+ - MIT
72
+ metadata: {}
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: 2.3.3
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ requirements: []
88
+ rubygems_version: 3.1.2
89
+ signing_key:
90
+ specification_version: 4
91
+ summary: TestBench fixtures for EntityProjection implementations
92
+ test_files: []