Ejemplo n.º 1
0
        public static Asset Create(AssetCommand command, Brand brand)
        {
            var asset = new Asset(command.Name, brand);

            asset.AddDescription(command.Description);
            return(asset);
        }
 public AssetsQueryBuilderTests()
 {
     this.id           = Guid.NewGuid();
     this.assetCommand = new AssetCommand {
         Name = MockString(), Description = MockString(), BrandId = Guid.NewGuid().ToString()
     };
     this.brand = new Brand(MockString());
     this.asset = new Asset(MockString(), this.brand);
 }
Ejemplo n.º 3
0
        public void Should_return_a_notification_when_creating_a_new_asset_and_asset_name_is_null()
        {
            var assetCommand = new AssetCommand
            {
                BrandId = Guid.NewGuid().ToString()
            };

            Assert.IsFalse(assetCommand.IsValid());
            Assert.IsTrue(assetCommand.Notifications.ToList().Any(n => n.Property.Contains(nameof(assetCommand.Name))));
        }
Ejemplo n.º 4
0
        public AssetQueryBuilder UpdateAsset(Guid id, AssetCommand assetCommand)
        {
            this.query = @"UPDATE Assets SET Name = @Name, Description = @Description, BrandID = @BrandID 
						WHERE AssetID = @AssetID"                        ;
            this.parameters.Add("AssetID", id);
            this.parameters.Add("Name", assetCommand.Name);
            this.parameters.Add("Description", assetCommand.Description);
            this.parameters.Add("BrandID", assetCommand.BrandId);
            return(this);
        }
Ejemplo n.º 5
0
        public void Should_return_a_notification_when_creating_a_new_asset_with_a_invalid_brand_identifier()
        {
            var assetCommand = new AssetCommand
            {
                Name    = this.MockString(Asset.MINIMUM_NAME_SIZE),
                BrandId = Guid.NewGuid().ToString().Substring(0, 9)
            };

            Assert.IsFalse(assetCommand.IsValid());
            Assert.IsTrue(assetCommand.Notifications.ToList().Any(n => n.Property.Contains(nameof(assetCommand.BrandId))));
        }
Ejemplo n.º 6
0
        public void Should_return_a_notification_when_creating_a_new_asset_with_a_asset_name_greater_than_the_maximum_allowed_size()
        {
            var assetCommand = new AssetCommand
            {
                Name    = this.MockString(Asset.MAXIMUM_NAME_SIZE + 1),
                BrandId = Guid.NewGuid().ToString()
            };

            Assert.IsFalse(assetCommand.IsValid());
            Assert.IsTrue(assetCommand.Notifications.ToList().Any(n => n.Property.Contains(nameof(assetCommand.Name))));
        }
Ejemplo n.º 7
0
        public void Should_return_true_when_creating_a_new_asset_with_valid_requides_properties()
        {
            var assetCommand = new AssetCommand
            {
                Name    = this.MockString(Asset.MINIMUM_NAME_SIZE),
                BrandId = Guid.NewGuid().ToString()
            };

            Assert.IsTrue(assetCommand.IsValid());
            Assert.IsFalse(assetCommand.Notifications.ToList().Any());
        }
        public void Should_contain_a_notification_when_creating_a_new_asset_and_asset_name_is_null()
        {
            var assetCommand = new AssetCommand
            {
                BrandId = Guid.NewGuid().ToString()
            };

            assetCommand.IsValid();

            assetCommand.Notifications.ToList().Should().Contain(n => n.Property.Contains(nameof(assetCommand.Name)));
        }
        public void Should_contain_a_notification_when_creating_a_new_asset_with_a_asset_name_lower_than_the_minimum_allowed_size()
        {
            var assetCommand = new AssetCommand
            {
                Name    = this.MockString(Asset.MINIMUM_NAME_SIZE - 1),
                BrandId = Guid.NewGuid().ToString()
            };

            assetCommand.IsValid();

            assetCommand.Notifications.ToList().Should().Contain(n => n.Property.Contains(nameof(assetCommand.Name)));
        }
        public void Should_not_contain_notifications_when_creating_a_new_asset_with_valid_requides_properties()
        {
            var assetCommand = new AssetCommand
            {
                Name    = this.MockString(Asset.MINIMUM_NAME_SIZE),
                BrandId = Guid.NewGuid().ToString()
            };

            assetCommand.IsValid();

            assetCommand.Notifications.ToList().Should().BeEmpty();
        }
Ejemplo n.º 11
0
        private async Task <object?> PublishIdempotentAsync(AssetCommand command)
        {
            var result = await PublishAsync(command);

            var previousSnapshot = sut.Snapshot;
            var previousVersion  = sut.Snapshot.Version;

            await PublishAsync(command);

            Assert.Same(previousSnapshot, sut.Snapshot);
            Assert.Equal(previousVersion, sut.Snapshot.Version);

            return(result);
        }
Ejemplo n.º 12
0
        public IActionResult Put(string id, [FromBody] AssetCommand assetCommand)
        {
            var result = this.assetCommandHandler.Update(id, assetCommand);

            return(this.StatusCode((int)result.StatusCode, result));
        }
Ejemplo n.º 13
0
        public IActionResult Post([FromBody] AssetCommand assetCommand)
        {
            var result = this.assetCommandHandler.Create(assetCommand);

            return(this.StatusCode((int)result.StatusCode, result));
        }
Ejemplo n.º 14
0
        private async Task <object?> PublishAsync(AssetCommand command)
        {
            var result = await sut.ExecuteAsync(CreateAssetCommand(command));

            return(result.Value);
        }