public void ShouldReturnErrorWhenDescriptionLenghtIsGreaterThan100() { var command = new CreateChannelCommand { Name = "channelOne", Description = "PS15TihJoUQEydtvAZFa5SeaHcDNdosgagsPHrLIPS15TihJoUQEydtvAZFa5SeaHcDNdosgagsPHrLIPS15TihJoUQEydtvAZFa5SeaHcDNdosgagsPHrLI", AdministratorId = Guid.NewGuid() }; command.Validate(); command.Invalid.Should().BeTrue(); }
public async Task ShouldReturnErrorWhenCommandIsInvalid(CreateChannelCommand command) { var fakeUserRepository = new Mock <IUserRepository>(); var fakeChannelRepository = new Mock <IChannelRepository>(); var handler = new ChannelHandler(fakeChannelRepository.Object, fakeUserRepository.Object); ICommandResult result = await handler.HandleAsync(command); handler.Invalid.Should().BeTrue(); result.Success.Should().BeFalse(); result.Errors.Should().HaveCountGreaterThan(0); }
public void ShouldReturnErrorWhenNameIsWhiteSpaces() { var command = new CreateChannelCommand { Name = " ", Description = "The first channel", AdministratorId = Guid.NewGuid() }; command.Validate(); command.Invalid.Should().BeTrue(); }
public void ShouldReturnSuccessWhenDescriptionIsWhiteSpace() { var command = new CreateChannelCommand { Name = "channelOne", Description = " ", AdministratorId = Guid.NewGuid() }; command.Validate(); command.Valid.Should().BeTrue(); }
public async Task WhenPostingChannel_ItShouldIssueCreateChannelCommand() { var data = new NewChannelData(BlogId, ChannelName.Value, Price.Value, IsVisibleToNonSubscribers); var command = new CreateChannelCommand(Requester, ChannelId, BlogId, ChannelName, Price, IsVisibleToNonSubscribers); this.requesterContext.Setup(_ => _.GetRequesterAsync()).ReturnsAsync(Requester); this.guidCreator.Setup(_ => _.CreateSqlSequential()).Returns(ChannelId.Value); this.createChannel.Setup(_ => _.HandleAsync(command)).Returns(Task.FromResult(0)).Verifiable(); var result = await this.target.PostChannelAsync(data); Assert.AreEqual(result, ChannelId); this.createChannel.Verify(); }
public async Task ShouldReturnSuccessWhenAdministratorExists() { Guid administratorId = Guid.Parse("fecd358a-5098-49bf-b26a-3a366a6da6f2"); var fakeUserRepository = new Mock <IUserRepository>(); fakeUserRepository .Setup(repository => repository.GetById(It.IsAny <Guid>())) .ReturnsAsync((Guid id) => { if (id != administratorId) { return(null); } return(new GetUserByIdQueryResult { Id = administratorId, Username = "******" }); }); var fakeChannelRepository = new Mock <IChannelRepository>(); fakeChannelRepository .Setup(repository => repository.CreateChannel(It.IsAny <Channel>())); var command = new CreateChannelCommand { Name = "channelOne", Description = "The first channel", AdministratorId = administratorId }; var handler = new ChannelHandler(fakeChannelRepository.Object, fakeUserRepository.Object); ICommandResult result = await handler.HandleAsync(command); var resultOutput = result.Data as ChannelOutput; result.Success.Should().BeTrue(); result.Data.Should().NotBeNull(); result.Errors.Should().BeNullOrEmpty(); resultOutput.Should().NotBeNull(); resultOutput?.Id.Should().NotBeEmpty(); resultOutput?.Administrator.Should().NotBeNull(); resultOutput?.Administrator?.Id.Should().Be(administratorId); handler.Valid.Should().BeTrue(); fakeChannelRepository.Verify( repository => repository.CreateChannel(It.IsAny <Channel>()), Times.Once()); }
public async Task Owner_can_create_channel() => await Run(async sut => { var group = await GroupBuilder.For(sut) .CreateGroup("group1") .Build(); var createChannel = new CreateChannelCommand(group.OwnerId, group.GroupId, Guid.NewGuid(), "channel1"); await sut.SendAsync(createChannel); var channels = await sut.QueryAsync(new GetGroupChannelsQuery(group.OwnerId, group.GroupId)); channels.Should().ContainEquivalentOf(new ChannelDto { GroupId = group.GroupId, ChannelId = createChannel.ChannelId, ChannelName = createChannel.ChannelName }); });
public async Task <ActionResult> CreateChannel(ChannelPostViewModel data, [FromHeader] Guid authorization, [FromServices] IHandler <CreateChannelCommand> handler) { var command = new CreateChannelCommand { Name = data.Name, Description = data.Description, AdministratorId = authorization }; ICommandResult result = await handler.HandleAsync(command); if (!result.Success) { return(BadRequest(new ErrorViewModel(result))); } return(Ok(result.Data)); }
public async Task Member_with_valid_permissions_can_create_channel(string validPermission) => await Run(async sut => { var group = await GroupBuilder.For(sut) .CreateGroup("group1") .AsOwner().CreateRole("role1").AddPermission(validPermission).Build() .CreateMember().AssignRole(1).Build() .Build().Build(); var createChannel = new CreateChannelCommand(group.OwnerId, group.GroupId, Guid.NewGuid(), "channel1"); await sut.SendAsync(createChannel); var channels = await sut.QueryAsync(new GetGroupChannelsQuery(group.OwnerId, group.GroupId)); channels.Should().ContainEquivalentOf(new ChannelDto { GroupId = group.GroupId, ChannelId = createChannel.ChannelId, ChannelName = createChannel.ChannelName }); });
public async Task ShouldReturnSuccessWhenCommandIsValid(CreateChannelCommand command) { var fakeUserRepository = new Mock <IUserRepository>(); fakeUserRepository .Setup(repository => repository.GetById(It.IsAny <Guid>())) .ReturnsAsync((Guid id) => new GetUserByIdQueryResult { Id = id, Username = "******" }); var fakeChannelRepository = new Mock <IChannelRepository>(); fakeChannelRepository .Setup(repository => repository.CreateChannel(It.IsAny <Channel>())); var handler = new ChannelHandler(fakeChannelRepository.Object, fakeUserRepository.Object); ICommandResult result = await handler.HandleAsync(command); var resultOutput = result.Data as ChannelOutput; handler.Valid.Should().BeTrue(); result.Success.Should().BeTrue(); result.Data.Should().NotBeNull(); result.Errors.Should().BeNullOrEmpty(); resultOutput.Should().NotBeNull(); resultOutput?.Id.Should().NotBeEmpty(); resultOutput?.Administrator.Should().NotBeNull(); resultOutput?.Administrator?.Id.Should().Be(command.AdministratorId); fakeChannelRepository.Verify( repository => repository.CreateChannel(It.IsAny <Channel>()), Times.Once()); fakeChannelRepository.Verify( repository => repository.AddUserToChannel( It.Is <Guid>(id => id == command.AdministratorId), It.Is <Guid>(id => id == resultOutput.Id), It.Is <bool>(isAdministrator => isAdministrator == true))); }
public async Task ShouldReturnErrorWhenAdministratorNotExists() { var fakeUserRepository = new Mock <IUserRepository>(); fakeUserRepository .Setup(repository => repository.GetById(It.IsAny <Guid>())) .Returns(Task.FromResult <GetUserByIdQueryResult>(null)); var fakeChannelRepository = new Mock <IChannelRepository>(); var command = new CreateChannelCommand { Name = "channelOne", Description = "The first channel", AdministratorId = Guid.NewGuid() }; var handler = new ChannelHandler(fakeChannelRepository.Object, fakeUserRepository.Object); ICommandResult result = await handler.HandleAsync(command); result.Success.Should().BeFalse(); result.Errors.Should().HaveCountGreaterThan(0); handler.Invalid.Should().BeTrue(); }
public void SetUp() { createChannelCommand = new CreateChannelCommand(RepositoryFactory, Log, FileSystem, ClientFactory); }
public void SetUp() { createChannelCommand = new CreateChannelCommand(RepositoryFactory, FileSystem, ClientFactory, CommandOutputProvider); }