// Получение названия курса по id:
 public async Task <MailingsGeneratorDomain.Models.Mailing> GetCourseAsync(GetMailingModel getModel)
 {
     if (getModel.Id.HasValue)
     {
         return(await _dbContext.Mailings.FirstOrDefaultAsync(m => m.MailingId == getModel.Id.Value));
     }
     return(await _dbContext.Mailings.FirstOrDefaultAsync(m => m.CourseName.Equals(getModel.Name)));
 }
Beispiel #2
0
        public async Task GetCourseAsync_ThrowsExpected(GetMailingModel getModel,
                                                        Type type, string message)
        {
            //arrange
            //act
            var exception = Assert.ThrowsAsync(type, () => _service.GetCourseAsync(getModel));

            // assert
            Assert.AreEqual(message, exception.Message);
            Assert.AreEqual(exception.GetType(), type);
        }
Beispiel #3
0
        public async Task <MailingsGeneratorDomain.Models.Mailing> GetCourseAsync(GetMailingModel getMailingModel)
        {
            if (getMailingModel == null || getMailingModel.IsEmpty())
            {
                throw new ExceptionTypes.NullValueException();
            }

            if (getMailingModel.Id.HasValue && getMailingModel.Id.Value < 1)
            {
                throw new ExceptionTypes.IncorrectIdException();
            }

            return(await _repository.GetCourseAsync(getMailingModel));
        }
 public async Task <IActionResult> GetCourseAsync(GetMailingModel getModel)
 {
     try
     {
         return(Ok(await GetCourseAsync(getModel)));
     }
     catch (ExceptionTypes.NotExistException er)
     {
         return(NotFound(er.StackTrace));
     }
     catch (Exception er)
     {
         return(BadRequest(er.StackTrace));
     }
 }
Beispiel #5
0
        public async Task GetCourseAsync_CreatesMailingAndReturnsIt()
        {
            //arrange
            var model = new GetMailingModel()
            {
                Name = "probability theory"
            };

            //act
            var mail1 = await _service.GetCourseAsync(1);

            var mail2 = await _service.GetCourseAsync(model);

            // assert
            Assert.IsTrue(_mailingsDb.ContainsValue(mail1));
            Assert.IsTrue(_mailingsDb.ContainsKey(mail1.MailingId));
            Assert.IsTrue(_mailingsDb.ContainsValue(mail2));
            Assert.IsTrue(_mailingsDb.ContainsKey(mail2.MailingId));
        }