示例#1
0
        public async Task VerifyNameIsNotTakenAsync_Should_Return_VerificationResult_With_Success_True()
        {
            const string name           = "Name";
            var          expectedResult = VerificationResult.Ok();

            _cityRepositoryMock.Setup(x => x.GetByNameAndStateIdAsync(It.IsAny <string>(), It.IsAny <Guid>()))
            .Returns(Task.FromResult <City>(null));

            var result = await _cityVerificationService.VerifyNameIsNotTakenAsync(name, Guid.NewGuid());

            result.Should().BeEquivalentTo(expectedResult);
        }
示例#2
0
        public async Task CheckDuplicateNamesAsync(string name, string polishName, Guid stateId)
        {
            var errors = new List <IError>();

            var verificationResult = await _cityVerificationService.VerifyNameIsNotTakenAsync(name, stateId);

            if (!verificationResult.Success)
            {
                errors.AddRange(verificationResult.Errors);
            }

            verificationResult = await _cityVerificationService.VerifyPolishNameIsNotTakenAsync(polishName, stateId);

            if (!verificationResult.Success)
            {
                errors.AddRange(verificationResult.Errors);
            }

            if (errors.Any())
            {
                throw new ConflictException(errors);
            }
        }
示例#3
0
        private async Task UpdateNamesAsync(City city, string name, string polishName, Guid stateId)
        {
            var errors = new List <IError>();

            if (!city.Name.Equals(name))
            {
                var verificationResult = await _cityVerificationService.VerifyNameIsNotTakenAsync(name, stateId);

                if (!verificationResult.Success)
                {
                    errors.AddRange(verificationResult.Errors);
                }
                else
                {
                    city.ChangeName(name);
                }
            }

            if (!city.PolishName.Equals(polishName))
            {
                var verificationResult = await _cityVerificationService.VerifyPolishNameIsNotTakenAsync(polishName, stateId);

                if (!verificationResult.Success)
                {
                    errors.AddRange(verificationResult.Errors);
                }
                else
                {
                    city.ChangePolishName(polishName);
                }
            }

            if (errors.Any())
            {
                throw new ConflictException(errors);
            }
        }