public async Task <int> AddLogAsync(LogCreateDto logCreateDto, string applicationDisplayName) { ApplicationEntity application = await _applicationRepository.TryGetByIdAsync(logCreateDto.ApplicationId); if (application == null) { throw new ArgumentException($"Application with id {logCreateDto.ApplicationId} not found."); } if (application.DisplayName != applicationDisplayName) { throw new ArgumentException("Application display name mismatch."); } LogEntity log = logCreateDto.ToLog(); _logRepository.Add(log); await _unitOfWork.CommitAsync(); return(log.Id); }
public async Task WhenAddingLogWithValidApplicationThenLogIsAddedToRepository() { // Arrange ILogRepository fakeLogRepository = A.Fake <ILogRepository>(); ApplicationEntity application = new ApplicationEntity() { DisplayName = "TestApplicationDisplayName" }; IApplicationRepository fakeApplicationRepository = A.Fake <IApplicationRepository>(); A.CallTo(() => fakeApplicationRepository.TryGetByIdAsync(1)).Returns(Task.FromResult(application)); IUnitOfWork fakeUnitOfWork = A.Fake <IUnitOfWork>(); LogCreateDto logCreateDto = new LogCreateDto() { ApplicationId = 1, Logger = "TestLogger", Level = "TestLevel", Message = "TestMessage" }; ILogService logService = new LogService(fakeLogRepository, fakeApplicationRepository, fakeUnitOfWork); // Act await logService.AddLogAsync(logCreateDto, "TestApplicationDisplayName"); // Assert A.CallTo(() => fakeLogRepository.Add(A <LogEntity> .That.Matches(l => l.Logger == "TestLogger" && l.Level == "TestLevel" && l.Message == "TestMessage" && l.ApplicationId == 1 ))).MustHaveHappened(); }
public ActionResult Put(Guid id, LogCreateDto dto) { var entity = _repository.Update(id, dto); return(Ok(entity)); }
public ActionResult Post([FromBody] LogCreateDto dto) { var entity = _repository.Create(dto); return(Ok(entity)); }