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

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

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

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

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