Beispiel #1
0
        public async Task DeleteBotFromDialogAsyncReturnsServiceResponseWithExMessage_IfErrorOccurs()
        {
            BotDialogAddDTO botDialog = new BotDialogAddDTO();

            _dbContextMock.Setup(r => r.SaveChangesAsync(CancellationToken.None)).Callback(() => throw new Exception());

            ServiceResponse <bool> serviceResponse = await _service.DeleteBotFromDialogAsync(botDialog);

            Assert.False(serviceResponse.Success);
            Assert.NotNull(serviceResponse.Message);
        }
Beispiel #2
0
        public async Task DeleteBotFromDialogAsyncCallsSaveChanges_and_ReturnsServiceResponseWithData()
        {
            BotDialogAddDTO botDialog = new BotDialogAddDTO();

            ServiceResponse <bool> serviceResponse = await _service.DeleteBotFromDialogAsync(botDialog);

            _botRepositoryMock.Verify(r => r.DeleteBotFromDialog(It.IsAny <BotDialog>()), Times.Once);
            _dbContextMock.Verify(r => r.SaveChangesAsync(CancellationToken.None), Times.AtLeast(1));
            Assert.IsAssignableFrom <ServiceResponse <bool> >(serviceResponse);
            Assert.True(serviceResponse.Success);
        }
Beispiel #3
0
        public async Task AddBotToDialogAsyncCallsSaveChanges_and_ReturnsServiceResponseWithData()
        {
            string          name      = "name";
            BotDialogAddDTO botDialog = new BotDialogAddDTO()
            {
                BotName = name
            };

            ServiceResponse <string> serviceResponse = await _service.AddBotToDialogAsync(botDialog);

            _botRepositoryMock.Verify(r => r.AddBotToDialog(It.Is <BotDialog>(b => b.BotName == name)), Times.Once);
            _dbContextMock.Verify(r => r.SaveChangesAsync(CancellationToken.None), Times.AtLeast(1));
            Assert.IsAssignableFrom <ServiceResponse <string> >(serviceResponse);
            Assert.True(serviceResponse.Success);
            Assert.Equal(name, serviceResponse.Data);
        }
Beispiel #4
0
        public async Task <ServiceResponse <bool> > DeleteBotFromDialogAsync(BotDialogAddDTO botDialogDTO)
        {
            ServiceResponse <bool> serviceResponse = new ServiceResponse <bool>();

            try
            {
                BotDialog botDialog = _mapper.Map <BotDialog>(botDialogDTO);
                _botRepository.DeleteBotFromDialog(botDialog);
                await _myDBContext.SaveChangesAsync();

                serviceResponse.Data = true;
                return(serviceResponse);
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = ex.Message;
                return(serviceResponse);
            }
        }
Beispiel #5
0
        public async Task <ServiceResponse <string> > AddBotToDialogAsync(BotDialogAddDTO botDialogDTO)
        {
            ServiceResponse <string> serviceResponse = new ServiceResponse <string>();

            try
            {
                BotDialog botDialog = _mapper.Map <BotDialog>(botDialogDTO);
                _botRepository.AddBotToDialog(botDialog);
                await _myDBContext.SaveChangesAsync();

                serviceResponse.Data = botDialog.BotName;
                return(serviceResponse);
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = ex.Message;
                return(serviceResponse);
            }
        }