public async Task CreateShouldSucceed() { // Arrange var id = Guid.NewGuid(); var name = "name"; var businessUnit = new BusinessUnit(id, name); // Act await _repository.CreateAsync(businessUnit); // Assert var data = RepositoryHelper.ForBusinessUnit.GetBusinessUnits(); data.Should().HaveCount(1); var result = data.First(); result.Id.Should().Be(id); result.Name.Should().Be(name); }
public async Task <Result> Handle(CreateBusinessUnitCommand request, CancellationToken cancellationToken) { var id = _identifierProvider.Generate(); var businessUnitToCreate = new BusinessUnit(id, request.Name); businessUnitToCreate.Version = _versionProvider.Generate(); Result result; try { await _businessUnitWriteRepository.CreateAsync(businessUnitToCreate); result = Result.Ok(id, businessUnitToCreate.Version); } catch (UniqueKeyException) { result = Result.Fail(new System.Collections.Generic.List <Failure>() { new HandlerFault() { Code = HandlerFaultCode.Conflict.Name, Message = HandlerFailures.Conflict, Target = "name" } } ); } catch { result = Result.Fail(CustomFailures.CreateBusinessUnitFailure); } return(result); }