Пример #1
0
        public async Task ReturnsJobsIfFound()
        {
            var fixture      = new Fixture();
            var testShift    = fixture.Create <Shift>();
            var expectedJobs = testShift.Jobs.Select(j => new JobSummary
            {
                Age            = j.Age,
                Category       = j.Category,
                Gender         = j.Gender,
                ReflectionFlag = j.ReflectionFlag
            });

            var shiftServiceMock = new Mock <IShiftService>(MockBehavior.Strict);

            shiftServiceMock.Setup(s => s.GetShift(AuthenticationHelperMock.GoodUserId, testShift.Id)).Returns(Task.FromResult <Shift>(testShift));
            var shiftService = shiftServiceMock.Object;

            var function = new GetJobs(shiftService, AuthenticationHelperMock.GetAuthenticationHelper());

            var request = new DefaultHttpRequest(new DefaultHttpContext());

            request.Headers.Add("Authorization", AuthenticationHelperMock.GoodHeader);
            request.QueryString = new QueryString($"?shiftId={testShift.Id}");

            var result = await function.Run(request, NullLogger.Instance);

            result.Should().BeOfType <OkObjectResult>()
            .Which.Value.Should().BeEquivalentTo(expectedJobs);
        }
Пример #2
0
        public async Task ReturnsEmptyListIfNoJobs()
        {
            var fixture   = new Fixture();
            var testShift = fixture.Create <Shift>();

            testShift.Jobs.Clear();
            var expectedJobs = Enumerable.Empty <JobSummary>();

            var shiftServiceMock = new Mock <IShiftService>(MockBehavior.Strict);

            shiftServiceMock.Setup(s => s.GetShift(AuthenticationHelperMock.GoodUserId, testShift.Id)).Returns(Task.FromResult(testShift));
            var shiftService = shiftServiceMock.Object;

            var function = new GetJobs(shiftService, AuthenticationHelperMock.GetAuthenticationHelper());

            var request = new DefaultHttpRequest(new DefaultHttpContext());

            request.Headers.Add("Authorization", AuthenticationHelperMock.GoodHeader);
            request.QueryString = new QueryString($"?shiftId={testShift.Id}");

            var result = await function.Run(request, NullLogger.Instance);

            result.Should().BeOfType <OkObjectResult>()
            .Which.Value.Should().BeEquivalentTo(expectedJobs);
        }
Пример #3
0
        public async Task ReturnsUnauthorisedWithNoClaims()
        {
            var shiftService = new Mock <IShiftService>(MockBehavior.Strict).Object;

            var function = new GetJobs(shiftService, AuthenticationHelperMock.GetAuthenticationHelper());

            var request = new DefaultHttpRequest(new DefaultHttpContext());

            var result = await function.Run(request, NullLogger.Instance);

            result.Should().BeOfType <UnauthorizedResult>();
        }
Пример #4
0
        public async Task ReturnsBadRequestIfNoShiftId()
        {
            var shiftService = new Mock <IShiftService>(MockBehavior.Strict).Object;

            var function = new GetJobs(shiftService, AuthenticationHelperMock.GetAuthenticationHelper());

            var request = new DefaultHttpRequest(new DefaultHttpContext());

            request.Headers.Add("Authorization", AuthenticationHelperMock.GoodHeader);

            var result = await function.Run(request, NullLogger.Instance);

            result.Should().BeOfType <BadRequestResult>();
        }
Пример #5
0
        public async Task ReturnsNotFoundRequestIfNoShift()
        {
            var fixture   = new Fixture();
            var testShift = fixture.Create <Shift>();

            var shiftServiceMock = new Mock <IShiftService>(MockBehavior.Strict);

            shiftServiceMock.Setup(s => s.GetShift(AuthenticationHelperMock.GoodUserId, testShift.Id)).Returns(Task.FromResult <Shift>(null));
            var shiftService = shiftServiceMock.Object;

            var function = new GetJobs(shiftService, AuthenticationHelperMock.GetAuthenticationHelper());

            var request = new DefaultHttpRequest(new DefaultHttpContext());

            request.Headers.Add("Authorization", AuthenticationHelperMock.GoodHeader);
            request.QueryString = new QueryString($"?shiftId={testShift.Id}");

            var result = await function.Run(request, NullLogger.Instance);

            result.Should().BeOfType <NotFoundResult>();
        }