Exemplo n.º 1
0
        public async void CheckDnas(List <string> dnamock, bool expected)
        {
            CheckMutantCommand checkCommand = new CheckMutantCommand()
            {
                dna = dnamock
            };
            bool IsMutant = expected;

            _processor.Setup(x => x.isMutant(checkCommand.dna)).Returns(IsMutant);
            _mediator
            .Setup(m => m.Publish(It.IsAny <DnaProcessedEvent>(), It.IsAny <CancellationToken>()))
            .Verifiable();

            Dna dna = new Dna()
            {
                DnaSecuence = string.Join("|", checkCommand.dna.ToArray()), IsMutant = IsMutant
            };

            _repository.Setup(x => x.AddAsync(It.IsAny <Dna>())).ReturnsAsync(true);

            var result = await _sut.Handle(checkCommand, new System.Threading.CancellationToken());

            Assert.Equal(IsMutant, result);
            _repository.VerifyAll();
            _processor.VerifyAll();
            _mediator.VerifyAll();
        }
Exemplo n.º 2
0
        public async void CheckDnas(List <string> dnamock, string expected)
        {
            CheckMutantCommandValidator validator    = new CheckMutantCommandValidator();
            CheckMutantCommand          checkCommand = new CheckMutantCommand()
            {
                dna = dnamock
            };

            var result = validator.Validate(checkCommand);
            var errors = result.Errors.Select(e => e.ErrorMessage).ToList();

            Assert.False(result.IsValid);
            Assert.Contains(expected, errors);
        }
Exemplo n.º 3
0
        public async Task <ActionResult> Post([FromBody] CheckMutantCommand dna)
        {
            try
            {
                bool result = await _mediator.Send(dna);

                if (!result)
                {
                    return(StatusCode(403));
                }
                return(StatusCode(200));
            }
            catch (Exception e)
            {
                return(StatusCode(403));
            }
        }
Exemplo n.º 4
0
        public async void CheckEmptyDnas()
        {
            CheckMutantCommandValidator validator    = new CheckMutantCommandValidator();
            CheckMutantCommand          checkCommand = new CheckMutantCommand()
            {
                dna = new List <string>()
                {
                }
            };
            string expected = "NotEmptyValidator";

            var result = validator.Validate(checkCommand);
            var errors = result.Errors.Select(e => e.ErrorCode).ToList();

            Assert.False(result.IsValid);
            Assert.Contains(expected, errors);
        }
        public async void CheckDnas(List <string> dnamock, bool IsMutant, string expected)
        {
            CheckMutantCommand checkCommand = new CheckMutantCommand()
            {
                dna = dnamock
            };

            _mediator
            .Setup(m => m.Send(It.IsAny <CheckMutantCommand>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(IsMutant).Verifiable();

            var result = await _sut.Post(checkCommand);

            StatusCodeResult statusCodeResult = result as StatusCodeResult;

            Assert.Equal(expected, statusCodeResult.StatusCode.ToString());
            _mediator.VerifyAll();
        }
        public async void CheckException()
        {
            CheckMutantCommand checkCommand = new CheckMutantCommand()
            {
                dna = new List <string>()
                {
                    "AAAA", "AGTA", "ATAC", "AACG"
                }
            };
            string expected = "403";

            _mediator
            .Setup(m => m.Send(It.IsAny <CheckMutantCommand>(), It.IsAny <CancellationToken>()))
            .Throws(new Exception()).Verifiable();

            var result = await _sut.Post(checkCommand);

            StatusCodeResult statusCodeResult = result as StatusCodeResult;

            Assert.Equal(expected, statusCodeResult.StatusCode.ToString());
            _mediator.VerifyAll();
        }