protected async override Task <HttpResponseMessage> SendAsync( HttpRequestMessage request, CancellationToken cancellationToken) { string content = request.Content == null ? null : await request.Content.ReadAsStringAsync().ConfigureAwait(false); RequestContents.Add(content); if (OnSendingRequest != null) { Requests.Add(await OnSendingRequest(request).ConfigureAwait(false)); } else { Requests.Add(request); } if (_responseIndex < Responses.Count) { return(Responses[_responseIndex++]); } return(_nullResponse); }
public async Task GetEmployeeInfo_Error_No_Data_Test() { //Arrange var(service, logger, mockFactory, mockHttpMessageHandler, config, sqlApi) = getService(ResponseContents.GetEmployeeInfoErrorNoDataResponse()); var ex = await Assert.ThrowsAsync <ArgumentException>(async() => await service.GetEmployeeInfo(CompanyEnum.Austria, 1234)); mockHttpMessageHandler.Protected().Verify( "SendAsync", Times.Exactly(1), ItExpr.Is <HttpRequestMessage>(req => req.CheckRequest(config.Endpoint, RequestContents.GetEmployeeInfoRequestContent(1, 1234))), ItExpr.IsAny <CancellationToken>()); }
public async Task GetEmployeeInfoTest() { //Arrange var(service, logger, mockFactory, mockHttpMessageHandler, config, sqlApi) = getService(ResponseContents.GetEmployeeInfoResponse()); var info = await service.GetEmployeeInfo(1, 5555); info.Should().BeOfType <EmployeeInfo>(); info.FirstName.Should().Be("Michael"); info.LastName.Should().Be("Prattinger"); info.ManagerDisciplinary.Should().Be(5022); info.ManagerProfessional.Should().Be(5022); info.EntryDate.Should().Be(new System.DateTime(2018, 4, 3)); mockHttpMessageHandler.Protected().Verify( "SendAsync", Times.Exactly(1), ItExpr.Is <HttpRequestMessage>(req => req.CheckRequest(config.Endpoint, RequestContents.GetEmployeeInfoRequestContent(1, 5555))), ItExpr.IsAny <CancellationToken>()); }
public async Task GetEmployeeCheckIns_Error_Wrong_Employee_Test() { var(service, logger, mockFactory, mockHttpMessageHandler, config, sqlApi) = getService(ResponseContents.GetEmployeeCheckInsErrorWrongEmployeeResponse()); var ex = await Assert.ThrowsAsync <ArgumentException>(async() => await service.GetEmployeeCheckIns(1, 1234, new DateTime(2020, 11, 5))); mockHttpMessageHandler.Protected().Verify( "SendAsync", Times.Exactly(1), ItExpr.Is <HttpRequestMessage>(req => req.CheckRequest(config.Endpoint, RequestContents.GetEmployeeCheckInsRequestContent(1, 1234, "5112020"))), ItExpr.IsAny <CancellationToken>()); }
public async Task GetEmployeeCheckInsTest() { var(service, logger, mockFactory, mockHttpMessageHandler, config, sqlApi) = getService(ResponseContents.GetEmployeeCheckInsResponse()); var list = await service.GetEmployeeCheckIns(1, 5555, new DateTime(2020, 11, 5)); list.Count.Should().Be(6); list.First().CheckinTime.Should().Be(new DateTime(2020, 11, 5, 6, 30, 0)); list.First().Type.Should().Be(PresenceType.AN); list[2].CheckinTime.Should().Be(new DateTime(2020, 11, 5, 7, 41, 0)); list[2].Type.Should().Be(PresenceType.AN); list.Last().CheckinTime.Should().Be(new DateTime(2020, 11, 5, 16, 0, 0)); list.Last().Type.Should().Be(PresenceType.AB); mockHttpMessageHandler.Protected().Verify( "SendAsync", Times.Exactly(1), ItExpr.Is <HttpRequestMessage>(req => req.CheckRequest(config.Endpoint, RequestContents.GetEmployeeCheckInsRequestContent(1, 5555, "5112020"))), ItExpr.IsAny <CancellationToken>()); }
public async Task GetEmployeePresenceStatus_Error_Wrong_Company_Test() { var(service, logger, mockFactory, mockHttpMessageHandler, config, sqlApi) = getService(ResponseContents.GetEmployeePresenceStatusErrorCompanyResponse()); var ex = await Assert.ThrowsAsync <ArgumentException>(async() => await service.GetEmployeePresenceStatus(789, 5555)); mockHttpMessageHandler.Protected().Verify( "SendAsync", Times.Exactly(1), ItExpr.Is <HttpRequestMessage>(req => req.CheckRequest(config.Endpoint, RequestContents.GetEmployeePresenceStatusRequestContent(789, 5555))), ItExpr.IsAny <CancellationToken>()); }
public async Task GetEmployeePresenceStatusTest() { //Arrange var(service, logger, mockFactory, mockHttpMessageHandler, config, sqlApi) = getService(ResponseContents.GetEmployeePresenceStatusResponse()); var status = await service.GetEmployeePresenceStatus(1, 5555); status.Should().BeOfType <EmployeePresenceStatus>(); status.EmployeeId.Should().Be(5555); status.CurrentDate.Should().Be(new DateTime(2020, 11, 11)); status.Type.Should().Be(PresenceType.AB); mockHttpMessageHandler.Protected().Verify( "SendAsync", Times.Exactly(1), ItExpr.Is <HttpRequestMessage>(req => req.CheckRequest(config.Endpoint, RequestContents.GetEmployeePresenceStatusRequestContent(1, 5555))), ItExpr.IsAny <CancellationToken>()); }
public async Task GetEmployeeTimeDetails_Error_NoData_Test() { //Arrange var(service, logger, mockFactory, mockHttpMessageHandler, config, sqlApi) = getService(ResponseContents.GetEmployeeTimeDetailsErrorNoDataResponse()); var ex = await Assert.ThrowsAsync <ArgumentException>(async() => await service.GetEmployeeTimeDetails(1, 5555, new DateTime(2015, 10, 1), new DateTime(2015, 10, 30))); mockHttpMessageHandler.Protected().Verify( "SendAsync", Times.Exactly(1), ItExpr.Is <HttpRequestMessage>(req => req.CheckRequest(config.Endpoint, RequestContents.GetEmployeeTimeDetailsRequestContent(1, 5555, "1102015", "30102015"))), ItExpr.IsAny <CancellationToken>()); }
public async Task GetEmployeeTimeDetailsTest() { //Arrange var(service, logger, mockFactory, mockHttpMessageHandler, config, sqlApi) = getService(ResponseContents.GetEmployeeTimeDetailsResponse()); var list = await service.GetEmployeeTimeDetails(1, 5555, new DateTime(2020, 10, 1), new DateTime(2020, 10, 30)); list.Should().BeOfType <List <EmployeeTimeDetail> >(); list.Count.Should().Be(30); list.First().GrossWorktime.Should().Be(TimeSpan.FromMinutes(519)); list.First().TargetWorktime.Should().Be(TimeSpan.FromMinutes(492)); list.First().NetWorktime.Should().Be(TimeSpan.FromMinutes(519)); list.First().NetWorktimeDifference.Should().Be(TimeSpan.FromMinutes(27)); list.Last().GrossWorktime.Should().Be(TimeSpan.FromMinutes(362)); list.Last().TargetWorktime.Should().Be(TimeSpan.FromMinutes(342)); list.Last().NetWorktime.Should().Be(TimeSpan.FromMinutes(362)); list.Last().NetWorktimeDifference.Should().Be(TimeSpan.FromMinutes(20)); mockHttpMessageHandler.Protected().Verify( "SendAsync", Times.Exactly(1), ItExpr.Is <HttpRequestMessage>(req => req.CheckRequest(config.Endpoint, RequestContents.GetEmployeeTimeDetailsRequestContent(1, 5555, "1102020", "30102020"))), ItExpr.IsAny <CancellationToken>()); }
public async Task GetEmployeeListTest() { //Arrange var(service, logger, mockFactory, mockHttpMessageHandler, config, sqlApi) = getService(ResponseContents.GetEmployeeListResponse()); var list = await service.GetEmployeeList(1); list.Should().BeOfType <List <EmployeeBaseInfo> >(); list.Count.Should().Be(4); list.First().FirstName.Should().Be("Martin"); list.First().LastName.Should().Be("Auer"); list.First().EmployeeId.Should().Be(5120); list.Last().FirstName.Should().Be("Manfred"); list.Last().LastName.Should().Be("Augustin"); list.Last().EmployeeId.Should().Be(1425); mockHttpMessageHandler.Protected().Verify( "SendAsync", Times.Exactly(1), ItExpr.Is <HttpRequestMessage>(req => req.CheckRequest(config.Endpoint, RequestContents.GetEmployeeListRequestContent(1))), ItExpr.IsAny <CancellationToken>()); }