Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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();
        }
Exemplo n.º 3
0
        public ActionResult Put(Guid id, LogCreateDto dto)
        {
            var entity = _repository.Update(id, dto);

            return(Ok(entity));
        }
Exemplo n.º 4
0
        public ActionResult Post([FromBody] LogCreateDto dto)
        {
            var entity = _repository.Create(dto);

            return(Ok(entity));
        }