public async Task RegisterCustomer_ValidData_Succeeds() { var customer = new RegisterCustomerDto { CustomerCode = "0055_ALT-CM0102", Email = "*****@*****.**", Username = "******", FirstName = "Ian", LastName = "Clive", Password = "******", PhoneNumber = "+4412345678", }; Assert.Null(await Record.ExceptionAsync(async() => await _client.Accounts_RegisterCustomerAsync(customer))); Assert.Null(await Record.ExceptionAsync(async() => await _client.AuthenticateUserAsync("iclive", "password"))); using (var context = _factory.GetKIOTContext()) { Assert.True(context.Customers.Any(x => x.FirstName == customer.FirstName && x.LastName == customer.LastName && x.Username == customer.Username && x.PhoneNumber == customer.PhoneNumber)); } using (var context = _factory.GetIdentityContext()) { Assert.True(context.Users.Any(x => x.Email == customer.Email && x.UserName == customer.Username)); } }
public async Task RegisterPushToken_ValidRequest_Succeeds() { var dto = await _client.AuthenticateUserAsync("mwilson", "password"); _httpClient.AddAuthorization(dto); var pushTokenDto = new RegisterPushTokenDto { PushToken = "4bb26a87-2ccb-48b7-ba66-c1025b22056e", DeviceName = "Test Device", InstallationId = "6eb6ef3e-e1b0-428f-832a-bbf6d36c9e9c", MobileOs = MobileOS.Android }; SuccessfulRequestDto dto2 = null; var exception2 = await Record.ExceptionAsync(async() => { dto2 = await _client.Authentication_RegisterPushTokenAsync(pushTokenDto); }); Assert.Null(exception2); using (var context = _factory.GetKIOTContext()) { Assert.True(context.PushTokens.Include(x => x.MobileDevice).Any(x => x.MobileDevice.DeviceName == pushTokenDto.DeviceName && x.Token == pushTokenDto.PushToken && x.MobileDevice.InstallationId == pushTokenDto.InstallationId && x.MobileDevice.MobileOS == Core.Models.Application.MobileOS.Android)); } }
public async Task GetAssignedCaretakers_ValidRequest_Successful() { (await _client.AuthenticateUserAsync("mwilson", "password")).AddAuthorization(_httpClient); AssignedCaretakersForCustomerDto response = null; Assert.Null(await Record.ExceptionAsync(async() => response = await _client.Customer_GetAssignedCaretakersAsync())); Assert.NotNull(response); Assert.Empty(response.Caretakers); using (var context = _factory.GetKIOTContext()) { var caretaker = context.Caretakers.SingleOrDefault(x => x.Username == "jcole"); Assert.NotNull(caretaker); var customer = context.Customers.SingleOrDefault(x => x.Username == "mwilson"); Assert.NotNull(customer); context.IsCaredForBys.Add(new CaretakerForCustomer(caretaker.Id, customer.Id)); context.SaveChanges(); } response = null; Assert.Null(await Record.ExceptionAsync(async() => response = await _client.Customer_GetAssignedCaretakersAsync())); Assert.NotNull(response); Assert.Single(response.Caretakers); }
public async Task GetCustomerHomepage_ValidRequest_Succeeds() { using (var context = _factory.GetKIOTContext()) { _ = context.AddCaretakerForCustomer("jcole", "fbrown"); } (await _client.AuthenticateUserAsync("jcole", "password")).AddAuthorization(_httpClient); CustomerHomepageForCaretakerDto response = null; Assert.Null(await Record.ExceptionAsync(async() => response = await _client.Caretaker_GetCustomerHomepageAsync(Guid.Parse("48dd8db1-2c48-4f8b-a318-8a85cc286557")))); Assert.NotNull(response); Assert.NotNull(response.Customer); Assert.True(response.Customer.FirstName == "Frank" && response.Customer.LastName == "Brown" && response.Customer.Username == "fbrown"); Assert.Equal(3, response.PowerUsageRatios.Count()); Assert.Equal(3, response.PowerUsageRatios.Select(x => x.TimePeriod).Distinct().Count()); }
public async Task RegisterApplianceCategory_NewCategory_Succeeds() { (await _client.AuthenticateUserAsync("mwilson", "password")).AddAuthorization(_httpClient); Assert.Null(await Record.ExceptionAsync(async() => Assert.NotNull(await _client.Appliance_RegisterApplianceCategoryAsync("TestCategory")))); using (var context = _factory.GetKIOTContext()) { Assert.True(context.ApplianceCategories.Any(x => x.CustomerId == -1 && x.Name == "TestCategory")); } }