public async Task RegisterPushToken_InvalidRequest_Fails() { var dto = await _client.AuthenticateUserAsync("mwilson", "password"); _httpClient.AddAuthorization(dto); var pushTokenDto = new RegisterPushTokenDto { PushToken = null, 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); }); using (var context = _factory.GetKIOTContext()) { Assert.False(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)); } Assert.NotNull(exception2); }
public async Task DeleteAssignedCaretaker_ValidRequest_Successful() { 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(); } (await _client.AuthenticateUserAsync("mwilson", "password")).AddAuthorization(_httpClient); SuccessfulRequestDto response = null; Assert.Null(await Record.ExceptionAsync(async() => response = await _client.Customer_DeleteAssignedCaretakerAsync(Guid.Parse("e0e26424-f4cd-4400-bc78-28b0bfef729a")))); Assert.NotNull(response); AssignedCaretakersForCustomerDto response1 = null; Assert.Null(await Record.ExceptionAsync(async() => response1 = await _client.Customer_GetAssignedCaretakersAsync())); Assert.NotNull(response1); Assert.Empty(response1.Caretakers); }
public async Task RegisterCustomerTask_InvalidRequest_Fails() { (await _client.AuthenticateUserAsync("jcole", "password")).AddAuthorization(_httpClient); SuccessfulRequestDto response = null; Assert.NotNull(await Record.ExceptionAsync(async() => response = await _client.Caretaker_RegisterCustomerTaskAsync(new RegisterCustomerTaskDto { CustomerGuid = Guid.Parse("48dd8db1-2c48-4f8b-a318-8a85cc286557"), Title = null, Description = "TaskDescription", ExpiresAt = null, }))); Assert.Null(response); Assert.NotNull(await Record.ExceptionAsync(async() => response = await _client.Caretaker_RegisterCustomerTaskAsync(new RegisterCustomerTaskDto { CustomerGuid = Guid.Parse("48dd8db1-2c48-4f8b-a318-8a85cc286557"), Title = "TestTitle", Description = null, ExpiresAt = null, }))); Assert.Null(response); }
public async Task SetAliasForAppliance_ClearAlias_Succeeds() { (await _client.AuthenticateUserAsync("mwilson", "password")).AddAuthorization(_httpClient); SuccessfulRequestDto response = null; Assert.Null(await Record.ExceptionAsync(async() => response = await _client.Customer_SetAliasForApplianceAsync( new SetAliasForApplianceDto { Alias = "ApplianceAlias", ApplianceId = 20501 }))); Assert.NotNull(response); SuccessfulRequestDto response1 = null; Assert.Null(await Record.ExceptionAsync(async() => response1 = await _client.Customer_SetAliasForApplianceAsync( new SetAliasForApplianceDto { Alias = null, ApplianceId = 20501 }))); Assert.NotNull(response1); CustomerAppliancesDto response2 = null; Assert.Null(await Record.ExceptionAsync(async() => response2 = await _client.Customer_GetAppliancesAsync())); Assert.NotNull(response2); Assert.Contains(response2.Appliances, x => x.ApplianceName == null && x.ApplianceId == 20501); }
public async Task SetCustomerTaskState_InvalidTaskState_Fails() { Guid guid; using (var context = _factory.GetKIOTContext()) { var(customer, caretaker) = context.AddCaretakerForCustomer("jcole", "fbrown"); var task = new CustomerTask(customer, caretaker, "TestDescription", "TestTitle", null); guid = task.Guid; Assert.False(task.TaskFinished); context.CustomerTasks.Add(task); context.SaveChanges(); } Assert.NotEqual(Guid.Empty, guid); (await _client.AuthenticateUserAsync("jcole", "password")).AddAuthorization(_httpClient); SuccessfulRequestDto response = null; Assert.NotNull(await Record.ExceptionAsync(async() => response = await _client.Caretaker_SetCustomerTaskStateAsync(new SetCustomerTaskStateDto { CustomerTaskGuid = guid, State = (CustomerTaskState)12 }))); Assert.Null(response); using (var context = _factory.GetKIOTContext()) { Assert.Equal(1, context.CustomerTasks.Count(x => x.Caretaker.Username == "jcole")); } }
public async Task GetAssignedCustomers_ValidRequest_Succeeds() { (await _client.AuthenticateUserAsync("twilliams", "password")).AddAuthorization(_httpClient); AssignedCustomersForCaretakerDto response = null; Assert.Null(await Record.ExceptionAsync(async() => response = await _client.Caretaker_GetAssignedCustomersAsync())); Assert.NotNull(response); Assert.Empty(response.Customers); SuccessfulRequestDto response1 = null; Assert.Null(await Record.ExceptionAsync(async() => response1 = await _client.Caretaker_HandleCaretakerRequestAsync(Guid.Parse("f61ee92d-792e-45dd-a664-309178a71830"), new HandleCaretakerForCustomerRequestDto { AcceptRequest = true }))); Assert.NotNull(response1); response = null; Assert.Null(await Record.ExceptionAsync(async() => response = await _client.Caretaker_GetAssignedCustomersAsync())); Assert.NotNull(response); Assert.Single(response.Customers); var customer = response.Customers.First(); Assert.NotNull(customer); Assert.Equal("Matt", customer.FirstName); Assert.Equal("Wilson", customer.LastName); Assert.Equal("mwilson", customer.Username); Assert.Equal("+4418821000", customer.PhoneNumber); }
public async Task DeleteApplianceCategory_CategoryHasAppliances_Succeeds() { Guid guid; using (var context = _factory.GetKIOTContext()) { var category = new ApplianceCategory("TestCategory", -1); guid = category.Guid; Assert.NotEqual(Guid.Empty, guid); context.ApplianceCategories.Add(category); context.SaveChanges(); } (await _client.AuthenticateUserAsync("mwilson", "password")).AddAuthorization(_httpClient); SuccessfulRequestDto dto1 = null; Assert.Null(await Record.ExceptionAsync(async() => dto1 = await _client.Appliance_SetApplianceCategoryAsync(20501, "TestCategory"))); Assert.NotNull(dto1); SuccessfulRequestDto dto2 = null; Assert.NotNull(await Record.ExceptionAsync(async() => dto2 = await _client.Appliance_DeleteApplianceCategoryAsync(guid))); Assert.Null(dto2); using (var context = _factory.GetKIOTContext()) { Assert.Equal(1, context.ApplianceCategories.Count(x => x.Guid == guid)); } }
public async Task SetApplianceCategory_UpdateCategory_Succeeds() { using (var context = _factory.GetKIOTContext()) { context.ApplianceCategories.Add(new ApplianceCategory("TestCategory1", -1)); context.ApplianceCategories.Add(new ApplianceCategory("TestCategory2", -1)); context.SaveChanges(); } (await _client.AuthenticateUserAsync("mwilson", "password")).AddAuthorization(_httpClient); SuccessfulRequestDto dto = null; Assert.Null(await Record.ExceptionAsync(async() => dto = await _client.Appliance_SetApplianceCategoryAsync(20501, "TestCategory1"))); Assert.NotNull(dto); Assert.Null(await Record.ExceptionAsync(async() => dto = await _client.Appliance_SetApplianceCategoryAsync(20501, "TestCategory2"))); Assert.NotNull(dto); using (var context = _factory.GetKIOTContext()) { Assert.True(context.Customers.Include(x => x.Appliances) .ThenInclude(x => x.Category).SingleOrDefault(x => x.Username == "mwilson")? .Appliances.Any(x => x.ApplianceId == 20501 && x.Category.Name == "TestCategory2") ?? false); } }
public async Task HandleCaretakerRequest_DeclineRequest_Succeeds() { (await _client.AuthenticateUserAsync("twilliams", "password")).AddAuthorization(_httpClient); SuccessfulRequestDto response = null; Assert.Null(await Record.ExceptionAsync(async() => response = await _client.Caretaker_HandleCaretakerRequestAsync(Guid.Parse("f61ee92d-792e-45dd-a664-309178a71830"), new HandleCaretakerForCustomerRequestDto { AcceptRequest = false }))); Assert.NotNull(response); PendingCaretakerRequestsDto response1 = null; Assert.Null(await Record.ExceptionAsync(async() => response1 = await _client.Caretaker_GetPendingCaretakerRequestsAsync())); Assert.NotNull(response1); Assert.Equal(2, response1.CaretakerRequests.Count()); AssignedCustomersForCaretakerDto response2 = null; Assert.Null(await Record.ExceptionAsync(async() => response2 = await _client.Caretaker_GetAssignedCustomersAsync())); Assert.NotNull(response2); Assert.Empty(response2.Customers); }
public async Task AddCaretakerForCustomer_ValidRequest_Successful() { (await _client.AuthenticateUserAsync("fbrown", "password")).AddAuthorization(_httpClient); SuccessfulRequestDto response = null; Assert.Null(await Record.ExceptionAsync(async() => response = await _client.Customer_AddCaretakerForCustomerAsync( new AddCaretakerForCustomerDto { CaretakerUsername = "******" }))); Assert.NotNull(response); (await _client.AuthenticateUserAsync("jcole", "password")).AddAuthorization(_httpClient); PendingCaretakerRequestsDto response1 = null; Assert.Null(await Record.ExceptionAsync(async() => response1 = await _client.Caretaker_GetPendingCaretakerRequestsAsync())); Assert.NotNull(response1); Assert.Single(response1.CaretakerRequests); Assert.Contains(response1.CaretakerRequests, x => x.Customer.FirstName == "Frank" && x.Customer.LastName == "Brown" && x.Customer.Username == "fbrown" && x.Customer.PhoneNumber == "+4418821001"); }
public async Task DeleteAssignedCustomer_EmptyGuid_Fails() { (await _client.AuthenticateUserAsync("jcole", "password")).AddAuthorization(_httpClient); SuccessfulRequestDto response = null; Assert.NotNull(await Record.ExceptionAsync(async() => response = await _client.Caretaker_DeleteAssignedCustomerAsync(Guid.Empty))); Assert.Null(response); }
public async Task DeleteAssignedCustomer_InvalidCustomer_Fails() { (await _client.AuthenticateUserAsync("jcole", "password")).AddAuthorization(_httpClient); SuccessfulRequestDto response = null; Assert.NotNull(await Record.ExceptionAsync(async() => response = await _client.Caretaker_DeleteAssignedCustomerAsync(Guid.Parse("48dd8db1-2c48-4f8b-a318-8a85cc286557")))); Assert.Null(response); }
public async Task AlertCustomer_InvalidRequest_Fails() { (await _client.AuthenticateUserAsync("jcole", "password")).AddAuthorization(_httpClient); SuccessfulRequestDto response = null; Assert.NotNull(await Record.ExceptionAsync(async() => response = await _client.Caretaker_AlertCustomerAsync(new AlertCustomerDto { Username = "******", Message = null }))); Assert.Null(response); }
public async Task AddCaretakerForCustomer_InvalidUsername_Fails() { (await _client.AuthenticateUserAsync("fbrown", "password")).AddAuthorization(_httpClient); SuccessfulRequestDto response = null; Assert.NotNull(await Record.ExceptionAsync(async() => response = await _client.Customer_AddCaretakerForCustomerAsync( new AddCaretakerForCustomerDto { CaretakerUsername = "******" }))); Assert.Null(response); }
public async Task DeleteAssignedCaretaker_InvalidCaretaker_Successful() { (await _client.AuthenticateUserAsync("mwilson", "password")).AddAuthorization(_httpClient); SuccessfulRequestDto response = null; Assert.NotNull(await Record.ExceptionAsync(async() => response = await _client.Customer_DeleteAssignedCaretakerAsync(Guid.Parse("e0e26424-f4cd-4400-bc78-28b0bfef729a")))); Assert.Null(response); AssignedCaretakersForCustomerDto response1 = null; Assert.Null(await Record.ExceptionAsync(async() => response1 = await _client.Customer_GetAssignedCaretakersAsync())); Assert.NotNull(response1); Assert.Empty(response1.Caretakers); }
public async Task SetCustomerTaskState_InvalidTaskGuid_Fails() { (await _client.AuthenticateUserAsync("jcole", "password")).AddAuthorization(_httpClient); SuccessfulRequestDto response = null; Assert.NotNull(await Record.ExceptionAsync(async() => response = await _client.Caretaker_SetCustomerTaskStateAsync(new SetCustomerTaskStateDto { CustomerTaskGuid = Guid.Parse("00000000-2c48-4f8b-a318-000000000000"), State = CustomerTaskState.Complete }))); Assert.Null(response); using (var context = _factory.GetKIOTContext()) { Assert.Equal(0, context.CustomerTasks.Count(x => x.Caretaker.Username == "jcole")); } }
public async Task SetAliasForAppliance_InvalidApplianceId_Fails() { (await _client.AuthenticateUserAsync("mwilson", "password")).AddAuthorization(_httpClient); SuccessfulRequestDto response = null; Assert.NotNull(await Record.ExceptionAsync(async() => response = await _client.Customer_SetAliasForApplianceAsync( new SetAliasForApplianceDto { Alias = "ApplianceAlias", ApplianceId = 0 }))); Assert.Null(response); using (var context = _factory.GetKIOTContext()) { Assert.False(context.CustomerAppliances .Any(x => x.Customer.Username == "mwilson" && x.Alias == "ApplianceAlias")); } }
public async Task DeleteAssignedCustomer_ValidRequest_Succeeds() { using (var context = _factory.GetKIOTContext()) { _ = context.AddCaretakerForCustomer("jcole", "fbrown"); } (await _client.AuthenticateUserAsync("jcole", "password")).AddAuthorization(_httpClient); SuccessfulRequestDto response = null; Assert.Null(await Record.ExceptionAsync(async() => response = await _client.Caretaker_DeleteAssignedCustomerAsync(Guid.Parse("48dd8db1-2c48-4f8b-a318-8a85cc286557")))); Assert.NotNull(response); using (var context = _factory.GetKIOTContext()) { Assert.False(context.IsCaredForBys.Include($"{nameof(CaretakerForCustomer.Caretaker)}") .Include($"{nameof(CaretakerForCustomer.Customer)}") .Any(x => x.Caretaker.Username == "jcole" && x.Customer.Username == "fbrown")); } }
public async Task AddCaretaker_ExistingRequest_Fails() { (await _client.AuthenticateUserAsync("fbrown", "password")).AddAuthorization(_httpClient); SuccessfulRequestDto response = null; Assert.NotNull(await Record.ExceptionAsync(async() => response = await _client.Customer_AddCaretakerForCustomerAsync( new AddCaretakerForCustomerDto { CaretakerUsername = "******" }))); Assert.Null(response); (await _client.AuthenticateUserAsync("jcole", "password")).AddAuthorization(_httpClient); PendingCaretakerRequestsDto response1 = null; Assert.Null(await Record.ExceptionAsync(async() => response1 = await _client.Caretaker_GetPendingCaretakerRequestsAsync())); Assert.NotNull(response1); Assert.Empty(response1.CaretakerRequests); }
public async Task RegisterCustomerTask_ValidRequest_Succeeds() { using (var context = _factory.GetKIOTContext()) { _ = context.AddCaretakerForCustomer("jcole", "fbrown"); } (await _client.AuthenticateUserAsync("jcole", "password")).AddAuthorization(_httpClient); SuccessfulRequestDto response = null; Assert.Null(await Record.ExceptionAsync(async() => response = await _client.Caretaker_RegisterCustomerTaskAsync(new RegisterCustomerTaskDto { CustomerGuid = Guid.Parse("48dd8db1-2c48-4f8b-a318-8a85cc286557"), Title = "TestTitle", Description = "TaskDescription", ExpiresAt = null, }))); Assert.NotNull(response); Assert.Null(await Record.ExceptionAsync(async() => response = await _client.Caretaker_RegisterCustomerTaskAsync(new RegisterCustomerTaskDto { CustomerGuid = Guid.Parse("48dd8db1-2c48-4f8b-a318-8a85cc286557"), Title = "TestTitle", Description = "TaskDescription", ExpiresAt = DateTime.UtcNow.AddDays(2), }))); Assert.NotNull(response); using (var context = _factory.GetKIOTContext()) { Assert.Equal(2, context.CustomerTasks.Count(x => x.Customer.Guid == Guid.Parse("48dd8db1-2c48-4f8b-a318-8a85cc286557") && x.Caretaker.Username == "jcole")); } }