public void TestConstructorSuccess() { string senderSource = "senderSource"; string receiverSource = "receiverSource"; int batchSize = 10; string resultType = "resultType1"; var mockSenderStore = new Mock <ISequentialStore <TestOperationResult> >(); IAsyncEnumerable <TestOperationResult> senderResults = new StoreTestResultCollection <TestOperationResult>(mockSenderStore.Object, batchSize); var mockReceiverStore = new Mock <ISequentialStore <TestOperationResult> >(); IAsyncEnumerable <TestOperationResult> receiverResults = new StoreTestResultCollection <TestOperationResult>(mockReceiverStore.Object, batchSize); var reportGenerator = new DirectMethodLongHaulReportGenerator( TestDescription, Guid.NewGuid().ToString(), senderSource, Topology.SingleNode, false, senderResults.GetAsyncEnumerator(), receiverSource, receiverResults.GetAsyncEnumerator(), resultType); Assert.Equal(TestDescription, reportGenerator.TestDescription); Assert.Equal(receiverSource, reportGenerator.ReceiverSource); Assert.Equal(senderResults.GetAsyncEnumerator(), reportGenerator.SenderTestResults); Assert.Equal(senderSource, reportGenerator.SenderSource); Assert.Equal(receiverResults.GetAsyncEnumerator(), reportGenerator.ReceiverTestResults); Assert.Equal(resultType, reportGenerator.ResultType); }
public async Task TestCreateReportAsyncWithEmptyResults() { string senderSource = "senderSource"; string receiverSource = "receiverSource"; int batchSize = 10; var mockSenderStore = new Mock <ISequentialStore <TestOperationResult> >(); IAsyncEnumerable <TestOperationResult> senderResults = new StoreTestResultCollection <TestOperationResult>(mockSenderStore.Object, batchSize); var mockReceiverStore = new Mock <ISequentialStore <TestOperationResult> >(); IAsyncEnumerable <TestOperationResult> receiverResults = new StoreTestResultCollection <TestOperationResult>(mockReceiverStore.Object, batchSize); var reportGenerator = new DirectMethodLongHaulReportGenerator( TestDescription, Guid.NewGuid().ToString(), senderSource, Topology.SingleNode, false, senderResults.GetAsyncEnumerator(), receiverSource, receiverResults.GetAsyncEnumerator(), "resultType1"); var report = (DirectMethodLongHaulReport)await reportGenerator.CreateReportAsync(); Assert.Equal(0L, report.ReceiverSuccesses); Assert.Equal(0L, report.SenderSuccesses); Assert.Equal(0L, report.StatusCodeZero); Assert.Equal(0L, report.Unauthorized); Assert.Equal(0L, report.DeviceNotFound); Assert.Equal(0L, report.TransientError); Assert.Equal(0L, report.ResourceError); Assert.Equal(0L, report.Other.Sum(x => x.Value)); Assert.True(report.IsPassed); }
public async Task TestOtherStatusCodeCounts() { var x = DirectMethodLongHaulReportData.GetStatusCodeTestData; IEnumerable <ulong> senderStoreValues = (IEnumerable <ulong>)x[0]; IEnumerable <ulong> receiverStoreValues = (IEnumerable <ulong>)x[1]; IEnumerable <HttpStatusCode> statusCodes = (IEnumerable <HttpStatusCode>)x[2]; IEnumerable <DateTime> timestamps = (IEnumerable <DateTime>)x[3]; int batchSize = (int)x[4]; bool expectedIsPassed = (bool)x[5]; long expectedOk = (long)x[6]; long expectedStatusCodeZero = (long)x[7]; long expectedStatusCodeNotFound = (long)x[8]; Dictionary <HttpStatusCode, long> expectedOtherDict = (Dictionary <HttpStatusCode, long>)x[9]; string senderSource = "senderSource"; string receiverSource = "receiverSource"; string resultType = TestOperationResultType.DirectMethod.ToString(); var mockSenderStore = new Mock <ISequentialStore <TestOperationResult> >(); IAsyncEnumerable <TestOperationResult> senderResults = new StoreTestResultCollection <TestOperationResult>(mockSenderStore.Object, batchSize); var mockReceiverStore = new Mock <ISequentialStore <TestOperationResult> >(); IAsyncEnumerable <TestOperationResult> receiverResults = new StoreTestResultCollection <TestOperationResult>(mockReceiverStore.Object, batchSize); var reportGenerator = new DirectMethodLongHaulReportGenerator( TestDescription, Guid.NewGuid().ToString(), senderSource, senderResults.GetAsyncEnumerator(), receiverSource, receiverResults.GetAsyncEnumerator(), resultType); Guid guid = Guid.NewGuid(); List <(long, TestOperationResult)> senderStoreData = GetSenderStoreData(senderSource, resultType, senderStoreValues, statusCodes, timestamps, guid); for (int i = 0; i < senderStoreData.Count; i += batchSize) { int startingOffset = i; mockSenderStore.Setup(s => s.GetBatch(startingOffset, batchSize)).ReturnsAsync(senderStoreData.Skip(startingOffset).Take(batchSize)); } List <(long, TestOperationResult)> receiverStoreData = GetReceiverStoreData(receiverSource, resultType, receiverStoreValues, timestamps, guid); for (int j = 0; j < receiverStoreData.Count; j += batchSize) { int startingOffset = j; mockReceiverStore.Setup(s => s.GetBatch(startingOffset, batchSize)).ReturnsAsync(receiverStoreData.Skip(startingOffset).Take(batchSize)); } var report = (DirectMethodLongHaulReport)await reportGenerator.CreateReportAsync(); Assert.Equal(expectedIsPassed, report.IsPassed); Assert.Equal(expectedOk, report.SenderSuccesses); Assert.Equal(expectedStatusCodeZero, report.StatusCodeZero); Assert.Equal(expectedStatusCodeNotFound, report.DeviceNotFound); Assert.Equal(expectedOtherDict.Sum(x => x.Value), report.Other.Sum(x => x.Value)); Assert.Equal(expectedOtherDict[HttpStatusCode.ServiceUnavailable], report.Other[HttpStatusCode.ServiceUnavailable]); Assert.Equal(expectedOtherDict[HttpStatusCode.InternalServerError], report.Other[HttpStatusCode.InternalServerError]); }
public async Task TestCreateReportAsync( IEnumerable <ulong> senderStoreValues, IEnumerable <ulong> receiverStoreValues, IEnumerable <HttpStatusCode> statusCodes, IEnumerable <DateTime> timestamps, int batchSize, bool expectedIsPassed, long expectedOk, long expectedStatusCodeZero, long expectedDeviceNotFound, long expectedTransientError, long expectedResourceError, long expectedOther) { string senderSource = "senderSource"; string receiverSource = "receiverSource"; string resultType = TestOperationResultType.DirectMethod.ToString(); var mockSenderStore = new Mock <ISequentialStore <TestOperationResult> >(); IAsyncEnumerable <TestOperationResult> senderResults = new StoreTestResultCollection <TestOperationResult>(mockSenderStore.Object, batchSize); var mockReceiverStore = new Mock <ISequentialStore <TestOperationResult> >(); IAsyncEnumerable <TestOperationResult> receiverResults = new StoreTestResultCollection <TestOperationResult>(mockReceiverStore.Object, batchSize); var reportGenerator = new DirectMethodLongHaulReportGenerator( TestDescription, Guid.NewGuid().ToString(), senderSource, senderResults.GetAsyncEnumerator(), receiverSource, receiverResults.GetAsyncEnumerator(), resultType); Guid guid = Guid.NewGuid(); List <(long, TestOperationResult)> senderStoreData = GetSenderStoreData(senderSource, resultType, senderStoreValues, statusCodes, timestamps, guid); for (int i = 0; i < senderStoreData.Count; i += batchSize) { int startingOffset = i; mockSenderStore.Setup(s => s.GetBatch(startingOffset, batchSize)).ReturnsAsync(senderStoreData.Skip(startingOffset).Take(batchSize)); } List <(long, TestOperationResult)> receiverStoreData = GetReceiverStoreData(receiverSource, resultType, receiverStoreValues, timestamps, guid); for (int j = 0; j < receiverStoreData.Count; j += batchSize) { int startingOffset = j; mockReceiverStore.Setup(s => s.GetBatch(startingOffset, batchSize)).ReturnsAsync(receiverStoreData.Skip(startingOffset).Take(batchSize)); } var report = (DirectMethodLongHaulReport)await reportGenerator.CreateReportAsync(); Assert.Equal(expectedIsPassed, report.IsPassed); Assert.Equal(expectedOk, report.SenderSuccesses); Assert.Equal(expectedStatusCodeZero, report.StatusCodeZero); Assert.Equal(expectedDeviceNotFound, report.DeviceNotFound); Assert.Equal(expectedTransientError, report.TransientError); Assert.Equal(expectedResourceError, report.ResourceError); Assert.Equal(expectedOther, report.Other.Sum(x => x.Value)); }
public async Task TestCreateReportAsyncWithEmptyResults() { string senderSource = "senderSource"; string receiverSource = "receiverSource"; int batchSize = 10; var mockSenderStore = new Mock <ISequentialStore <TestOperationResult> >(); var senderResults = new StoreTestResultCollection <TestOperationResult>(mockSenderStore.Object, batchSize); var mockReceiverStore = new Mock <ISequentialStore <TestOperationResult> >(); var receiverResults = Option.Some <ITestResultCollection <TestOperationResult> >( new StoreTestResultCollection <TestOperationResult>(mockReceiverStore.Object, batchSize)); var reportGenerator = new DirectMethodLongHaulReportGenerator( TestDescription, Guid.NewGuid().ToString(), senderSource, senderResults, Option.Some(receiverSource), receiverResults, "resultType1"); var report = (DirectMethodLongHaulReport)await reportGenerator.CreateReportAsync(); Assert.Equal(0UL, report.ReceiverSuccesses.Expect <ArgumentException>(() => throw new ArgumentException("impossible"))); Assert.Equal(0UL, report.SenderSuccesses); Assert.Equal(0UL, report.StatusCodeZero); Assert.Equal(0UL, report.Unknown); Assert.True(report.IsPassed); }
public void TestConstructorSuccess() { string senderSource = "senderSource"; Option <string> receiverSource = Option.Some("receiverSource"); int batchSize = 10; string resultType = "resultType1"; var mockSenderStore = new Mock <ISequentialStore <TestOperationResult> >(); var senderResults = new StoreTestResultCollection <TestOperationResult>(mockSenderStore.Object, batchSize); var mockReceiverStore = new Mock <ISequentialStore <TestOperationResult> >(); var receiverResults = Option.Some <ITestResultCollection <TestOperationResult> >( new StoreTestResultCollection <TestOperationResult>(mockReceiverStore.Object, batchSize)); var reportGenerator = new DirectMethodLongHaulReportGenerator( TestDescription, Guid.NewGuid().ToString(), senderSource, senderResults, receiverSource, receiverResults, resultType); Assert.Equal(TestDescription, reportGenerator.TestDescription); Assert.Equal(receiverSource, reportGenerator.ReceiverSource); Assert.Equal(senderResults, reportGenerator.SenderTestResults); Assert.Equal(senderSource, reportGenerator.SenderSource); Assert.Equal(receiverResults, reportGenerator.ReceiverTestResults); Assert.Equal(resultType, reportGenerator.ResultType); }
public async Task TestCreateReportWithSenderResultsOnlyAsync( IEnumerable <ulong> senderStoreValues, IEnumerable <ulong> receiverStoreValues, IEnumerable <HttpStatusCode> statusCodes, IEnumerable <DateTime> timestamps, int batchSize, bool expectedIsPassed, ulong expectedOk, ulong expectedStatusCodeZero, ulong expectedUnknown) { string senderSource = "senderSource"; var values = receiverStoreValues; string resultType = TestOperationResultType.DirectMethod.ToString(); var mockSenderStore = new Mock <ISequentialStore <TestOperationResult> >(); var senderResults = new StoreTestResultCollection <TestOperationResult>(mockSenderStore.Object, batchSize); var receiverResults = Option.None <ITestResultCollection <TestOperationResult> >(); var reportGenerator = new DirectMethodLongHaulReportGenerator( TestDescription, Guid.NewGuid().ToString(), senderSource, senderResults, Option.None <string>(), receiverResults, resultType); var senderStoreData = GetSenderStoreData(senderSource, resultType, senderStoreValues, statusCodes, timestamps, Guid.NewGuid()); for (int i = 0; i < senderStoreData.Count; i += batchSize) { int startingOffset = i; mockSenderStore.Setup(s => s.GetBatch(startingOffset, batchSize)).ReturnsAsync(senderStoreData.Skip(startingOffset).Take(batchSize)); } var report = (DirectMethodLongHaulReport)await reportGenerator.CreateReportAsync(); Assert.Equal(expectedIsPassed, report.IsPassed); Assert.Equal(expectedOk, report.SenderSuccesses); Assert.Equal(expectedStatusCodeZero, report.StatusCodeZero); Assert.Equal(expectedUnknown, report.Unknown); }