예제 #1
0
        public async Task ReturnsBadRequestWithInvalidEvent()
        {
            var fixture = new Fixture();

            var testShift = fixture.Build <NewShift>()
                            .With(j => j.Duration, TimeSpan.FromHours(2))
                            .With(j => j.Event, string.Empty)
                            .Create();

            var body       = JsonConvert.SerializeObject(testShift);
            var bodyArray  = Encoding.UTF8.GetBytes(body);
            var bodyStream = new MemoryStream(bodyArray);

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

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

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

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

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

            result.Should().BeOfType <BadRequestResult>();
        }
예제 #2
0
        public async Task ReturnsOkIfValidRequest()
        {
            var fixture = new Fixture();

            var testId    = fixture.Create <string>();
            var testShift = fixture.Build <NewShift>()
                            .With(j => j.Duration, TimeSpan.FromHours(2))
                            .Create();

            var body       = JsonConvert.SerializeObject(testShift);
            var bodyArray  = Encoding.UTF8.GetBytes(body);
            var bodyStream = new MemoryStream(bodyArray);

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

            shiftServiceMock.Setup(s => s.AddShift(AuthenticationHelperMock.GoodUserId, It.Is <NewShift>(j => j.Equals(testShift)))).ReturnsAsync(testId);
            var shiftService = shiftServiceMock.Object;

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

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

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

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

            result.Should().BeOfType <OkResult>();

            shiftServiceMock.Verify(s => s.AddShift(AuthenticationHelperMock.GoodUserId, It.Is <NewShift>(j => j.Equals(testShift))));
        }
예제 #3
0
        public async Task ReturnsUnauthorisedWithNoClaims()
        {
            var shiftService = new Mock <IShiftService>(MockBehavior.Strict).Object;

            var function = new LogShift(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 ReturnsBadRequestWithInvalidJson()
        {
            var body       = JsonConvert.SerializeObject("{ invalidjson }");
            var bodyArray  = Encoding.UTF8.GetBytes(body);
            var bodyStream = new MemoryStream(bodyArray);

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

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

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

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

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

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