Exemplo n.º 1
0
        public async Task HandleAsync(CreateStateCommand command, CancellationToken cancellationToken = default)
        {
            await CheckDuplicateNamesAsync(command.Name, command.PolishName);

            var state = _mapper.Map <CreateStateCommand, State>(command);
            await _stateRepository.AddAsync(state);
        }
Exemplo n.º 2
0
        public async Task AddAsync_Should_Add_State()
        {
            var state = State.Builder()
                        .SetId(Guid.NewGuid())
                        .SetRowVersion(Array.Empty <byte>())
                        .SetName("StateRepositoryTestAddAsync")
                        .SetPolishName("StateRepositoryTestAddAsync")
                        .Build();
            var stateEntity = new StateEntity
            {
                Id         = state.Id,
                Name       = state.Name,
                PolishName = state.PolishName,
                RowVersion = state.RowVersion.ToArray()
            };

            _mapperMock.Setup(x => x.Map <State, StateEntity>(It.IsAny <State>()))
            .Returns(stateEntity);
            _memoryCacheMock.Setup(x => x.Remove(It.IsAny <object>()));

            Func <Task> result = async() => await _repository.AddAsync(state);

            await result.Should().NotThrowAsync <Exception>();

            var addedState = await _dbContext.States.FindAsync(state.Id);

            addedState.Should().NotBeNull();
            _memoryCacheMock.Verify(x => x.Remove(It.Is <object>(key => ReferenceEquals(key, CacheKeys.StatesKey))));
        }
Exemplo n.º 3
0
        public async Task SetCity(string city, string stateName)
        {
            var isCityExists = (await _cityRepo.GetByAsync(x => x.Name == city)) != null;

            if (!isCityExists)
            {
                var state = await _stateRepo.GetByAsync(x => x.Name == stateName || x.ShortName == stateName);

                if (state == null)
                {
                    var newState = new State {
                        Name = RemoveDigits(stateName), ShortName = RemoveDigits(stateName)
                    };
                    var stateId = await _stateRepo.AddAsync(newState);

                    newState.Id = stateId;
                    await _cityRepo.AddAsync(new City { Name = RemoveDigits(city), State = newState });
                }
                else
                {
                    await _cityRepo.AddAsync(new City { Name = RemoveDigits(city), State = state });
                }
            }
        }