Пример #1
0
        public async Task DeleteSpeechWithValidModelStateReturnOk()
        {
            //Arrange
            DeleteSpeechCommandMessage deleteSpeechCommandMessage = null;
            var moqDeleteSpeechUseCase = new Mock <IDeleteSpeechUseCase>();

            moqDeleteSpeechUseCase.Setup(x => x.Handle(It.IsAny <DeleteSpeechCommandMessage>()))
            .Returns(Task.CompletedTask)
            .Callback <DeleteSpeechCommandMessage>(x => deleteSpeechCommandMessage = x);

            var speechForDeleteDto = new SpeechForDeleteDto
            {
                Id      = Guid.NewGuid(),
                Version = 1
            };

            var sut = new SpeechController(It.IsAny <ICreateSpeechUseCase>(), It.IsAny <IUpdateSpeechUseCase>(), moqDeleteSpeechUseCase.Object);

            //Act
            IActionResult result = await sut.Delete(speechForDeleteDto);

            //Assert
            Assert.IsType <OkResult>(result);
            moqDeleteSpeechUseCase.Verify(x => x.Handle(It.IsAny <DeleteSpeechCommandMessage>()), Times.Once);
            Assert.Equal(speechForDeleteDto.Id, deleteSpeechCommandMessage.SpeechId);
            Assert.Equal(speechForDeleteDto.Version, deleteSpeechCommandMessage.OriginalVersion);
        }
Пример #2
0
        public async Task DeleteSpeechWithInvalidModelStateReturnBadRequest()
        {
            //Arrange
            var moqRegisterSpeechUseCase = new Mock <ICreateSpeechUseCase>();
            var moqUpdateSpeechUseCase   = new Mock <IUpdateSpeechUseCase>();
            var sut = new SpeechController(moqRegisterSpeechUseCase.Object, moqUpdateSpeechUseCase.Object, It.IsAny <IDeleteSpeechUseCase>());

            sut.ModelState.AddModelError("x", "Invalid ModelState");

            //Act
            IActionResult result = await sut.Delete(It.IsAny <SpeechForDeleteDto>());

            //Assert
            Assert.IsType <BadRequestObjectResult>(result);
        }