public async Task CreateShouldSucceed() { // Arrange var id = TeamId.New; var name = new Name("name"); var team = new Team(id, name); var image = "image"; team.SetImage(image); var description = (Description)"description"; team.SetDescription(description); var layout = new Layout(Guid.NewGuid()); team.SetLayout(layout); var memberId = Guid.NewGuid(); var member = new Member(memberId); team.AddMember(member); // Act await _repository.CreateAsync(team); // Assert var data = RepositoryHelper.ForTeam.GetTeams(); data.Should().HaveCount(1); var result = data.First(); result.Id.Should().Be(id); result.Name.Should().Be(name); result.Image.Should().Be(image); result.Description.Should().Be(description); result.DriverWait.Should().Be(DriverWait.Unspecified); result.Layout.Should().Be(layout); result.Members.Should().NotBeNull(); result.Members.Should().HaveCount(1); result.Members.First().Should().Be(member); }
public async Task <Result> Handle(CreateTeamCommand command, CancellationToken cancellationToken) { var id = _identifierProvider.Generate(); var teamToCreate = new Team(TeamId.With(id), new Name(command.Name)); teamToCreate.SetImage(command.Image); teamToCreate.SetDescription((Description)command.Description); if (Guid.TryParse(command.Layout, out Guid layoutId) && layoutId != default(Guid)) { var layout = new Layout(layoutId); teamToCreate.SetLayout(layout); } teamToCreate.SetVersion(_versionProvider.Generate()); Result result; try { await _teamWriteRepository.CreateAsync(teamToCreate); return(Result.Ok(id, teamToCreate.Version)); } catch (UniqueKeyException) { result = Result.Fail(new List <Failure>() { new HandlerFault() { Code = HandlerFaultCode.Conflict.Name, Message = HandlerFailures.ConflictTeam, Target = "name" } } ); } catch { result = Result.Fail(CustomFailures.CreateTeamFailure); } return(result); }