public async Task <Result> Handle(CreateSiteCommand request, CancellationToken cancellationToken) { Result result; var id = _identifierProvider.Generate(); var siteToCreate = new Site(id, request.Code, request.Name, request.Source); siteToCreate.Version = _versionProvider.Generate(); try { await _siteWriteRepository.CreateAsync(siteToCreate); result = Result.Ok(id, siteToCreate.Version); } catch (UniqueKeyException) { result = Result.Fail(new System.Collections.Generic.List <Failure>() { new HandlerFault() { Code = HandlerFaultCode.Conflict.Name, Message = HandlerFailures.CodeSourceConflict, Target = "code-source" } } ); } catch { result = Result.Fail(CustomFailures.CreateSiteFailure); } return(result); }
public async Task CreateShouldSucceed() { //Arrange var code = "TestCode"; var name = "TestName"; var source = "TestSource"; var site = new Site(Guid.NewGuid(), code, name, source); //Act await _repository.CreateAsync(site); //Asssert var data = RepositoryHelper.ForSite.GetSites(); data.Should().HaveCount(1); var result = data.First(); result.Name.Should().Be(name); result.Code.Should().Be(code); result.Source.Should().Be(source); }