public Task <IActionResult> PatchRelationshipAsync(string id, string relationshipName, [FromBody] object secondaryResourceIds, CancellationToken cancellationToken) { int idValue = HexadecimalCodec.Decode(id); return(base.PatchRelationshipAsync(idValue, relationshipName, secondaryResourceIds, cancellationToken)); }
public Task <IActionResult> DeleteRelationshipAsync(string id, string relationshipName, [FromBody] ISet <IIdentifiable> secondaryResourceIds, CancellationToken cancellationToken) { int idValue = HexadecimalCodec.Decode(id); return(base.DeleteRelationshipAsync(idValue, relationshipName, secondaryResourceIds, cancellationToken)); }
public async Task Cannot_delete_missing_resource() { // Arrange var stringId = HexadecimalCodec.Encode(99999999); var route = "/bankAccounts/" + stringId; // Act var(httpResponse, responseDocument) = await _testContext.ExecuteDeleteAsync <ErrorDocument>(route); // Assert httpResponse.Should().HaveStatusCode(HttpStatusCode.NotFound); responseDocument.Errors.Should().HaveCount(1); responseDocument.Errors[0].StatusCode.Should().Be(HttpStatusCode.NotFound); responseDocument.Errors[0].Title.Should().Be("The requested resource does not exist."); responseDocument.Errors[0].Detail.Should().Be($"Resource of type 'bankAccounts' with ID '{stringId}' does not exist."); responseDocument.Errors[0].Source.Parameter.Should().BeNull(); }
public async Task Cannot_delete_missing_resource() { // Arrange var codec = new HexadecimalCodec(); string stringId = codec.Encode(99999999); string route = "/bankAccounts/" + stringId; // Act (HttpResponseMessage httpResponse, ErrorDocument responseDocument) = await _testContext.ExecuteDeleteAsync <ErrorDocument>(route); // Assert httpResponse.Should().HaveStatusCode(HttpStatusCode.NotFound); responseDocument.Errors.Should().HaveCount(1); Error error = responseDocument.Errors[0]; error.StatusCode.Should().Be(HttpStatusCode.NotFound); error.Title.Should().Be("The requested resource does not exist."); error.Detail.Should().Be($"Resource of type 'bankAccounts' with ID '{stringId}' does not exist."); }
public async Task Can_filter_any_in_primary_resources() { // Arrange var accounts = _fakers.BankAccount.Generate(2); await _testContext.RunOnDatabaseAsync(async dbContext => { await dbContext.ClearTableAsync <BankAccount>(); dbContext.BankAccounts.AddRange(accounts); await dbContext.SaveChangesAsync(); }); var route = $"/bankAccounts?filter=any(id,'{accounts[1].StringId}','{HexadecimalCodec.Encode(99999999)}')"; // Act var(httpResponse, responseDocument) = await _testContext.ExecuteGetAsync <Document>(route); // Assert httpResponse.Should().HaveStatusCode(HttpStatusCode.OK); responseDocument.ManyData.Should().HaveCount(1); responseDocument.ManyData[0].Id.Should().Be(accounts[1].StringId); }
public async Task Can_create_resource_with_relationship() { // Arrange var existingBankAccount = _fakers.BankAccount.Generate(); var newDebitCard = _fakers.DebitCard.Generate(); await _testContext.RunOnDatabaseAsync(async dbContext => { dbContext.BankAccounts.Add(existingBankAccount); await dbContext.SaveChangesAsync(); }); var requestBody = new { data = new { type = "debitCards", attributes = new { ownerName = newDebitCard.OwnerName, pinCode = newDebitCard.PinCode }, relationships = new { account = new { data = new { type = "bankAccounts", id = existingBankAccount.StringId } } } } }; var route = "/debitCards"; // Act var(httpResponse, responseDocument) = await _testContext.ExecutePostAsync <Document>(route, requestBody); // Assert httpResponse.Should().HaveStatusCode(HttpStatusCode.Created); responseDocument.SingleData.Attributes["ownerName"].Should().Be(newDebitCard.OwnerName); responseDocument.SingleData.Attributes["pinCode"].Should().Be(newDebitCard.PinCode); var newDebitCardId = HexadecimalCodec.Decode(responseDocument.SingleData.Id); await _testContext.RunOnDatabaseAsync(async dbContext => { var debitCardInDatabase = await dbContext.DebitCards .Include(debitCard => debitCard.Account) .FirstAsync(debitCard => debitCard.Id == newDebitCardId); debitCardInDatabase.OwnerName.Should().Be(newDebitCard.OwnerName); debitCardInDatabase.PinCode.Should().Be(newDebitCard.PinCode); debitCardInDatabase.Account.Should().NotBeNull(); debitCardInDatabase.Account.Id.Should().Be(existingBankAccount.Id); debitCardInDatabase.Account.StringId.Should().Be(existingBankAccount.StringId); }); }
public Task <IActionResult> DeleteAsync(string id, CancellationToken cancellationToken) { int idValue = HexadecimalCodec.Decode(id); return(base.DeleteAsync(idValue, cancellationToken)); }
public Task <IActionResult> PatchAsync(string id, [FromBody] TResource resource, CancellationToken cancellationToken) { int idValue = HexadecimalCodec.Decode(id); return(base.PatchAsync(idValue, resource, cancellationToken)); }
public Task <IActionResult> GetRelationshipAsync(string id, string relationshipName, CancellationToken cancellationToken) { int idValue = HexadecimalCodec.Decode(id); return(base.GetRelationshipAsync(idValue, relationshipName, cancellationToken)); }
protected override string GetStringId(int value) { return(HexadecimalCodec.Encode(value)); }
protected override int GetTypedId(string value) { return(HexadecimalCodec.Decode(value)); }