public async Task Handle_ValidCommand_ShouldUpdateEntriesSuccessfully() { //Create entity to inserted and update var entity = _fixture.Create <Domain.Entities.Issue>(); // Arrange var issue = await ContextOperation.CreateEntity(_context, entity); // update properties issue.Title = _fixture.Create <string>(); // AutoMapper setup _mapperMock.Setup(m => m.Map(It.IsAny <UpdateIssueCommand>(), It.IsAny <Domain.Entities.Issue>())).Returns(issue); // creating System Under Test var sut = new UpdateIssueCommandHandler(_context, _mapperMock.Object); // Act await sut.Handle(new UpdateIssueCommand(), CancellationToken.None); // Assert var dbIssue = _context.Issues.First(); dbIssue.Title.ShouldBe(issue.Title); }
public async Task Handle_ValidCommand_ShouldLoginSuccessfully(LoginOutput loginOutput) { // Arrange _mapperMock.Setup(m => m.Map <LoginOutput>(It.IsAny <User>())).Returns(loginOutput); // AutoMapper setup _appsettingMock.SetReturnsDefault(new AppSettings { Issuer = "key1", Secret = "kesdfaaaaaasffffffffy1" }); var sut = new LoginCommandHandler(_context, _mapperMock.Object, _appsettingMock.Object); // creating system under test var temUser = _fixture.Create <User>(); temUser.PasswordHash = "3pRTT3NlZJrki0wrSlmOjA=="; // Act await ContextOperation.CreateEntity(_context, temUser); var password = SecurityHelper.Decrypt(temUser.PasswordHash); var output = await sut.Handle(new LoginCommand { Email = temUser.Email, Password = password }, CancellationToken.None); // Assert Assert.True(!string.IsNullOrEmpty(output.Token)); }
public async Task Handle_GetAllQuery_ShouldReturnEntriesSuccessfully(List <IssueTypesDto> output) { // Arrange _mapperMock.Setup(m => m.Map <List <IssueTypesDto> >(It.IsAny <List <IssueType> >())).Returns(output); // AutoMapper setup var sut = new GetAllIssueTypesQueryHandler(_context, _mapperMock.Object); // creating system under test var temIssueType = _fixture.Create <IssueType>(); // Act await ContextOperation.CreateEntity(_context, temIssueType); var result = await sut.Handle(new GetAllIssueTypesQuery(), CancellationToken.None); // Assert result.Count().ShouldBeGreaterThan(0); }
public async Task Handle_ValidCommand_ShouldSaveEntriesSuccessfully(Domain.Entities.Issue Issue) { _fixture.RepeatCount = 0; // Arrange _mapperMock.Setup(m => m.Map <Domain.Entities.Issue>(It.IsAny <CreateIssueCommand>())) .Returns(Issue); // AutoMapper setup var sut = new CreateIssueCommandHandler(_context, _mapperMock.Object); // creating system under test var project = await ContextOperation.CreateEntity(_context, _fixture.Create <Project>()); // Act await sut.Handle(new CreateIssueCommand { ProjectId = project.Id }, CancellationToken.None); // Assert _context.Issues.Count().ShouldBe(1); }
public async Task Handle_ValidId_EntityShouldNotDeletedBecauseRelatedEntities() { _fixture.RepeatCount = 1; //Create entity to inserted and delete it var temProject = _fixture.Create <Project>(); // Arrange var project = await ContextOperation.CreateEntity(_context, temProject); var sut = new DeleteProjectCommandHandler(_context); // Assert await Assert.ThrowsAsync <DeleteFailureException>(() => sut.Handle(new DeleteProjectCommand { Id = project.Id, OwnerId = project.OwnerId }, CancellationToken.None)); }
public async Task Handle_ValidId_EntityShoulDeletedSuccessfully() { _fixture.RepeatCount = 0; //Create entity to inserted and delete it var temIssue = _fixture.Create <Domain.Entities.Issue>(); // Arrange var Issue = await ContextOperation.CreateEntity(_context, temIssue); var sut = new DeleteIssueCommandHandler(_context); // Act await sut.Handle(new DeleteIssueCommand { Id = Issue.Id }, CancellationToken.None); // Assert _context.Issues.Count().ShouldBe(0); }
public async Task Handle_ValidId_EntityShoulDeletedSuccessfully() { _fixture.RepeatCount = 0; //Create entity to inserted and delete it var temproject = _fixture.Create <Project>(); // Arrange var project = await ContextOperation.CreateEntity(_context, temproject); var sut = new DeleteProjectCommandHandler(_context); // Act await sut.Handle(new DeleteProjectCommand { Id = project.Id, OwnerId = project.OwnerId }, CancellationToken.None); // Assert _context.Projects.Count().ShouldBe(0); }
public async Task Handle_ValidCommand_ShouldSaveEntriesSuccessfully(Project Project) { _fixture.RepeatCount = 0; // Arrange _mapperMock.Setup(m => m.Map <Project>(It.IsAny <CreateProjectCommand>())).Returns(Project); // AutoMapper setup _mediatorMock.Setup(m => m.Publish(It.IsAny <CreateProjectParticipantsCommand>(), It.IsAny <CancellationToken>())); var sut = new CreateProjectCommandHandler(_context, _mapperMock.Object, _mediatorMock.Object); // creating system under test // Act var owner = _fixture.Create <User>(); await ContextOperation.CreateEntity(_context, owner); await sut.Handle(new CreateProjectCommand { OwnerId = owner.Id }, CancellationToken.None); // Assert _context.Projects.Count().ShouldBe(1); }