Example #1
0
        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));
        }
Example #2
0
        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));
        }
Example #3
0
        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);
            });
        }
Example #4
0
        public Task <IActionResult> DeleteAsync(string id, CancellationToken cancellationToken)
        {
            int idValue = HexadecimalCodec.Decode(id);

            return(base.DeleteAsync(idValue, cancellationToken));
        }
Example #5
0
        public Task <IActionResult> PatchAsync(string id, [FromBody] TResource resource, CancellationToken cancellationToken)
        {
            int idValue = HexadecimalCodec.Decode(id);

            return(base.PatchAsync(idValue, resource, cancellationToken));
        }
Example #6
0
        public Task <IActionResult> GetRelationshipAsync(string id, string relationshipName, CancellationToken cancellationToken)
        {
            int idValue = HexadecimalCodec.Decode(id);

            return(base.GetRelationshipAsync(idValue, relationshipName, cancellationToken));
        }
Example #7
0
 protected override int GetTypedId(string value)
 {
     return(HexadecimalCodec.Decode(value));
 }
Example #8
0
        public Task <IActionResult> GetAsync(string id, CancellationToken cancellationToken)
        {
            int idValue = _codec.Decode(id);

            return(base.GetAsync(idValue, cancellationToken));
        }