예제 #1
0
        public void ShouldHaveInstructionNotFoundCustomFailureWhenIdIsGuidEmpty()
        {
            // Arrange
            var id                    = Guid.Empty;
            var name                  = "name";
            var description           = "description";
            var icon                  = "icon Url";
            IEnumerable <string> tags = new List <string>()
            {
                "tag1", "tag2"
            };
            var content = "content";
            var image   = "image";
            var video   = "video";
            var version = 0;

            var command = new UpdateInstructionCommand(id, name, description, icon, tags, content, image, video, version);

            // Act
            var validationResult = _validator.Validate(command);
            var exists           =
                validationResult.Errors.Any(
                    a => a.PropertyName.Equals("Id") && a.ErrorMessage.Contains(CustomFailures.InstructionNotFound));

            // Assert
            exists.Should().BeTrue();
        }
예제 #2
0
        public void ShouldHaveInstructionNameCannotStartOrEndWithWhiteSpaceValidationErrorWhenNameStartsOrEndsWithWhiteSpace(string symbols)
        {
            // Arrange
            var id                    = Guid.NewGuid();
            var name                  = symbols;
            var description           = "description";
            var icon                  = "icon Url";
            IEnumerable <string> tags = new List <string>()
            {
                "tag1", "tag2"
            };
            var content = "content";
            var image   = "image";
            var video   = "video";
            var version = 0;

            var command = new UpdateInstructionCommand(id, name, description, icon, tags, content, image, video, version);

            // Act
            var validationResult = _validator.Validate(command);
            var exists           = validationResult.Errors.Any(a => a.PropertyName.Equals("Name") && a.ErrorMessage.Contains(ValidationFailures.InstructionNameCannotStartOrEndWithWhiteSpace));

            // Assert
            exists.Should().BeTrue();
        }
예제 #3
0
        public void ShouldContainNoErrors()
        {
            // Arrange
            var id                    = Guid.NewGuid();
            var name                  = "name";
            var description           = "description";
            var icon                  = "icon Url";
            IEnumerable <string> tags = new List <string>()
            {
                "tag1", "tag2"
            };
            var content = "content";
            var image   = "image";
            var video   = "video";
            var version = 0;

            var command = new UpdateInstructionCommand(id, name, description, icon, tags, content, image, video, version);

            // Act
            var validationResult = _validator.Validate(command);
            var exists           = validationResult.Errors.Count > 0;

            // Assert
            exists.Should().BeFalse();
        }
예제 #4
0
        public void ShouldHaveInstructionTagMandatoryValidationFailureWhenTagsContainsWhiteSpaceValue()
        {
            // Arrange
            var id                    = Guid.NewGuid();
            var name                  = "name";
            var description           = "description";
            var icon                  = "icon Url";
            IEnumerable <string> tags = new List <string>()
            {
                "tag1", "   ", "tag2"
            };
            var content = "content";
            var image   = "image";
            var video   = "video";
            var version = 0;

            var command = new UpdateInstructionCommand(id, name, description, icon, tags, content, image, video, version);

            // Act
            var validationResult = _validator.Validate(command);
            var exists           =
                validationResult.Errors.Any(
                    a => a.PropertyName.Contains("Tags[1]") && a.ErrorMessage.Contains(ValidationFailures.InstructionTagMandatory));

            // Assert
            exists.Should().BeTrue();
        }
예제 #5
0
        public async override Task <string> Handle(UpdateInstructionCommand request, CancellationToken cancellationToken)
        {
            Entity = repo.Find(request.ID);

            if (Entity == null)
            {
                throw new InvalidOperationException($"Can't Update Because Not find Entity {request} with Id : {request.ID}");
            }

            Entity.Description = request.Description;
            Entity.ImageUrl    = request.ImageUrl;
            Entity.Step        = request.Step;

            Result = repo.Update(Entity);

            return(Result);
        }