public async Task And_Exception_Then_Returns_Bad_Request(
            long cohortId,
            [Frozen] Mock <IMediator> mockMediator,
            [Greedy] CohortsController controller)
        {
            mockMediator
            .Setup(mediator => mediator.Send(
                       It.IsAny <GetCohortQuery>(),
                       It.IsAny <CancellationToken>()))
            .Throws <InvalidOperationException>();

            var controllerResult = await controller.Get(cohortId) as BadRequestResult;

            controllerResult.StatusCode.Should().Be((int)HttpStatusCode.BadRequest);
        }
        public async Task Then_Returns_Not_Found_If_No_Cohort(
            long cohortId,
            [Frozen] Mock <IMediator> mockMediator,
            [Greedy] CohortsController controller)
        {
            mockMediator
            .Setup(mediator => mediator.Send(
                       It.Is <GetCohortQuery>(query => query.CohortId == cohortId),
                       It.IsAny <CancellationToken>()))
            .ReturnsAsync(new GetCohortResult {
                Cohort = null
            });

            var controllerResult = await controller.Get(cohortId) as NotFoundResult;

            Assert.IsNotNull(controllerResult);
            controllerResult.StatusCode.Should().Be((int)HttpStatusCode.NotFound);
        }
        public async Task Then_Gets_Cohort_From_Mediator(
            long cohortId,
            GetCohortResult mediatorResult,
            [Frozen] Mock <IMediator> mockMediator,
            [Greedy] CohortsController controller)
        {
            mockMediator
            .Setup(mediator => mediator.Send(
                       It.Is <GetCohortQuery>(query => query.CohortId == cohortId),
                       It.IsAny <CancellationToken>()))
            .ReturnsAsync(mediatorResult);

            var controllerResult = await controller.Get(cohortId) as ObjectResult;

            Assert.IsNotNull(controllerResult);
            controllerResult.StatusCode.Should().Be((int)HttpStatusCode.OK);
            var model = controllerResult.Value as GetCohortResponse;

            Assert.IsNotNull(model);
            model.Should().BeEquivalentTo(mediatorResult.Cohort);
        }
Ejemplo n.º 4
0
        public void Setup()
        {
            evals = new List <Evaluation>
            {
                new Evaluation
                {
                    EvaluationID  = 0,
                    OpenDate      = DateTime.Today.AddDays(-10),
                    CloseDate     = DateTime.Today.AddDays(10),
                    SelfAnswers   = "123123",
                    CompletedDate = DateTime.Today.AddDays(-10),
                    Raters        = new List <Rater>()
                },
                new Evaluation
                {
                    EvaluationID  = 1,
                    OpenDate      = DateTime.Today.AddDays(-10),
                    CloseDate     = DateTime.Today.AddDays(10),
                    SelfAnswers   = null,
                    CompletedDate = null,
                    Raters        = new List <Rater>()
                }
            };

            employees = new List <Employee>
            {
                new Employee
                {
                    EmployeeID  = 0,
                    FirstName   = "Dwight",
                    LastName    = "Schrute",
                    CohortID    = 0,
                    Evaluations = evals
                },
                new Employee
                {
                    EmployeeID  = 1,
                    FirstName   = "Angela",
                    LastName    = "Martin",
                    CohortID    = 0,
                    Evaluations = new List <Evaluation>()
                },
                new Employee
                {
                    EmployeeID  = 2,
                    FirstName   = "Andrew",
                    LastName    = "Bernard",
                    CohortID    = 0,
                    Evaluations = new List <Evaluation>()
                }
            };

            cohorts = new List <Cohort>
            {
                new Cohort
                {
                    CohortID      = 0,
                    Name          = "Sales",
                    Type1Assigned = false,
                    Type2Assigned = false,
                    Employees     = employees
                },
                new Cohort
                {
                    CohortID      = 1,
                    Name          = "Accounting",
                    Type1Assigned = false,
                    Type2Assigned = false
                },
                new Cohort
                {
                    CohortID      = 2,
                    Name          = "Human Resources",
                    Type1Assigned = false,
                    Type2Assigned = false
                }
            };

            mockUnitOfWork        = new Mock <IUnitOfWork>();
            controller            = new CohortsController();
            controller.UnitOfWork = mockUnitOfWork.Object;
            mockUnitOfWork.Setup(
                m => m.CohortRepository.Get(null, null, "")).Returns(
                cohorts);
            foreach (var cohort in cohorts)
            {
                mockUnitOfWork.Object.CohortRepository.Insert(cohort);
            }
        }