public void Handle_NotFoundCategory_ShouldThrowArgException()
        {
            // Arrange
            var handler = new CreateIssueCommandHandler(GetCategoryRepository().Object, GetMapper());

            var request = new CreateIssueCommand
            {
                CategoryId = 2,
                IssueName  = "Clean up room"
            };

            // Act
            var del = new AsyncTestDelegate(() => handler.Handle(request, CancellationToken.None));

            // Assert
            Assert.ThrowsAsync <System.ArgumentException>(del);
        }
Пример #2
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);
        }
Пример #3
0
        public CreateIssueCommandTests()
        {
            _currentUserId = "1a";
            var currentUserService = new Mock <ICurrentUserService>();

            currentUserService.Setup(x => x.GetUserId()).Returns(_currentUserId);

            var context = ContextFactory.CreateInMemoryContext(currentUserService.Object);

            _issueTypeRepository  = new IssueTypeRepository(context);
            _issueRepository      = new IssueRepository(context);
            _issueStateRepository = new IssueStateRepository(context);
            SeedDataTest();


            _handler = new CreateIssueCommandHandler(currentUserService.Object, _issueRepository, _issueStateRepository);
            _request = new CreateIssueCommand("Summary 1", _issueType.Id);
        }
        public async Task Handle_NewIssue_ShouldSaveNewIssue()
        {
            // Arrange
            var categoryRepositoryMock = GetCategoryRepository();

            var handler = new CreateIssueCommandHandler(categoryRepositoryMock.Object, GetMapper());

            var request = new CreateIssueCommand
            {
                CategoryId = 1,
                IssueName  = "Clean out room"
            };

            // Act
            await handler.Handle(request, CancellationToken.None);

            // Assert
            categoryRepositoryMock.Verify(x => x.SaveCategory(It.IsAny <Category>()), Times.Once);
        }
Пример #5
0
        public async void GivenCommandWithData_WhenCommandIsSendToApplicationService_ThenreadModelIsChanged()
        {
            var serviceLocator = new ServiceLocator();

            var readModel      = new AppReadModel("Cleaning main room", "Writing blog", "cleaning kitchen");
            var commandHandler = new CreateIssueCommandHandler(readModel);

            serviceLocator.RegisterQueryHandler(commandHandler);

            var applicationService = new IssueApplicationService(new QueryBus(serviceLocator.GetMediator()));

            //Given
            var query = new GetIssuesNamesQuery("cleaning");

            //When
            var result = await applicationService.GetIssuesNames(query);

            //Then
            result.Should().Have.Count.EqualTo(2);
            result.Should().Have.SameValuesAs("Cleaning main room", "cleaning kitchen");
        }
Пример #6
0
    public void GivenCommandWithData_WhenCommandIsSendToApplicationService_ThenWriteModelIsChanged()
    {
        var serviceLocator = new ServiceLocator();

        var writeModel     = new AppWriteModel();
        var commandHandler = new CreateIssueCommandHandler(writeModel);

        serviceLocator.RegisterCommandHandler <CreateIssueCommand, CreateIssueCommandHandler>(commandHandler);

        var applicationService = new IssueApplicationService(new CommandBus(serviceLocator.GetMediator()));

        //Given
        var createdIssueName = "cleaning";

        var command = new CreateIssueCommand(createdIssueName);

        //When
        applicationService.CreateIssue(command);

        //Then
        writeModel.Issues.Should().Have.Count.EqualTo(1);
        writeModel.Issues.Should().Have.SameValuesAs(createdIssueName);
    }