static void Main(string[] args) { Server server = null; try { server = new Server() { Services = { GreetingService.BindService(new GreetingServiceImpl()), SumService.BindService(new SumServiceImpl()), PrimeNumberService.BindService(new PrimeNumberServiceImpl()), ComputeAverageService.BindService(new ComputeAverageServiceImpl()), FindMaximumService.BindService(new FindMaximumServiceImpl()) }, Ports = { new ServerPort("localhost", Port, ServerCredentials.Insecure) } }; server.Start(); Console.WriteLine("The server is listening on the port: " + Port); Console.ReadKey(); } catch (IOException e) { Console.WriteLine("The server failed to start: " + e.Message); throw; } finally { if (server != null) { server.ShutdownAsync().Wait(); } } }
public async Task GetNextPrimeNumberAsync_number_in_range_should_return_next_number(int testValue, int nextPrimeNumber) { var service = new PrimeNumberService(mockLogger.Object); var result = await service.GetNextPrimeNumberAsync(testValue); Assert.AreEqual(result, nextPrimeNumber); }
public void ShouldThrowExceptionIfNumberIsSmallerThen1() { var service = new PrimeNumberService(); Assert.Throws <InvalidOperationException>(() => service.IsPrimeNumer(-1)); Assert.Throws <InvalidOperationException>(() => service.IsPrimeNumer(0)); }
public void GetNextPrimeNumberAsync_search_overflows_should_should_throw_exception(int value) { var service = new PrimeNumberService(mockLogger.Object); var exception = Assert.ThrowsAsync <ArgumentOutOfRangeException>(() => service.GetNextPrimeNumberAsync(value)); Assert.AreEqual(exception.Message, "Specified argument was out of the range of valid values. (Parameter 'Prime number')"); }
public void ShouldReturnsFalseForNumberThatIsNotPrime() { var service = new PrimeNumberService(); Assert.True(service.IsPrimeNumer(4)); Assert.True(service.IsPrimeNumer(16)); Assert.True(service.IsPrimeNumer(22)); }
public void ShouldReturnsTrueForPrimeNumber() { var service = new PrimeNumberService(); Assert.True(service.IsPrimeNumer(2)); Assert.True(service.IsPrimeNumer(3)); Assert.True(service.IsPrimeNumer(7)); }
public ActionResult <int> NextPrime(int number) { var result = PrimeNumberService.NextPrime(number); return(result.HasErrors switch { true => BadRequest(result.Errors), false => Ok(result.Value) });
public void FindPrimeNumbersTest() { // Arrange var pns = new PrimeNumberService(100); // Act var fndPrimes = pns.FindPrimeNumbers(2); // Assert Assert.IsTrue(fndPrimes.Count == 100); }
public void IsPrimeNumberAsync_number_is_prime_should_return_true(int[] values) { var service = new PrimeNumberService(mockLogger.Object); values.ToList().ForEach(value => { var result = service.IsPrimeNumberAsync(value).GetAwaiter().GetResult(); Assert.IsTrue(result); }); }
public void IsPrimeNumberAsync_number_is_below_or_equel_one_should_throw_exception(int[] values) { var service = new PrimeNumberService(mockLogger.Object); values.ToList().ForEach(value => { var exception = Assert.ThrowsAsync <ArgumentOutOfRangeException>(() => service.IsPrimeNumberAsync(value)); Assert.AreEqual(exception.Message, "Specified argument was out of the range of valid values. (Parameter 'Prime number')"); }); }
public void GetNextPrimeNumberAsync_number_below_one_range_should_return_two(int[] values) { var service = new PrimeNumberService(mockLogger.Object); values.ToList().ForEach(value => { var result = service.GetNextPrimeNumberAsync(value).GetAwaiter().GetResult(); Assert.AreEqual(result, 2); }); }
public void PrimeNumberServiceTest() { { // Arrange var pns = new PrimeNumberService(100); // Act var rc = pns == null; // Assert Assert.IsFalse(rc); } }
public void CheckPrimaltyProperty() { var rand = new Random(DateTime.Now.Millisecond); for (int i = 0; i < 100; i++) { var number = rand.Next(-100, 100); Assert.IsTrue(PrimeProperty(number) == PrimeNumberService.IsPrime(number)); } }
public void PrimeNumberService_GetPrimeNumbers() { //arrange var moqPrimeNumberService = new PrimeNumberService(); int?number = 3; var expectedResult = new int[] { 3, 2 }; //act var sut = moqPrimeNumberService.GetPrimeNumbers(3); //assert Assert.AreEqual(expectedResult, sut); }
public void TestPrimesFoundReturnsNumbersFoundToBePrime() { // arrange const int knownPrime = 7; // act var serviceUnderTest = new PrimeNumberService(); serviceUnderTest.IsPrimeNumber(knownPrime); // assert Assert.IsTrue(serviceUnderTest.PrimesFound.Contains(knownPrime)); }
public void TestIsPrimeNumberMethodShouldReturnFalseForNonPrimeNumber() { // arrange const int knownNonPrime = 8; const bool expected = false; // act var serviceUnderTest = new PrimeNumberService(); var actual = serviceUnderTest.IsPrimeNumber(knownNonPrime); // assert Assert.AreEqual(expected, actual, "The non prime number should return false."); }
public void TestIsPrimeMethodNumberMethodShouldReturnTrueForPrimeNumber() { // arrange const int knownPrime = 7; const bool expected = true; // act var serviceUnderTest = new PrimeNumberService(); var actual = serviceUnderTest.IsPrimeNumber(knownPrime); // assert Assert.AreEqual(expected, actual, "The prime number should return true."); }
public void TestResetEmptiesPrimesFoundList() { // arrange const int knownPrime = 7; // act var serviceUnderTest = new PrimeNumberService(); serviceUnderTest.IsPrimeNumber(knownPrime); serviceUnderTest.Reset(); // assert Assert.IsFalse(serviceUnderTest.PrimesFound.Any()); }
private void ExecuteProcessNumberSieveCommand() { // reset display LoadNumbers(); // disable process button DispatchService.Invoke(() => IsNotBusy = false); // perform sieve in background thread DispatchService.Background(() => { const int interval = 100; var max = _numbers.Count + 1; for (var i = 2; i <= max; i++) { // delay System.Threading.Thread.Sleep(interval); // adjust for collection starting at 2 var index = i - 2; var number = i; // See if i is prime. if (!PrimeNumberService.IsPrimeNumber(number)) { continue; } // mark as prime _numbers[index].IsPrime = true; _numbers[index].DisplayColor = ColorService.PrimeColor; // Knock out multiples of number var backgroundColor = ColorService.GetNextColor(); for (var j = number * number; j <= max; j += number) { _numbers[j - 2].IsPrime = false; _numbers[j - 2].Model.DisplayColor = backgroundColor; // delay System.Threading.Thread.Sleep(interval); } } // re-enable button DispatchService.Invoke(() => IsNotBusy = true); }); }
public void PrimeNumberService_GetPrimeNumbers_Throw_ArgumentNullException() { //arrange var moqPrimeNumberService = new PrimeNumberService(); int?number = null; var expectedResult = new ArgumentNullException(); //act var sut = Assert.Throws <ArgumentNullException>( () => moqPrimeNumberService.GetPrimeNumbers(null), "should throw ArgumentNullException"); //assert Assert.AreEqual(expectedResult.InnerException, sut.InnerException); }
public void PrimeNumberService_GetPrimeNumbers_Throw_ArgumentOutOfRangeException() { //arrange var moqPrimeNumberService = new PrimeNumberService(); var number = 1; var expectedException = new ArgumentOutOfRangeException(); //act var sut = Assert.Throws <ArgumentOutOfRangeException>( () => moqPrimeNumberService.GetPrimeNumbers(1), "Should throw ArgumentOutOfRangeException"); //assert Assert.AreEqual(expectedException.InnerException, sut.InnerException); }
public void ComparePrimalNumbersFromZeroToHundredWithTheFilteredFromTheMethodNumbers() { //Arrange int[] primalNumbersTo100 = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97 }; List <int> primalNumbersFromMethod = new List <int>(); //Act for (int i = 0; i < 100; i++) { if (PrimeNumberService.IsPrime(i)) { primalNumbersFromMethod.Add(i); } } //Assert Assert.IsTrue(primalNumbersTo100.Length == primalNumbersFromMethod.Count); for (int i = 0; i < primalNumbersTo100.Length; i++) { Assert.IsTrue(primalNumbersTo100[i] == primalNumbersFromMethod[i]); } }
public PrimeNumberServiceTests() { this.primeNumberService = new PrimeNumberService(); }
public void Setup() { service = new PrimeNumberService(); }