Beispiel #1
0
            public void ShouldThrowException_IfCommandIsInvalid()
            {
                var command = new Logic.Product.Delete.Command();

                _validator.Validate(command).Returns(Helper.GetErrorValidationResult());

                Assert.Catch<ValidationException>(() => _sut.Handle(command));
            }
Beispiel #2
0
            public void ShouldThrowException_IfCommandHasWrongVersion()
            {
                var version1 = new byte[0];

                var version2 = new byte[] {5};

                var command = new Logic.Product.Delete.Command { Id = 1, Version = version1 };

                Debug.Assert(command.Id != null, $"{nameof(command.Id)} != null");

                _validator.Validate(command).Returns(new ValidationResult());

                _repository.GetRowVersion(command.Id.Value).Returns(version2);

                Assert.Catch<OptimisticConcurrencyException<Logic.Product.Delete.Command>>(() => _sut.Handle(command));
            }
Beispiel #3
0
            public void ShouldDelete_IfCommandIsValid()
            {
                var version = new byte[0];

                var command = new Logic.Product.Delete.Command { Id = 1, Version = version };

                Debug.Assert(command.Id != null, $"{nameof(command.Id)} != null");

                _validator.Validate(command).Returns(new ValidationResult());

                _repository.GetRowVersion(command.Id.Value).Returns(version);

                _repository.Can(command.Id.Value).Returns(true);

                _sut.Handle(command);

                _repository.Received().Execute(command.Id.Value);
            }
Beispiel #4
0
            public void ShouldThrowException_IfProductCannotBeDeleted()
            {
                var version = new byte[0];

                var command = new Logic.Product.Delete.Command { Id = 1, Version = version };

                Debug.Assert(command.Id != null, $"{nameof(command.Id)} != null");

                _validator.Validate(command).Returns(new ValidationResult());

                _repository.GetRowVersion(command.Id.Value).Returns(version);

                _repository.Can(command.Id.Value).Returns(false);

                Assert.Catch<ForeignKeyException<Logic.Product.Delete.Command>>(() => _sut.Handle(command));
            }
Beispiel #5
0
            public void ShouldReturnNoErrors_IfCommandIsValid()
            {
                var command = new Logic.Product.Delete.Command {Id = 1, Version = new byte[] {5}};

                var result = _sut.Validate(command);

                Assert.That(result.Errors.Count == 0);
            }
Beispiel #6
0
            public void ShouldReturnError_IfCommandHasVersionEqualToNull()
            {
                var command = new Logic.Product.Delete.Command { Id = 1 };

                var result = _sut.Validate(command);

                Assert.That(Common.Test.Helper.HasError(result, nameof(Logic.Product.Delete.Command.Version)));
            }