/// <inheritdoc /> /// <inheritdoc /> public async Task <ResponseBase> CreateUser(string email, string pass, string displayName, string phone) { var request = new RegisterRequest(); request.DisplayName = displayName; request.Password = pass; request.Email = email; request.Phone = phone; request.DeviceId = "DeviceMobile" + PinGenerator.GeneratePin(); var responseData = new ResponseBase() { HasBeenSuccessful = false }; var result = await this._apiWrapper.CreateUser(request); string content = await result.Content.ReadAsStringAsync(); if (result.StatusCode == HttpStatusCode.OK) { try { var deserializedContent = JsonConvert.DeserializeObject <ResponseBase>(content); if (!deserializedContent.HasBeenSuccessful) { responseData.HasBeenSuccessful = false; responseData.Error = "Internal Server Error"; return(responseData); } responseData.HasBeenSuccessful = true; responseData.Error = null; return(responseData); } catch (Exception e) { Console.WriteLine(e.StackTrace); responseData.HasBeenSuccessful = false; responseData.Error = "Deserialization Error"; return(responseData); } } else { responseData.HasBeenSuccessful = false; responseData.Error = "Internal Error" + result.StatusCode.ToString();; return(responseData); } }
public void GeneratePinTest() { // arrange int nrOfPinsToGenerate = 1000; int nrOfDigits = 4; // act IPinGenerator pinGen = new PinGenerator(nrOfPinsToGenerate, nrOfDigits); // assert for (int p = 0; p < 99999; p++) { var pin = pinGen.GeneratePin(); int i = pin / 1000; int j = (pin - 1000 * i) / 100; int k = (pin - 1000 * i - 100 * j) / 10; int l = pin - 1000 * i - 100 * j - k * 10; Assert.IsTrue(i != j && i != k && i != l && j != k && j != l && k != l); Assert.IsTrue(i != j - 1 && j != k - 1 && k != l - 1); Assert.IsTrue((int)Math.Ceiling(Math.Log10(pin)) <= 4); } }