Ejemplo n.º 1
0
        public async Task AnnotateSlug_should_create_events_and_update_slug()
        {
            var command = new AnnotateAsset {
                Slug = "my-new-image.png"
            };

            await ExecuteCreateAsync();

            var result = await PublishIdempotentAsync(command);

            result.ShouldBeEquivalent(sut.Snapshot);

            Assert.Equal(command.Slug, sut.Snapshot.Slug);

            LastEvents
            .ShouldHaveSameEvents(
                CreateAssetEvent(new AssetAnnotated {
                Slug = command.Slug
            })
                );
        }
Ejemplo n.º 2
0
        public async Task AnnotateProtected_should_create_events_and_update_protected_flag()
        {
            var command = new AnnotateAsset {
                IsProtected = true
            };

            await ExecuteCreateAsync();

            var result = await PublishIdempotentAsync(command);

            result.ShouldBeEquivalent(sut.Snapshot);

            Assert.Equal(command.IsProtected, sut.Snapshot.IsProtected);

            LastEvents
            .ShouldHaveSameEvents(
                CreateAssetEvent(new AssetAnnotated {
                IsProtected = command.IsProtected
            })
                );
        }
Ejemplo n.º 3
0
        public async Task AnnotateSlug_should_create_events()
        {
            var command = new AnnotateAsset {
                Slug = "my-new-image.png"
            };

            await ExecuteCreateAsync();

            var result = await sut.ExecuteAsync(CreateAssetCommand(command));

            result.ShouldBeEquivalent(new EntitySavedResult(1));

            Assert.Equal("my-new-image.png", sut.Snapshot.Slug);

            LastEvents
            .ShouldHaveSameEvents(
                CreateAssetEvent(new AssetAnnotated {
                Slug = "my-new-image.png"
            })
                );
        }
Ejemplo n.º 4
0
        public async Task AnnotateName_should_create_events_and_update_file_name()
        {
            var command = new AnnotateAsset {
                FileName = "My New Image.png"
            };

            await ExecuteCreateAsync();

            var result = await PublishIdempotentAsync(command);

            result.ShouldBeEquivalent(sut.Snapshot);

            Assert.Equal(command.FileName, sut.Snapshot.FileName);

            LastEvents
            .ShouldHaveSameEvents(
                CreateAssetEvent(new AssetAnnotated {
                FileName = command.FileName
            })
                );
        }
Ejemplo n.º 5
0
        public async Task AnnotateMetadata_should_create_events_and_update_metadata()
        {
            var command = new AnnotateAsset {
                Metadata = new AssetMetadata().SetPixelWidth(800)
            };

            await ExecuteCreateAsync();

            var result = await PublishIdempotentAsync(command);

            result.ShouldBeEquivalent(sut.Snapshot);

            Assert.Equal(command.Metadata, sut.Snapshot.Metadata);

            LastEvents
            .ShouldHaveSameEvents(
                CreateAssetEvent(new AssetAnnotated {
                Metadata = command.Metadata
            })
                );
        }
Ejemplo n.º 6
0
        public static void CanAnnotate(AnnotateAsset command)
        {
            Guard.NotNull(command);

            Validate.It(() => "Cannot annotate asset.", e =>
            {
                if (string.IsNullOrWhiteSpace(command.FileName) &&
                    string.IsNullOrWhiteSpace(command.Slug) &&
                    command.IsProtected == null &&
                    command.Metadata == null &&
                    command.Tags == null)
                {
                    e("At least one property must be defined.",
                      nameof(command.FileName),
                      nameof(command.IsProtected),
                      nameof(command.Metadata),
                      nameof(command.Slug),
                      nameof(command.Tags));
                }
            });
        }
Ejemplo n.º 7
0
        public async Task AnnotateName_should_create_events()
        {
            var command = new AnnotateAsset {
                FileName = "My New Image.png"
            };

            await ExecuteCreateAsync();

            var result = await sut.ExecuteAsync(CreateAssetCommand(command));

            result.ShouldBeEquivalent(sut.Snapshot);

            Assert.Equal("My New Image.png", sut.Snapshot.FileName);

            LastEvents
            .ShouldHaveSameEvents(
                CreateAssetEvent(new AssetAnnotated {
                FileName = "My New Image.png"
            })
                );
        }
Ejemplo n.º 8
0
        public async Task AnnotateTags_should_create_events_and_update_state()
        {
            var command = new AnnotateAsset {
                Tags = new HashSet <string> {
                    "tag1"
                }
            };

            await ExecuteCreateAsync();

            var result = await PublishIdempotentAsync(command);

            result.ShouldBeEquivalent2(sut.Snapshot);

            LastEvents
            .ShouldHaveSameEvents(
                CreateAssetEvent(new AssetAnnotated {
                Tags = new HashSet <string> {
                    "tag1"
                }
            })
                );
        }
Ejemplo n.º 9
0
        public static void CanAnnotate(AnnotateAsset command, string oldFileName, string oldSlug)
        {
            Guard.NotNull(command, nameof(command));

            Validate.It(() => "Cannot rename asset.", e =>
            {
                if (string.IsNullOrWhiteSpace(command.FileName) &&
                    string.IsNullOrWhiteSpace(command.Slug) &&
                    command.Tags == null)
                {
                    e("Either file name, slug or tags must be defined.", nameof(command.FileName), nameof(command.Slug), nameof(command.Tags));
                }

                if (!string.IsNullOrWhiteSpace(command.FileName) && string.Equals(command.FileName, oldFileName))
                {
                    e(Not.New("Asset", "name"), nameof(command.FileName));
                }

                if (!string.IsNullOrWhiteSpace(command.Slug) && string.Equals(command.Slug, oldSlug))
                {
                    e(Not.New("Asset", "slug"), nameof(command.Slug));
                }
            });
        }
Ejemplo n.º 10
0
 private void Annotate(AnnotateAsset command)
 {
     Raise(command, new AssetAnnotated());
 }
Ejemplo n.º 11
0
 public static void CanAnnotate(AnnotateAsset command)
 {
     Guard.NotNull(command, nameof(command));
 }
Ejemplo n.º 12
0
 public void Annotate(AnnotateAsset command)
 {
     RaiseEvent(SimpleMapper.Map(command, new AssetAnnotated()));
 }