public async void handle_ProjectCategorieslNull_test()
        {
            Project         project = new Project();
            ProjectCategory pc      = null;

            this._unitOfUnitMock.Setup(mock => mock.ProjectRepository.Create(It.IsAny <Project>())).Returns(project);

            this._unitOfUnitMock
            .Setup(mock => mock.RelationsRepository.CreateProjectCategory(It.IsAny <ProjectCategory>())).Returns(pc);

            CreateProjectCommand command = new CreateProjectCommand(new CreateProjectModel()
            {
                ProjectName = "test", Categories = new List <Category>()
                {
                    new Category()
                    {
                        CategoryId = 1, CategoryName = "test", Created = DateTime.Now, Id = 1
                    }
                }
            });
            CreateProjectHandler handler = new CreateProjectHandler(this._unitOfUnitMock.Object);

            var result = await handler.Handle(command, new CancellationTokenSource().Token);

            Assert.False((bool)result);
        }
        public void Should_AssignDefault_If_TypeOfProject_IsNotValid()
        {
            var expectedHandler = new CreateProjectHandler(mockUnitOfWork.Object);

            expectedHandler.Execute(fakeCommand);

            fakeProjectAggregate.ProjectType.Should().Be(TypeOfProject.None);
        }
        public async void handle_Exception_test()
        {
            Project project = new Project()
            {
                Id = 1
            };
            ProjectCategory     pc = new ProjectCategory();
            ProjectResearcher   pr = new ProjectResearcher();
            OrganisationProject op = new OrganisationProject();

            this._unitOfUnitMock.Setup(mock => mock.ProjectRepository.Create(It.IsAny <Project>())).Returns(project);
            this._unitOfUnitMock
            .Setup(mock => mock.RelationsRepository.CreateProjectCategory(It.IsAny <ProjectCategory>())).Returns(pc);
            this._unitOfUnitMock
            .Setup(mock => mock.RelationsRepository.CreateProjectResearcher(It.IsAny <ProjectResearcher>()))
            .Returns(pr);
            this._unitOfUnitMock.Setup(mock =>
                                       mock.RelationsRepository.CreateOrganisationProject(It.IsAny <OrganisationProject>())).Throws(new Exception());

            CreateProjectCommand command = new CreateProjectCommand(
                new CreateProjectModel()
            {
                ProjectName = "test",
                Categories  = new List <Category>()
                {
                    new Category()
                    {
                        CategoryId = 1, CategoryName = "test", Created = DateTime.Now, Id = 1
                    }
                },
                ResearcherCategories = new List <ResearcherCategory>()
                {
                    new ResearcherCategory()
                    {
                        Researcher = new Researcher()
                        {
                            Id = 1
                        }, Category = new Category()
                        {
                            Id = 1
                        }
                    }
                },
                Organisations = new List <Organisation>()
                {
                    new Organisation()
                    {
                        Id = 1,
                    }
                }
            });
            CreateProjectHandler handler = new CreateProjectHandler(this._unitOfUnitMock.Object);

            var result = await handler.Handle(command, new CancellationTokenSource().Token);

            Assert.Null(result);
        }
        public void Should_Retrieve_Donor()
        {
            var expectedHandler = new CreateProjectHandler(mockUnitOfWork.Object);

            expectedHandler.Execute(fakeCommand);

            mockRepository
            .Verify(x => x.Get <DonorAggregate>(), Times.Once());
        }
        public void Should_Return_ValidMessage_When_Succeed()
        {
            var expectedHandler = new CreateProjectHandler(mockUnitOfWork.Object);

            var result = expectedHandler.Execute(fakeCommand);

            result.Success.Should().BeTrue();
            result.Reason.Should().BeNullOrEmpty();
        }
        public void Should_AssignCorrect_If_TypeOfProject_IsValid()
        {
            var expectedHandler = new CreateProjectHandler(mockUnitOfWork.Object);

            fakeCommand = new CreateProjectCommand(fakeDonor.Id, fakeAnalyst.Id, "acronym", "TaPackage", "fake", DateTime.UtcNow);

            expectedHandler.Execute(fakeCommand);

            fakeProjectAggregate.ProjectType.Should().Be(TypeOfProject.TaPackage);
        }
        public void Should_AssignCorrect_If_TypeOfTender_IsValid()
        {
            var expectedHandler = new CreateProjectHandler(mockUnitOfWork.Object);

            fakeCommand = new CreateProjectCommand(fakeDonor.Id, fakeAnalyst.Id, "acronym", "fake", "NegotiatedProcedure", DateTime.UtcNow);

            expectedHandler.Execute(fakeCommand);

            fakeProjectAggregate.TenderProcessType.Should().Be(TypeOfTenderProcess.NegotiatedProcedure);
        }
        public void Should_Return_ValidMessage_When_Fails()
        {
            // throw exception
            mockUnitOfWork.Setup(x => x.CreateRepository())
            .Throws <NotImplementedException>();

            var expectedHandler = new CreateProjectHandler(mockUnitOfWork.Object);

            var result = expectedHandler.Execute(fakeCommand);

            result.Success.Should().BeFalse();
            result.Reason.Should().NotBeNullOrEmpty();
        }
        public async void handle_ProjectResutlNull_test()
        {
            Project projectnull = null;

            this._unitOfUnitMock.Setup(mock => mock.ProjectRepository.Create(It.IsAny <Project>())).Returns(projectnull);

            CreateProjectCommand command = new CreateProjectCommand(new CreateProjectModel()
            {
                ProjectName = "test"
            });
            CreateProjectHandler handler = new CreateProjectHandler(this._unitOfUnitMock.Object);

            var result = await handler.Handle(command, new CancellationTokenSource().Token);

            Assert.False((bool)result);
        }