public async Task Handle_GivenConversationIdAndMemberListValid_ShouldUpdateConversation() { ////Arrange var sut = new UpdateConversationNameCommandHandler(_context, _mapper); var command = new UpdateConversationNameCommand { Id = validConversationId, Name = "valid group name", Members = new List <UserModel>() { new UserModel() { UserId = validUserId1, DisplayName = "test" } } }; //// Act await sut.Handle(command, CancellationToken.None); var entity = _context.Conversations.Find(validConversationId); entity.ShouldNotBeNull(); entity.Name.ShouldBe("valid group name"); entity.Members.Count.ShouldBe(1); }
public async Task Handle_GivenConversationIdInvalid_ShouldRaiseNotFoundException() { ////Arrange var sut = new UpdateConversationNameCommandHandler(_context, _mapper); var command = new UpdateConversationNameCommand { Id = Guid.NewGuid(), Name = "valid group name" }; //// Act await Assert.ThrowsAsync <NotFoundException>(() => sut.Handle(command, CancellationToken.None)); }
public void Validate_ValidCommand_ShouldBeTrue() { var command = new UpdateConversationNameCommand { Name = new string('a', 200), Id = validConversationId1 }; var validator = new UpdateConversationNameCommandValidator(); var result = validator.Validate(command); result.IsValid.ShouldBe(true); }
public void Validate_NameIsGreaterThan200_ShouldBeFalse() { var command = new UpdateConversationNameCommand { Name = new string('a', 201), Id = validConversationId1 }; var validator = new UpdateConversationNameCommandValidator(); var result = validator.Validate(command); result.IsValid.ShouldBe(false); }
public async Task GivenValidUpdateConversationNameCommand_ReturnsSuccessCode() { var client = await _factory.GetAuthenticatedClientAsync(); var command = new UpdateConversationNameCommand { Id = new Guid("B73477A4-F61D-46FA-873C-7D71C01DFBDF"), Name = "Conversation rename", }; var content = IntegrationTestHelper.GetRequestContent(command); var response = await client.PutAsync($"/api/Conversation/{command.Id}/name", content); response.EnsureSuccessStatusCode(); }
public async Task GivenConversationIdDifferId_ReturnsBadrequest() { var client = await _factory.GetAuthenticatedClientAsync(); var command = new UpdateConversationNameCommand { Id = new Guid("B73477A4-F61D-46FA-873C-7D71C01DFBDF"), Name = "Conversation rename", }; var content = IntegrationTestHelper.GetRequestContent(command); var response = await client.PutAsync($"/api/Conversation/{Guid.NewGuid()}/name", content); response.StatusCode.ShouldBe(HttpStatusCode.BadRequest); }
public async Task Handle_GivenConversationIdValid_ShouldUpdateConversation() { ////Arrange var sut = new UpdateConversationNameCommandHandler(_context, _mapper); var command = new UpdateConversationNameCommand { Id = validConversationId, Name = "valid group name" }; //// Act await sut.Handle(command, CancellationToken.None); var entity = _context.Conversations.Find(validConversationId); entity.ShouldNotBeNull(); entity.Name.ShouldBe("valid group name"); }
public async Task <ActionResult> UpdateConversationName(string conversationId, UpdateConversationNameCommand command) { if (!conversationId.Equals(command.Id.ToString())) { return(BadRequest()); } await Mediator.Send(command); return(NoContent()); }