コード例 #1
0
        public async Task UpdateCaptainAsync(Captain captain)
        {
            try
            {
                var validationError = captain.Validate();
                if (validationError.Any())
                {
                    throw new ValidationException($"A validation exception was raised while trying to update a Captain : {JsonConvert.SerializeObject(validationError, Formatting.Indented)}");
                }
                await EnsureCaptainExistAsync(captain.Id);
                await CheckExplorersTeamExistAsync(captain.ExplorersTeamId);

                await m_repository.UpdateAsync(new List <Captain> {
                    captain
                });
            }
            catch (ValidationException e)
            {
                m_logger.LogWarning(e, "A validation failed");
                throw;
            }
            catch (Exception e) when(e.GetType() != typeof(ValidationException))
            {
                m_logger.LogCritical(e, $"Unexpected Exception while trying to update a Captain with the properties : {JsonConvert.SerializeObject(captain, Formatting.Indented)}");
                throw;
            }
        }
コード例 #2
0
        public async Task UpdateNewCaptain_Ok()
        {
            //Arrange
            var id      = Guid.NewGuid();
            var captain = new Captain
            {
                Id   = id,
                Name = "Test",
            };

            //Act
            await m_repository.CreateAsync(captain);

            var(_, captains) = await m_repository.SearchAsync(new Pagination(), new Ordering(), new CaptainFilter
            {
                SearchTerm = id.ToString()
            });

            captain.Name = "Modified";
            await m_repository.UpdateAsync(new List <Captain> {
                captain
            });

            var(_, updatedResponse) = await m_repository.SearchAsync(new Pagination(), new Ordering(), new CaptainFilter
            {
                SearchTerm = id.ToString()
            });

            //Assert
            Assert.Equal(id, captains.First().Id);
            Assert.Equal("Modified", captains.First().Name);
            await m_repository.DeleteAsync(updatedResponse.First());
        }